This series improves vectorization of negative-step contiguous data references.
Such DRs are vectorized using VMAT_CONTIGUOUS_REVERSE, which requires reverse
permutations for loads and stores. Consider this loop:
void foo (int *a)
{
for (int i = 99; i >= 0; i--)
a[i] *= 2;
}
On AArch64, current GCC emits the following code for the loop body:
ldr q30, [x1]
tbl v30.16b, {v30.16b}, v31.16b
add v30.4s, v30.4s, v30.4s
tbl v30.16b, {v30.16b}, v31.16b
str q30, [x1], -16
Since the operation between the load and the store is lane-wise, both tbl
instructions are unnecessary and can be elided by keeping the computation in
the reversed lane layout.
Current GCC generates reverse permutations in vectorizable_{load|store}, where
there is not enough context about how a loaded or stored vector is used or
produced to elide reverse permutations. This series does the optimization at
the SLP subgraph level. Each SLP instance records its connected subgraph leader
after the SLP graph partitioning. Then each leader keeps a flag indicating
whether reverse permutations can be elided throughout the SLP subgraph.
The whole patch series was bootstrapped and reg-tested on x86_64-linux-gnu,
arm-linux-gnueabihf and aarch64-linux-gnu with bootstrap-O3.
Pengfei Li (2):
vect: Generalize SLP graph partitioning
vect: Elide reverse permutations for VMAT_CONTIGUOUS_REVERSE
.../gcc.dg/vect/vect-elide-rev-perms-1.c | 34 ++++
.../gcc.dg/vect/vect-elide-rev-perms-2.c | 39 +++++
.../gcc.dg/vect/vect-elide-rev-perms-3.c | 38 +++++
.../gcc.dg/vect/vect-elide-rev-perms-4.c | 38 +++++
.../gcc.dg/vect/vect-elide-rev-perms-5.c | 42 +++++
gcc/tree-vect-slp.cc | 153 +++++++++++++++---
gcc/tree-vect-stmts.cc | 70 +++++++-
gcc/tree-vectorizer.h | 10 +-
8 files changed, 394 insertions(+), 30 deletions(-)
create mode 100644 gcc/testsuite/gcc.dg/vect/vect-elide-rev-perms-1.c
create mode 100644 gcc/testsuite/gcc.dg/vect/vect-elide-rev-perms-2.c
create mode 100644 gcc/testsuite/gcc.dg/vect/vect-elide-rev-perms-3.c
create mode 100644 gcc/testsuite/gcc.dg/vect/vect-elide-rev-perms-4.c
create mode 100644 gcc/testsuite/gcc.dg/vect/vect-elide-rev-perms-5.c
--
2.43.0