Re: [PATCH 2/2] tree-scalar-evolution: Handle toggle recurrences

Jeffrey Law <[email protected]> Wed, 5 Aug 2026 21:22:29 -0600
Newsgroups gmane.comp.gcc.patches
Message-ID <[email protected]>

On 8/4/2026 8:45 PM, liuhongt wrote:
> Recognize NEGATE_EXPR, BIT_NOT_EXPR and BIT_XOR_EXPR recurrences.
> Fold constant iteration counts and use a conditional for symbolic counts.
>
> Require may_be_zero to be false, since otherwise niter does not
> necessarily give the latch count.  Keep trapping signed negations
> unchanged.  This replaces the old invariant bit-operation helper;
> idempotent AND and IOR updates are handled by the preceding patch.
>
> gcc/ChangeLog:
>
> 	PR middle-end/124460
> 	PR middle-end/114502
> 	PR middle-end/112104
> 	PR middle-end/98909
> 	* tree-scalar-evolution.cc
> 	(analyze_and_compute_bitop_with_inv_effect): Remove.
> 	(compute_toggle_loop_value): New function.
> 	(final_value_replacement_loop): Use it.
>
> gcc/testsuite/ChangeLog:
>
> 	PR middle-end/124460
> 	PR middle-end/114502
> 	PR middle-end/112104
> 	PR middle-end/98909
> 	* gcc.dg/tree-ssa/pr124460-4.c: New test.
> 	* gcc.dg/tree-ssa/pr124460-5.c: Likewise.
> 	* gcc.target/i386/pr105735-1.c: Adjust scan count.
> 	* gcc.target/i386/pr105735-3.c: Likewise.
> 	* gcc.target/i386/pr92080-12.c: Keep the XOR operand variant.
This will need slight readjustment as I think we're better off with 
Rachit's patch for the idempotent cases.

It's been eons, but there was a paper, I think from the team at Rice, 
"Beyond Induction Variables" or something like that which described a 
bunch of these cases.  Did you happen to review that paper to see if 
there are any other toggle-like cases we should support?

Jeff