Hi,

This is v2 for optimizing away reverse permutations for negative-step
contiguous DRs in loops.

v1: https://gcc.gnu.org/pipermail/gcc-patches/2026-August/729126.html

The main change in v2 is to move the analysis into the existing SLP
optimization pass and reuse the SLP graph built there. It allows us to
remove the dependency on the BB SLP graph partitioning. Patch 1/2 adds
a function for weakly connected component (WCC) discovery in graphds.
Patch 2/2 analyzes each WCC individually to reduce the number of
reverse permutations inside.

Another change in v2 is to record the reverse state of DRs on SLP nodes
instead of SLP leader instances. So now the optimization is no longer
limited to cases where all DRs have the same VMAT_CONTIGUOUS_REVERSE.
For example,

        a[forward] = b[backward] + c[backward]

can now be handled by keeping the computation in the reversed layout
and adding one reverse permutation at the forward store, reducing two
reverse permutations to one.

In this v2, the final VMAT is still determined after the optimization.
If a DR has an inverted reverse state but later gets a non-contiguous
VMAT, vectorization is conservatively rejected. I haven't found a case
that can reach this bailout so far, so I expect it to be rare.

The checks in the analysis and testcases have also been improved.

Pengfei Li (2):
  graphds: Add weakly connected component discovery
  vect: Reduce reverse permutations for contiguous DRs in loops
    [PR61338]

 gcc/graphds.cc                              |  50 +++++
 gcc/graphds.h                               |   1 +
 gcc/testsuite/gcc.dg/vect/vect-rev-perm-1.c |  34 ++++
 gcc/testsuite/gcc.dg/vect/vect-rev-perm-2.c |  39 ++++
 gcc/testsuite/gcc.dg/vect/vect-rev-perm-3.c |  41 ++++
 gcc/testsuite/gcc.dg/vect/vect-rev-perm-4.c |  38 ++++
 gcc/testsuite/gcc.dg/vect/vect-rev-perm-5.c |  42 +++++
 gcc/testsuite/gcc.dg/vect/vect-rev-perm-6.c |  38 ++++
 gcc/testsuite/gcc.dg/vect/vect-rev-perm-7.c |  45 +++++
 gcc/tree-vect-slp.cc                        | 196 ++++++++++++++++++--
 gcc/tree-vect-stmts.cc                      |  38 +++-
 gcc/tree-vectorizer.h                       |   4 +
 12 files changed, 551 insertions(+), 15 deletions(-)
 create mode 100644 gcc/testsuite/gcc.dg/vect/vect-rev-perm-1.c
 create mode 100644 gcc/testsuite/gcc.dg/vect/vect-rev-perm-2.c
 create mode 100644 gcc/testsuite/gcc.dg/vect/vect-rev-perm-3.c
 create mode 100644 gcc/testsuite/gcc.dg/vect/vect-rev-perm-4.c
 create mode 100644 gcc/testsuite/gcc.dg/vect/vect-rev-perm-5.c
 create mode 100644 gcc/testsuite/gcc.dg/vect/vect-rev-perm-6.c
 create mode 100644 gcc/testsuite/gcc.dg/vect/vect-rev-perm-7.c

-- 
2.43.0

Reply via email to