omp-low.c (lower_omp_1): Look through ordered...
authorJakub Jelinek <jakub@redhat.com>
Mon, 27 May 2019 21:31:40 +0000 (23:31 +0200)
committerJakub Jelinek <jakub@gcc.gnu.org>
Mon, 27 May 2019 21:31:40 +0000 (23:31 +0200)
* omp-low.c (lower_omp_1) <case GIMPLE_ASSIGN>: Look through ordered,
critical, taskgroup and section regions when looking for a region
with non-NULL lastprivate_conditional_map.

* testsuite/libgomp.c-c++-common/lastprivate-conditional-3.c: New test.

From-SVN: r271672

gcc/ChangeLog
gcc/omp-low.c
libgomp/ChangeLog
libgomp/testsuite/libgomp.c-c++-common/lastprivate-conditional-3.c [new file with mode: 0644]

index a6f75ae5096a921b4594b9850632b57ed8371642..ce0004358ce42e7a9afb5f034da54192f3aacf90 100644 (file)
@@ -1,3 +1,9 @@
+2019-05-27  Jakub Jelinek  <jakub@redhat.com>
+
+       * omp-low.c (lower_omp_1) <case GIMPLE_ASSIGN>: Look through ordered,
+       critical, taskgroup and section regions when looking for a region
+       with non-NULL lastprivate_conditional_map.
+
 2019-05-27  Uroš Bizjak  <ubizjak@gmail.com>
 
        * config/i386/i386.c (ix86_gen_add3): Remove indirect function.
index faab5d3842800bafc9dab04f4d8154f9ba127f49..db9f5047c72d667f80eb1674c59aefebc6b23059 100644 (file)
@@ -10627,14 +10627,21 @@ lower_omp_1 (gimple_stmt_iterator *gsi_p, omp_context *ctx)
       goto regimplify;
 
     case GIMPLE_ASSIGN:
-      if (ctx && ctx->lastprivate_conditional_map)
+      for (omp_context *up = ctx; up; up = up->outer)
        {
+         if (gimple_code (up->stmt) == GIMPLE_OMP_ORDERED
+             || gimple_code (up->stmt) == GIMPLE_OMP_CRITICAL
+             || gimple_code (up->stmt) == GIMPLE_OMP_TASKGROUP
+             || gimple_code (up->stmt) == GIMPLE_OMP_SECTION)
+           continue;
+         else if (!up->lastprivate_conditional_map)
+           break;
          tree lhs = get_base_address (gimple_assign_lhs (stmt));
          if (DECL_P (lhs))
-           if (tree *v = ctx->lastprivate_conditional_map->get (lhs))
+           if (tree *v = up->lastprivate_conditional_map->get (lhs))
              {
                tree clauses
-                 = gimple_omp_for_clauses (as_a <gomp_for *> (ctx->stmt));
+                 = gimple_omp_for_clauses (as_a <gomp_for *> (up->stmt));
                tree c = omp_find_clause (clauses, OMP_CLAUSE__CONDTEMP_);
                c = omp_find_clause (OMP_CLAUSE_CHAIN (c),
                                     OMP_CLAUSE__CONDTEMP_);
index 73bc23e80d0e4b23a318a29f4d0c055487cc079a..33906ededc7e298de50bdbad86ee4207b42111a8 100644 (file)
@@ -1,5 +1,7 @@
 2019-05-27  Jakub Jelinek  <jakub@redhat.com>
 
+       * testsuite/libgomp.c-c++-common/lastprivate-conditional-3.c: New test.
+
        PR libgomp/90641
        * work.c (gomp_init_work_share): Instead of aligning final ordered
        value to multiples of long long alignment, align to that the
diff --git a/libgomp/testsuite/libgomp.c-c++-common/lastprivate-conditional-3.c b/libgomp/testsuite/libgomp.c-c++-common/lastprivate-conditional-3.c
new file mode 100644 (file)
index 0000000..6c4370a
--- /dev/null
@@ -0,0 +1,57 @@
+/* { dg-do run } */
+/* { dg-require-effective-target tls_runtime } */
+/* { dg-additional-options "-std=gnu99" {target c } } */
+
+#include <omp.h>
+#include <stdlib.h>
+
+int r, s, u, v, t;
+int *x;
+
+void
+foo (int *a)
+{
+  int i;
+  long long j;
+  #pragma omp for lastprivate (conditional: u, x) ordered
+  for (i = 15; i < 64; i++)
+    {
+      #pragma omp critical
+      {
+       if ((a[i] % 5) == 3)
+         u = i;
+      }
+      #pragma omp ordered
+      {
+       if ((a[i] % 7) == 2)
+         x = &a[i];
+      }
+    }
+  #pragma omp for lastprivate (conditional: v) reduction (+:r, s) schedule (nonmonotonic: static) reduction (task, +: t)
+  for (i = -3; i < 119; i += 2)
+    {
+      ++s;
+      #pragma omp taskgroup
+      {
+       #pragma omp task in_reduction (+: t)
+         ++t;
+       if ((a[i + 4] % 11) == 9)
+         v = i;
+       else
+         ++r;
+      }
+    }
+}
+
+int
+main ()
+{
+  int a[128], i;
+  for (i = 0; i < 128; i++)
+    a[i] = i;
+  #pragma omp parallel
+  foo (a);
+  if (u != 63 || v != 115 || x != &a[58] || r != 55 || s != 61 || t != 61)
+    abort ();
+  return 0;
+}