public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH] vect: Fix multi-vector SLP gather loads [PR103744]
@ 2021-12-16 15:43 Richard Sandiford
  0 siblings, 0 replies; only message in thread
From: Richard Sandiford @ 2021-12-16 15:43 UTC (permalink / raw)
  To: gcc-patches; +Cc: rguenther

[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

diff --git a/gcc/testsuite/gcc.dg/vect/pr103744-1.c b/gcc/testsuite/gcc.dg/vect/pr103744-1.c
new file mode 100644
index 00000000000..1bc81e26fe4
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/vect/pr103744-1.c
@@ -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
index 00000000000..52307abf246
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/vect/pr103744-2.c
@@ -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;
+}
diff --git a/gcc/tree-vect-stmts.c b/gcc/tree-vect-stmts.c
index 8c427174b37..720cf36caaf 100644
--- a/gcc/tree-vect-stmts.c
+++ b/gcc/tree-vect-stmts.c
@@ -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;
-- 
2.25.1


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2021-12-16 15:43 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-12-16 15:43 [PATCH] vect: Fix multi-vector SLP gather loads [PR103744] Richard Sandiford

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).