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] Don't optimize away OpenMP tasks with empty bodies, but with depend clauses (PR libgomp/80394)


Hi!

Tasks that have depend clauses can't be optimized away even if they
have empty body, the depend clause still has important side-effects.

Fixed thusly, bootstrapped/regtested on x86_64-linux and i686-linux,
committed to trunk, queued for backporting.

2017-04-11  Jakub Jelinek  <jakub@redhat.com>

	PR libgomp/80394
	* omp-low.c (scan_omp_task): Don't optimize away empty tasks
	if they have any depend clauses.

	* testsuite/libgomp.c/pr80394.c: New test.

--- gcc/omp-low.c.jj	2017-03-29 07:11:14.000000000 +0200
+++ gcc/omp-low.c	2017-04-11 15:17:32.608077934 +0200
@@ -1857,9 +1857,11 @@ scan_omp_task (gimple_stmt_iterator *gsi
   tree name, t;
   gomp_task *stmt = as_a <gomp_task *> (gsi_stmt (*gsi));
 
-  /* Ignore task directives with empty bodies.  */
+  /* Ignore task directives with empty bodies, unless they have depend
+     clause.  */
   if (optimize > 0
-      && empty_body_p (gimple_omp_body (stmt)))
+      && empty_body_p (gimple_omp_body (stmt))
+      && !omp_find_clause (gimple_omp_task_clauses (stmt), OMP_CLAUSE_DEPEND))
     {
       gsi_replace (gsi, gimple_build_nop (), false);
       return;
--- libgomp/testsuite/libgomp.c/pr80394.c.jj	2017-04-11 15:14:18.783514493 +0200
+++ libgomp/testsuite/libgomp.c/pr80394.c	2017-04-11 15:13:56.460795111 +0200
@@ -0,0 +1,22 @@
+/* PR libgomp/80394 */
+
+int
+main ()
+{
+  int x = 0;
+  #pragma omp parallel shared(x)
+  #pragma omp single
+  {
+    #pragma omp task depend(inout: x)
+    {
+      for (int i = 0; i < 100000; i++)
+        asm volatile ("" : : : "memory");
+      x += 5;
+    }
+    #pragma omp task if (0) depend(inout: x)
+    ;
+    if (x != 5)
+      __builtin_abort ();
+  }
+  return 0;
+}

	Jakub


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