RE: [PATCH 1/2] tree-scalar-evolution: Handle idempotent recurrences [PR124460]

"Liu, Hongtao" <[email protected]> Thu, 6 Aug 2026 04:54:42 +0000
Newsgroups gmane.comp.gcc.patches
Message-ID <DS4PPF240F42FB75A2A1C4C5661482D6E12E5D22@DS4PPF240F42FB7.namprd11.prod.outlook.com>

> -----Original Message-----
> From: Jeffrey Law <[email protected]>
> Sent: Thursday, August 6, 2026 11:18 AM
> To: Liu, Hongtao <[email protected]>; [email protected]; Rachit
> Mehta <[email protected]>
> Cc: [email protected]
> Subject: Re: [PATCH 1/2] tree-scalar-evolution: Handle idempotent
> recurrences [PR124460]
> 
> 
> 
> 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.

Sound ok to me.
> 
> Rachit, are you willing to do that work?  I would suggest y'all be co-authors on
> the result.
> 
> Thanks,
> Jeff