public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc/devel/omp/gcc-12] vect: Fix missed gather load opportunity
@ 2023-03-17 13:06 Andrew Stubbs
  0 siblings, 0 replies; only message in thread
From: Andrew Stubbs @ 2023-03-17 13:06 UTC (permalink / raw)
  To: gcc-cvs

https://gcc.gnu.org/g:833d374cd75810b8831f84c00c60c23d9e77788f

commit 833d374cd75810b8831f84c00c60c23d9e77788f
Author: Richard Sandiford <richard.sandiford@arm.com>
Date:   Tue Sep 20 15:27:46 2022 +0100

    vect: Fix missed gather load opportunity
    
    While writing a testcase for PR106794, I noticed that we failed
    to vectorise the testcase in the patch for SVE.  The code that
    recognises gather loads tries to optimise the point at which
    the offset is calculated, to avoid unnecessary extensions or
    truncations:
    
              /* Don't include the conversion if the target is happy with
                 the current offset type.  */
    
    But breaking only makes sense if we're at an SSA_NAME (which could
    then be vectorised).  We shouldn't break on a conversion embedded
    in a generic expression.
    
    gcc/
            * tree-vect-data-refs.cc (vect_check_gather_scatter): Restrict
            early-out optimisation to SSA_NAMEs.
    
    gcc/testsuite/
            * gcc.dg/vect/vect-gather-5.c: New test.
    
    (cherry picked from commit 4a773bf2f08656a39ac75cf6b4871c8cec8b5007)

Diff:
---
 gcc/ChangeLog.omp                         |  7 ++++++
 gcc/testsuite/ChangeLog.omp               |  6 +++++
 gcc/testsuite/gcc.dg/vect/vect-gather-5.c | 42 +++++++++++++++++++++++++++++++
 gcc/tree-vect-data-refs.cc                |  1 +
 4 files changed, 56 insertions(+)

diff --git a/gcc/ChangeLog.omp b/gcc/ChangeLog.omp
index 3a3e54bdeb2..fdccdabf72b 100644
--- a/gcc/ChangeLog.omp
+++ b/gcc/ChangeLog.omp
@@ -1,3 +1,10 @@
+2023-03-17  Andrew Stubbs  <ams@codesourcery.com>
+
+	Backport from mainline:
+	Richard Sandiford <richard.sandiford@arm.com>
+	* tree-vect-data-refs.cc (vect_check_gather_scatter): Restrict
+	early-out optimisation to SSA_NAMEs.
+
 2023-03-17  Andrew Stubbs  <ams@codesourcery.com>
 
 	* config/gcn/gcn-valu.md (gather_load<mode><vndi>): New.
diff --git a/gcc/testsuite/ChangeLog.omp b/gcc/testsuite/ChangeLog.omp
index 860ecdc780b..19357b0b5c2 100644
--- a/gcc/testsuite/ChangeLog.omp
+++ b/gcc/testsuite/ChangeLog.omp
@@ -1,3 +1,9 @@
+2023-03-17  Andrew Stubbs  <ams@codesourcery.com>
+
+	Backport from mainline:
+	Richard Sandiford <richard.sandiford@arm.com>
+	* gcc.dg/vect/vect-gather-5.c: New test.
+
 2023-03-06  Paul-Antoine Arras <pa@codesourcery.com>
 
 	Backported from master:
diff --git a/gcc/testsuite/gcc.dg/vect/vect-gather-5.c b/gcc/testsuite/gcc.dg/vect/vect-gather-5.c
new file mode 100644
index 00000000000..8b5074bba88
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/vect/vect-gather-5.c
@@ -0,0 +1,42 @@
+/* { dg-do compile } */
+/* { dg-additional-options "-O3" } */
+
+#ifdef __aarch64__
+#pragma GCC target "+sve"
+#endif
+
+long a[100], b[100], c[100];
+
+void g1 ()
+{
+  for (int i = 0; i < 100; i += 2)
+    {
+      c[i] += a[b[i]] + 1;
+      c[i + 1] += a[b[i + 1]] + 2;
+    }
+}
+
+long g2 ()
+{
+  long res = 0;
+  for (int i = 0; i < 100; i += 2)
+    {
+      res += a[b[i + 1]];
+      res += a[b[i]];
+    }
+  return res;
+}
+
+long g3 ()
+{
+  long res = 0;
+  for (int i = 0; i < 100; i += 2)
+    {
+      res += a[b[i]];
+      res += a[b[i + 1]];
+    }
+  return res;
+}
+
+/* { dg-final { scan-tree-dump-times {add new stmt[^\n]*GATHER_LOAD} 3 "vect" { target aarch64*-*-* } } } */
+/* { dg-final { scan-tree-dump-not {add new stmt[^\n]*VEC_PERM_EXPR} "vect" { target aarch64*-*-* } } } */
diff --git a/gcc/tree-vect-data-refs.cc b/gcc/tree-vect-data-refs.cc
index 70b671ed94a..21a7192bf24 100644
--- a/gcc/tree-vect-data-refs.cc
+++ b/gcc/tree-vect-data-refs.cc
@@ -4151,6 +4151,7 @@ vect_check_gather_scatter (stmt_vec_info stmt_info, loop_vec_info loop_vinfo,
 	  /* Don't include the conversion if the target is happy with
 	     the current offset type.  */
 	  if (use_ifn_p
+	      && TREE_CODE (off) == SSA_NAME
 	      && !POINTER_TYPE_P (TREE_TYPE (off))
 	      && vect_gather_scatter_fn_p (loop_vinfo, DR_IS_READ (dr),
 					   masked_p, vectype, memory_type,

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

only message in thread, other threads:[~2023-03-17 13:06 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-03-17 13:06 [gcc/devel/omp/gcc-12] vect: Fix missed gather load opportunity Andrew Stubbs

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).