vect: Fix multi-vector SLP gather loads [PR103744]
Commit Message
[Repost with address typo fixed]
This PR shows that I didn't properly test the multi-vector case when
adding support for SLP gather loads. The patch fixes that case using
the same approach as we do for non-SLP cases: keep the scalar base
the same, but iterate through the (also multi-vector) vector offsets.
“vec_num * j + i” is already used elsewhere as a way of handling both
the multi-vector SLP case and the multi-vector non-SLP case.
Tested on aarch64-linux-gnu. It probably falls just short of
being obvious, so: OK to install?
Thanks,
Richard
gcc/
PR tree-optimization/103744
* tree-vect-stmts.c (vectorizable_load): Handle multi-vector
SLP gather loads.
gcc/testsuite/
PR tree-optimization/103744
* gcc.dg/vect/pr103744-1.c: New test.
* gcc.dg/vect/pr103744-2.c: Likewise.
---
gcc/testsuite/gcc.dg/vect/pr103744-1.c | 20 +++++++++++++++++
gcc/testsuite/gcc.dg/vect/pr103744-2.c | 31 ++++++++++++++++++++++++++
gcc/tree-vect-stmts.c | 6 +++--
3 files changed, 55 insertions(+), 2 deletions(-)
create mode 100644 gcc/testsuite/gcc.dg/vect/pr103744-1.c
create mode 100644 gcc/testsuite/gcc.dg/vect/pr103744-2.c
new file mode 100644
@@ -0,0 +1,20 @@
+/* { dg-do compile } */
+
+int r;
+
+void
+foo (short int *s, short int *d1, short int *d2, int z)
+{
+ int *a;
+
+ while (z < 1)
+ {
+ int i;
+
+ i = *s++ - (*d1++ + *d2++);
+ r += a[i];
+ i = *s++ - (*d1++ + *d2++);
+ r += a[i];
+ ++z;
+ }
+}
new file mode 100644
@@ -0,0 +1,31 @@
+/* { dg-do compile } */
+
+int
+f1 (int *restrict x, unsigned short *restrict y)
+{
+ int res = 0;
+ for (int i = 0; i < 100; i += 2)
+ {
+ unsigned short i1 = y[i + 0] + 1;
+ unsigned short i2 = y[i + 1] + 2;
+ res += x[i1];
+ res += x[i2];
+ }
+ return res;
+}
+
+void
+f2 (int *restrict x, unsigned short *restrict y)
+{
+ int res1 = 0;
+ int res2 = 0;
+ for (int i = 0; i < 100; i += 2)
+ {
+ unsigned short i1 = y[i + 0] + 1;
+ unsigned short i2 = y[i + 1] + 2;
+ res1 += x[i1];
+ res2 += x[i2];
+ }
+ x[0] = res1;
+ x[1] = res2;
+}
@@ -9247,6 +9247,8 @@ vectorizable_load (vec_info *vinfo,
group_size = vec_num = 1;
group_gap_adj = 0;
ref_type = reference_alias_ptr_type (DR_REF (first_dr_info->dr));
+ if (slp)
+ vec_num = SLP_TREE_NUMBER_OF_VEC_STMTS (slp_node);
}
gcc_assert (alignment_support_scheme);
@@ -9592,7 +9594,7 @@ vectorizable_load (vec_info *vinfo,
final_mask = prepare_vec_mask (loop_vinfo, mask_vectype,
final_mask, vec_mask, gsi);
- if (i > 0)
+ if (i > 0 && !STMT_VINFO_GATHER_SCATTER_P (stmt_info))
dataref_ptr = bump_vector_ptr (vinfo, dataref_ptr, ptr_incr,
gsi, stmt_info, bump);
@@ -9609,7 +9611,7 @@ vectorizable_load (vec_info *vinfo,
&& gs_info.ifn != IFN_LAST)
{
if (STMT_VINFO_GATHER_SCATTER_P (stmt_info))
- vec_offset = vec_offsets[j];
+ vec_offset = vec_offsets[vec_num * j + i];
tree zero = build_zero_cst (vectype);
tree scale = size_int (gs_info.scale);
gcall *call;