public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
From: Richard Sandiford <rsandifo@gcc.gnu.org>
To: gcc-cvs@gcc.gnu.org
Subject: [gcc r12-6041] vect: Fix multi-vector SLP gather loads [PR103744]
Date: Fri, 17 Dec 2021 14:18:49 +0000 (GMT)	[thread overview]
Message-ID: <20211217141849.7789A3858407@sourceware.org> (raw)

https://gcc.gnu.org/g:e781cb93d7d908f1f4f1611d0034eccbd1478e91

commit r12-6041-ge781cb93d7d908f1f4f1611d0034eccbd1478e91
Author: Richard Sandiford <richard.sandiford@arm.com>
Date:   Fri Dec 17 14:18:39 2021 +0000

    vect: Fix multi-vector SLP gather loads [PR103744]
    
    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.

Diff:
---
 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(-)

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 ad90cdb0473..c842d500d10 100644
--- a/gcc/tree-vect-stmts.c
+++ b/gcc/tree-vect-stmts.c
@@ -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;


                 reply	other threads:[~2021-12-17 14:18 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=20211217141849.7789A3858407@sourceware.org \
    --to=rsandifo@gcc.gnu.org \
    --cc=gcc-cvs@gcc.gnu.org \
    /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).