public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Richard Sandiford <richard.sandiford@arm.com>
To: gcc-patches@gcc.gnu.org
Cc: rguenther@suse.de
Subject: [PATCH] vect: Fix multi-vector SLP gather loads [PR103744]
Date: Thu, 16 Dec 2021 15:43:45 +0000	[thread overview]
Message-ID: <mpto85gbln2.fsf@arm.com> (raw)

[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


                 reply	other threads:[~2021-12-16 15:43 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=mpto85gbln2.fsf@arm.com \
    --to=richard.sandiford@arm.com \
    --cc=gcc-patches@gcc.gnu.org \
    --cc=rguenther@suse.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).