]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
vect: Fix multi-vector SLP gather loads [PR103744]
authorRichard Sandiford <richard.sandiford@arm.com>
Fri, 17 Dec 2021 14:18:39 +0000 (14:18 +0000)
committerRichard Sandiford <richard.sandiford@arm.com>
Fri, 17 Dec 2021 14:18:39 +0000 (14:18 +0000)
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.

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 [new file with mode: 0644]
gcc/testsuite/gcc.dg/vect/pr103744-2.c [new file with mode: 0644]
gcc/tree-vect-stmts.c

diff --git a/gcc/testsuite/gcc.dg/vect/pr103744-1.c b/gcc/testsuite/gcc.dg/vect/pr103744-1.c
new file mode 100644 (file)
index 0000000..1bc81e2
--- /dev/null
@@ -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;
+    }
+}
diff --git a/gcc/testsuite/gcc.dg/vect/pr103744-2.c b/gcc/testsuite/gcc.dg/vect/pr103744-2.c
new file mode 100644 (file)
index 0000000..52307ab
--- /dev/null
@@ -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;
+}
index ad90cdb0473a337207d6ba54c1dd0a2ecc50ab8d..c842d500d104be0cdbcea02532aafed20a942421 100644 (file)
@@ -9249,6 +9249,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);
@@ -9594,7 +9596,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);
 
@@ -9611,7 +9613,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;