Re: [PATCH 1/2] tree-scalar-evolution: Handle idempotent recurrences [PR124460]
Jeffrey Law <[email protected]> Wed, 5 Aug 2026 21:18:26 -0600
| Newsgroups | gmane.comp.gcc.patches |
|---|---|
| Message-ID | <[email protected]> |
On 8/4/2026 8:45 PM, liuhongt wrote: > SCEV does not represent recurrences such as repeated MIN_EXPR or > BIT_AND_EXPR updates. Recognize MIN_EXPR, MAX_EXPR, BIT_AND_EXPR, > BIT_IOR_EXPR and ABS_EXPR updates with a loop-invariant second operand. > After any positive number of iterations their value is the operation > applied once to the initial value. > > gcc/ChangeLog: > > PR middle-end/124460 > * tree-scalar-evolution.cc (loop_phi_for_update): New function. > (build_loop_update): Likewise. > (compute_idempotent_loop_value): Likewise. > (final_value_replacement_loop): Use it. So there are pieces of both implementations that I prefer :-) Rachit's patch is better at checking for a variety of potential worries. Just some examples it verifies that the loop runs at least one time, avoiding problems with SSA_NAME_OCCURS_IN_ABNORMAL_PHI, etc. This patch is better in that it handles more types of operations. So what I'd suggest is we extend Rachit's implementation to cover min, max, abs, and, ior. Rachit, are you willing to do that work? I would suggest y'all be co-authors on the result. Thanks, Jeff