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] Fix handling of OpenMP implicit linear/lastprivate clauses (PR middle-end/70680)


Hi!

The following testcases show incorrect handling of implicit linear or
lastprivate clauses on the #pragma omp simd iterators, if the vars aren't
private in the outer context and they aren't in combined constructs, they
should be noticed in the outer context.

Bootstrapped/regtested on x86_64-linux and i686-linux, committed to trunk,
queued up for 6 branch after 6.1 is released.

2016-04-19  Jakub Jelinek  <jakub@redhat.com>

	PR middle-end/70680
	* gimplify.c (gimplify_omp_for): Call omp_notice_variable for
	implicitly linear or lastprivate iterator on the outer context.

	* testsuite/libgomp.c/pr70680-1.c: New test.
	* testsuite/libgomp.c/pr70680-2.c: New test.

--- gcc/gimplify.c.jj	2016-04-15 18:04:42.000000000 +0200
+++ gcc/gimplify.c	2016-04-19 20:03:19.347936293 +0200
@@ -8785,7 +8785,10 @@ gimplify_omp_for (tree *expr_p, gimple_s
 						  decl, false))
 		    ;
 		  else if (outer->region_type != ORT_COMBINED_PARALLEL)
-		    outer = NULL;
+		    {
+		      omp_notice_variable (outer, decl, true);
+		      outer = NULL;
+		    }
 		  if (outer)
 		    {
 		      n = splay_tree_lookup (outer->variables,
@@ -8868,7 +8871,10 @@ gimplify_omp_for (tree *expr_p, gimple_s
 						  decl, false))
 		    ;
 		  else if (outer->region_type != ORT_COMBINED_PARALLEL)
-		    outer = NULL;
+		    {
+		      omp_notice_variable (outer, decl, true);
+		      outer = NULL;
+		    }
 		  if (outer)
 		    {
 		      n = splay_tree_lookup (outer->variables,
--- libgomp/testsuite/libgomp.c/pr70680-1.c.jj	2016-04-19 20:13:54.998588014 +0200
+++ libgomp/testsuite/libgomp.c/pr70680-1.c	2016-04-19 20:01:54.000000000 +0200
@@ -0,0 +1,75 @@
+/* PR middle-end/70680 */
+
+int v;
+
+void
+f1 (void)
+{
+  int i = 0;
+#pragma omp task default(shared) if(0)
+  {
+#pragma omp simd
+    for (i = 0; i < 100; i++)
+      ;
+    v = i;
+  }
+  if (i != 100)
+    __builtin_abort ();
+}
+
+void
+f2 (void)
+{
+  int i = 0;
+#pragma omp task default(shared) if(0)
+  {
+#pragma omp simd
+    for (i = 0; i < 100; i++)
+      ;
+  }
+  if (i != 100)
+    __builtin_abort ();
+}
+
+void
+f3 (void)
+{
+  int i = 0;
+#pragma omp task default(shared) if(0)
+  {
+#pragma omp simd linear(i: 1)
+    for (i = 0; i < 100; i++)
+      ;
+    v = i;
+  }
+  if (i != 100)
+    __builtin_abort ();
+}
+
+void
+f4 (void)
+{
+  int i = 0;
+#pragma omp task default(shared) if(0)
+  {
+#pragma omp simd linear(i: 1)
+    for (i = 0; i < 100; i++)
+      ;
+  }
+  if (i != 100)
+    __builtin_abort ();
+}
+
+int
+main ()
+{
+  f1 ();
+  if (v++ != 100)
+    __builtin_abort ();
+  f2 ();
+  f3 ();
+  if (v++ != 100)
+    __builtin_abort ();
+  f4 ();
+  return 0;
+}
--- libgomp/testsuite/libgomp.c/pr70680-2.c.jj	2016-04-19 20:13:59.570527869 +0200
+++ libgomp/testsuite/libgomp.c/pr70680-2.c	2016-04-19 20:09:02.000000000 +0200
@@ -0,0 +1,79 @@
+/* PR middle-end/70680 */
+
+int v;
+
+void
+f1 (void)
+{
+  int i = 0, j = 0;
+#pragma omp task default(shared) if(0)
+  {
+#pragma omp simd collapse(2)
+    for (i = 0; i < 10; i++)
+      for (j = 0; j < 10; j++)
+	;
+    v = i + j;
+  }
+  if (i != 10 || j != 10)
+    __builtin_abort ();
+}
+
+void
+f2 (void)
+{
+  int i = 0, j = 0;
+#pragma omp task default(shared) if(0)
+  {
+#pragma omp simd collapse(2)
+    for (i = 0; i < 10; i++)
+      for (j = 0; j < 10; j++)
+	;
+  }
+  if (i != 10 || j != 10)
+    __builtin_abort ();
+}
+
+void
+f3 (void)
+{
+  int i = 0, j = 0;
+#pragma omp task default(shared) if(0)
+  {
+#pragma omp simd collapse(2) lastprivate (i, j)
+    for (i = 0; i < 10; i++)
+      for (j = 0; j < 10; j++)
+	;
+    v = i + j;
+  }
+  if (i != 10 || j != 10)
+    __builtin_abort ();
+}
+
+void
+f4 (void)
+{
+  int i = 0, j = 0;
+#pragma omp task default(shared) if(0)
+  {
+#pragma omp simd collapse(2) lastprivate (i, j)
+    for (i = 0; i < 10; i++)
+      for (j = 0; j < 10; j++)
+	;
+  }
+  if (i != 10 || j != 10)
+    __builtin_abort ();
+}
+
+int
+main ()
+{
+  f1 ();
+  if (v++ != 20)
+    __builtin_abort ();
+  f2 ();
+  f3 ();
+  if (v++ != 20)
+    __builtin_abort ();
+  f4 ();
+  return 0;
+}

	Jakub


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