Hi!

When working on scan, I've noticed I forgot to emit in loops
that use GOMP_loop_start just to allocate some memory also
GOMP_loop_end_nowait to allow destroying of that worksharing structure on
the libgomp side.

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

2019-07-03  Jakub Jelinek  <ja...@redhat.com>

        * omp-expand.c (expand_omp_for_static_nochunk,
        expand_omp_for_static_chunk): For nowait worksharing loop with
        conditional lastprivate clause(s), emit GOMP_loop_end_nowait call
        at the end.

        * c-c++-common/gomp/lastprivate-conditional-5.c: New test.

--- gcc/omp-expand.c.jj 2019-07-01 12:33:57.739215084 +0200
+++ gcc/omp-expand.c    2019-07-01 12:40:33.778182080 +0200
@@ -4039,6 +4039,12 @@ expand_omp_for_static_nochunk (struct om
       else
        gsi_insert_after (&gsi, omp_build_barrier (t), GSI_SAME_STMT);
     }
+  else if (fd->have_pointer_condtemp)
+    {
+      tree fn = builtin_decl_explicit (BUILT_IN_GOMP_LOOP_END_NOWAIT);
+      gcall *g = gimple_build_call (fn, 0);
+      gsi_insert_after (&gsi, g, GSI_SAME_STMT);
+    }
   gsi_remove (&gsi, true);
 
   /* Connect all the blocks.  */
@@ -4696,6 +4702,12 @@ expand_omp_for_static_chunk (struct omp_
       else
        gsi_insert_after (&gsi, omp_build_barrier (t), GSI_SAME_STMT);
     }
+  else if (fd->have_pointer_condtemp)
+    {
+      tree fn = builtin_decl_explicit (BUILT_IN_GOMP_LOOP_END_NOWAIT);
+      gcall *g = gimple_build_call (fn, 0);
+      gsi_insert_after (&gsi, g, GSI_SAME_STMT);
+    }
   gsi_remove (&gsi, true);
 
   /* Connect the new blocks.  */
--- gcc/testsuite/c-c++-common/gomp/lastprivate-conditional-5.c.jj      
2019-07-01 12:47:59.191458100 +0200
+++ gcc/testsuite/c-c++-common/gomp/lastprivate-conditional-5.c 2019-07-01 
12:56:29.414946288 +0200
@@ -0,0 +1,33 @@
+/* { dg-do compile } */
+/* { dg-options "-O2 -fopenmp -fdump-tree-ompexp" } */
+/* { dg-final { scan-tree-dump-times "GOMP_loop_start " 3 "ompexp" } } */
+/* { dg-final { scan-tree-dump-times "GOMP_loop_end_nowait " 3 "ompexp" } } */
+
+int r;
+
+void
+foo (int *a)
+{
+  #pragma omp for nowait lastprivate(conditional: r)
+  for (int i = 0; i < 64; ++i)
+    if (a[i])
+      r = a[i];
+}
+
+void
+bar (int *a)
+{
+  #pragma omp for nowait lastprivate(conditional: r) schedule (static, 4)
+  for (int i = 0; i < 64; ++i)
+    if (a[i])
+      r = a[i];
+}
+
+void
+baz (int *a)
+{
+  #pragma omp for nowait lastprivate(conditional: r) schedule (runtime)
+  for (int i = 0; i < 64; ++i)
+    if (a[i])
+      r = a[i];
+}

        Jakub

Reply via email to