On Thu, 30 Oct 2025, Eric Botcazou wrote:

> > When we are unlucky operand canonicalization can end up presenting
> > us with different order, making a possible SLP reduction group
> > not match up.  The following allows swapping operands in this case.
> > 
> > Bootstrapped and tested on x86_64-unknown-linux-gnu, pushed.
> > 
> >     * tree-vect-slp.cc (vect_get_operand_map): Handle commutative
> >     operands when swapping is requested.
> >     (vect_build_slp_tree_1): Allow STMT_VINFO_REDUC_IDX differences
> >     when operand swapping makes them match and request swapping.
> >     (vect_build_slp_instance): Indicate we have successfully
> >     discovered a SLP reduction group.
> > 
> >     * gcc.dg/vect/slp-reduc-13.c: New testcase.
> 
> Thanks for looking into this!  I was planning to get back to it after having 
> sufficiently delved into the SLP-based vectorization scheme, but quickly got 
> side tracked...
> 
> I did see the operand swapping mechanism when I was investigating the issue 
> but got the impression that, as long as STMT_VINFO_REDUC_IDX is tracked for 
> each statement, swapping the operands to have it uniform across the whole 
> group would be superfluous for a commutative operation.  Obviously I totally 
> missed vect_get_operand_map and its implications.
> 
> I can confirm that the patch enables loop vectorization for the Ada testcase 
> compiled for x86_64-w64-mingw32 in 64-bit mode.  From the outside, it looks 
> like a straightforward extension to the operand swapping mechanism, so do you 
> plan to install it in GCC 16?

I pushed it to trunk already (but not your Ada testcase).

Richard.

Reply via email to