On Thu, 29 Oct 2026, Robin Dapp wrote:

> > So what I'm most worried about is that you modify only the 
> > SLP_TREE_VECTYPE and that in-place.  Both the SLP_TREE_SCALAR_STMTS
> > and the SLP_TREE_REPRESENTATIVE have contradicting info, so
> > I wonder how you get away without modifying the reduction epilogue
> > code.  If that just works then it would be by chance, not by design.
> 
> Yeah, wouldn't disagree that it's hackish but from what I could see at 
> least vect_create_epilog_for_reduction always converts to the scalar 
> type so the "compensation" was already there.  I went through some more 

It's there for sign-conversions, yeah.

> usage sites and while there are surely still holes but I didn't manage 
> to trigger them in a first attempt (likely because the "pass" is not 
> doing a lot right now).

I think it's generally good to reduce the precision of the reduction
variable up to the precision of the values reduced (but not smaller),
so at least for testing I'd open this "pass" up for reduction ops
other than SAD.

> > I see the scalar pattern approach isn't any easier as you'd have to
> > introduce pattern stmts for PHIs.  Using SLP patterns would work
> > to some extent, but there's still the issue that the live lane for
> > the reduction epilog has a wrong type and we do not represent
> > compensation for that.  So both those and your approach feel
> > like hacks.
> 
> To add to that, my main issue about pattern matching, vect or SLP was 
> that when deciding for a lower precision I'd also want to check the 
> reduction operation.  If, it feels like a higher-level pattern matching 
> the whole chain, so more like something slp_optimize would do.
> 
> > In the end I'm going to point to the pre-pass we have to facilitate
> > vectorization which is if-conversion.  What I'd do is attempt to
> > narrow the reduction PHI and insert a compensation scalar conversion
> > at the loop exit.  It should be possible to use check_reduction_path
> > to gather SSA cycles.
> 
> Would you be ok with doing it in ifcvt?  I guess there's precedent with 
> bitfield lowering but... :)  What I'm concerned about is that we don't 
> know about patterns yet (SAD is not embarrassingly simple) and "always" 
> reducing the precision would penalize targets that don't have a 2x but 
> only a 4x SAD (x86?).
> For non-pattern operations like regular + it might be easier.

Hmm, yeah, it would likely pessimize SAD on x86, so it then rules
out doing it in ifcvt.  Dang.

> In my initial attempt, I adjusted the vectype in 
> vect_get_vector_types_for_stmt for those statements marked part of a 
> narrowable cycle via STMT_VINFO_REDUC_PREC but that's not any prettier 
> either as scalar and vector similarly disagree.

With doing this as SLP pattern you'd have the chance to invent
new SLP_TREE_REPRESENTATIVE stmts (also for the PHI).  There's
still the remaining issue that for the live lane we want to
have the "true" scalar def, and there's no way to do that given
we do not represent the LC PHI in the SLP graph (we do not
represent any reduction result or live lane extract result).

But in principle this would be the way to go, and represent the
reduction result and possibly LC PHIs.  So if we can do it as
SLP pattern, leaving the missed representation aside and instead
use some kind of implicit thing like a flag (aka "demoted vector 
element"), that would sound most future-proof to me?

Richard.


-- 
Richard Biener <[email protected]>
SUSE Software Solutions Germany GmbH,
Frankenstrasse 146, 90461 Nuernberg, Germany;
GF: Stefan Gaiser, Jochen Jaser, Abhinav Puri; (HRB 36809, AG Nuernberg)

Reply via email to