This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[committed] Improve simd with a single lastprivate iterator


Hi!

While the iterator of a simd collapse(1) loop is predetermined linear, in
OpenMP 5 one can specify it also explicitly in a linear, lastprivate or
private clause.  The following testcase shows that we weren't vectorizing
those if the iterator wasn't addressable and has been explicitly
lastprivate, as the magic simd arrays prevented number of iterations
computation.  Fixed by not forcing it into a simd array in that case.

Bootstrapped/regtested on x86_64-linux and i686-linux, committed to trunk.

2019-07-20  Jakub Jelinek  <jakub@redhat.com>

	* omp-low.c (lower_rec_input_clauses): Don't force simd arrays for
	lastprivate non-addressable iterator of a collapse(1) simd.

	* gcc.dg/vect/vect-simd-16.c: New test.

--- gcc/omp-low.c.jj	2019-07-19 13:25:52.001314547 +0200
+++ gcc/omp-low.c	2019-07-19 17:01:17.168704782 +0200
@@ -5123,7 +5123,10 @@ lower_rec_input_clauses (tree clauses, g
 		{
 		  tree y = lang_hooks.decls.omp_clause_dtor (c, new_var);
 		  if ((TREE_ADDRESSABLE (new_var) || nx || y
-		       || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_LASTPRIVATE
+		       || (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_LASTPRIVATE
+			   && (gimple_omp_for_collapse (ctx->stmt) != 1
+			       || (gimple_omp_for_index (ctx->stmt, 0)
+				   != new_var)))
 		       || OMP_CLAUSE_CODE (c) == OMP_CLAUSE__CONDTEMP_
 		       || omp_is_reference (var))
 		      && lower_rec_simd_input_clauses (new_var, ctx, &sctx,
--- gcc/testsuite/gcc.dg/vect/vect-simd-16.c.jj	2019-07-19 17:16:24.035069658 +0200
+++ gcc/testsuite/gcc.dg/vect/vect-simd-16.c	2019-07-19 17:20:48.034099757 +0200
@@ -0,0 +1,61 @@
+/* { dg-additional-options "-fopenmp-simd" } */
+/* { dg-additional-options "-mavx" { target avx_runtime } } */
+/* { dg-final { scan-tree-dump-times "vectorized \[1-3] loops" 3 "vect" { target i?86-*-* x86_64-*-* } } } */
+
+#include "tree-vect.h"
+
+__attribute__((noipa)) int
+foo (int *a)
+{
+  int i;
+  #pragma omp simd lastprivate (i)
+  for (i = 0; i < 64; i++)
+    a[i] = i;
+  return i;
+}
+
+__attribute__((noipa)) void
+bar (int *a)
+{
+  int i;
+  #pragma omp simd private (i)
+  for (i = 0; i < 64; i++)
+    a[i] = i + 1;
+}
+
+__attribute__((noipa)) int
+baz (int *a)
+{
+  int i;
+  #pragma omp simd linear (i)
+  for (i = 0; i < 64; i++)
+    a[i] = i + 2;
+  return i;
+}
+
+int
+main ()
+{
+  int i;
+  int a[64];
+  check_vect ();
+  if (foo (a) != 64)
+    abort ();
+  for (i = 0; i < 64; ++i)
+    if (a[i] != i)
+      abort ();
+    else
+      a[i] = -8;
+  bar (a);
+  for (i = 0; i < 64; ++i)
+    if (a[i] != i + 1)
+      abort ();
+    else
+      a[i] = -8;
+  if (baz (a) != 64)
+    abort ();
+  for (i = 0; i < 64; ++i)
+    if (a[i] != i + 2)
+      abort ();
+  return 0;
+}

	Jakub


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]