public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc r8-10869] openmp, openacc: Fix up handling of data regions [PR98183]
@ 2021-04-22 16:49 Jakub Jelinek
  0 siblings, 0 replies; only message in thread
From: Jakub Jelinek @ 2021-04-22 16:49 UTC (permalink / raw)
  To: gcc-cvs

https://gcc.gnu.org/g:ac7f86aab4f8ca2db7cc7f97fcd2eebdec6be9d8

commit r8-10869-gac7f86aab4f8ca2db7cc7f97fcd2eebdec6be9d8
Author: Jakub Jelinek <jakub@redhat.com>
Date:   Sat Dec 12 08:36:02 2020 +0100

    openmp, openacc: Fix up handling of data regions [PR98183]
    
    While the data regions (target data and OpenACC counterparts) aren't
    standalone directives, unlike most other OpenMP/OpenACC constructs
    we allow (apparently as an extension) exceptions and goto out of
    the block. During gimplification we place an *end* call into a finally
    block so that it is reached even on exceptions or goto out etc.).
    During omplower pass we then add paired #pragma omp return for them,
    but due to the exceptions because the region is not SESE we can end up
    with #pragma omp return appearing only conditionally in the CFG etc.,
    which the ompexp pass can't handle.
    For the ompexp pass, we actually don't care about the end part or about
    target data nesting, so we can treat it as standalone directive.
    
    2020-12-12  Jakub Jelinek  <jakub@redhat.com>
    
            PR middle-end/98183
            * omp-low.c (lower_omp_target): Don't add OMP_RETURN for
            data regions.
            * omp-expand.c (expand_omp_target): Don't try to remove
            OMP_RETURN for data regions.
            (build_omp_regions_1, omp_make_gimple_edges): Don't expect
            OMP_RETURN for data regions.
    
            * gcc.dg/gomp/pr98183.c: New test.
            * gcc.dg/goacc/pr98183.c: New test.
    
    (cherry picked from commit 8c1ed7223ad1bc19ed9c936ba496220c8ef673bc)

Diff:
---
 gcc/omp-expand.c                     | 24 +++++++-----------------
 gcc/omp-low.c                        |  7 ++++---
 gcc/testsuite/gcc.dg/goacc/pr98183.c | 15 +++++++++++++++
 gcc/testsuite/gcc.dg/gomp/pr98183.c  | 15 +++++++++++++++
 4 files changed, 41 insertions(+), 20 deletions(-)

diff --git a/gcc/omp-expand.c b/gcc/omp-expand.c
index a2ec912323e..1967da1ddb1 100644
--- a/gcc/omp-expand.c
+++ b/gcc/omp-expand.c
@@ -6911,7 +6911,7 @@ expand_omp_target (struct omp_region *region)
   gomp_target *entry_stmt;
   gimple *stmt;
   edge e;
-  bool offloaded, data_region;
+  bool offloaded;
 
   entry_stmt = as_a <gomp_target *> (last_stmt (region->entry));
   new_bb = region->entry;
@@ -6928,12 +6928,9 @@ expand_omp_target (struct omp_region *region)
     case GF_OMP_TARGET_KIND_OACC_UPDATE:
     case GF_OMP_TARGET_KIND_OACC_ENTER_EXIT_DATA:
     case GF_OMP_TARGET_KIND_OACC_DECLARE:
-      data_region = false;
-      break;
     case GF_OMP_TARGET_KIND_DATA:
     case GF_OMP_TARGET_KIND_OACC_DATA:
     case GF_OMP_TARGET_KIND_OACC_HOST_DATA:
-      data_region = true;
       break;
     default:
       gcc_unreachable ();
@@ -7419,13 +7416,6 @@ expand_omp_target (struct omp_region *region)
       gcc_assert (g && gimple_code (g) == GIMPLE_OMP_TARGET);
       gsi_remove (&gsi, true);
     }
-  if (data_region && region->exit)
-    {
-      gsi = gsi_last_nondebug_bb (region->exit);
-      g = gsi_stmt (gsi);
-      gcc_assert (g && gimple_code (g) == GIMPLE_OMP_RETURN);
-      gsi_remove (&gsi, true);
-    }
 }
 
 /* Expand KFOR loop as a HSA grifidied kernel, i.e. as a body only with
@@ -7887,15 +7877,15 @@ build_omp_regions_1 (basic_block bb, struct omp_region *parent,
 	      switch (gimple_omp_target_kind (stmt))
 		{
 		case GF_OMP_TARGET_KIND_REGION:
-		case GF_OMP_TARGET_KIND_DATA:
 		case GF_OMP_TARGET_KIND_OACC_PARALLEL:
 		case GF_OMP_TARGET_KIND_OACC_KERNELS:
-		case GF_OMP_TARGET_KIND_OACC_DATA:
-		case GF_OMP_TARGET_KIND_OACC_HOST_DATA:
 		  break;
 		case GF_OMP_TARGET_KIND_UPDATE:
 		case GF_OMP_TARGET_KIND_ENTER_DATA:
 		case GF_OMP_TARGET_KIND_EXIT_DATA:
+		case GF_OMP_TARGET_KIND_DATA:
+		case GF_OMP_TARGET_KIND_OACC_DATA:
+		case GF_OMP_TARGET_KIND_OACC_HOST_DATA:
 		case GF_OMP_TARGET_KIND_OACC_UPDATE:
 		case GF_OMP_TARGET_KIND_OACC_ENTER_EXIT_DATA:
 		case GF_OMP_TARGET_KIND_OACC_DECLARE:
@@ -8131,15 +8121,15 @@ omp_make_gimple_edges (basic_block bb, struct omp_region **region,
       switch (gimple_omp_target_kind (last))
 	{
 	case GF_OMP_TARGET_KIND_REGION:
-	case GF_OMP_TARGET_KIND_DATA:
 	case GF_OMP_TARGET_KIND_OACC_PARALLEL:
 	case GF_OMP_TARGET_KIND_OACC_KERNELS:
-	case GF_OMP_TARGET_KIND_OACC_DATA:
-	case GF_OMP_TARGET_KIND_OACC_HOST_DATA:
 	  break;
 	case GF_OMP_TARGET_KIND_UPDATE:
 	case GF_OMP_TARGET_KIND_ENTER_DATA:
 	case GF_OMP_TARGET_KIND_EXIT_DATA:
+	case GF_OMP_TARGET_KIND_DATA:
+	case GF_OMP_TARGET_KIND_OACC_DATA:
+	case GF_OMP_TARGET_KIND_OACC_HOST_DATA:
 	case GF_OMP_TARGET_KIND_OACC_UPDATE:
 	case GF_OMP_TARGET_KIND_OACC_ENTER_EXIT_DATA:
 	case GF_OMP_TARGET_KIND_OACC_DECLARE:
diff --git a/gcc/omp-low.c b/gcc/omp-low.c
index 996989cef0e..2ccf6129386 100644
--- a/gcc/omp-low.c
+++ b/gcc/omp-low.c
@@ -8612,9 +8612,10 @@ lower_omp_target (gimple_stmt_iterator *gsi_p, omp_context *ctx)
       gimple_seq_add_seq (&new_body, join_seq);
 
       if (offloaded)
-	new_body = maybe_catch_exception (new_body);
-
-      gimple_seq_add_stmt (&new_body, gimple_build_omp_return (false));
+	{
+	  new_body = maybe_catch_exception (new_body);
+	  gimple_seq_add_stmt (&new_body, gimple_build_omp_return (false));
+	}
       gimple_omp_set_body (stmt, new_body);
     }
 
diff --git a/gcc/testsuite/gcc.dg/goacc/pr98183.c b/gcc/testsuite/gcc.dg/goacc/pr98183.c
new file mode 100644
index 00000000000..b0410117c84
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/goacc/pr98183.c
@@ -0,0 +1,15 @@
+/* PR middle-end/98183 */
+/* { dg-additional-options "-fexceptions -O0" } */
+
+void bar (void);
+int x, y;
+
+void
+foo (void)
+{
+#pragma acc data copyout(x)
+  {
+#pragma acc data copyout(y)
+    bar ();
+  }
+}
diff --git a/gcc/testsuite/gcc.dg/gomp/pr98183.c b/gcc/testsuite/gcc.dg/gomp/pr98183.c
new file mode 100644
index 00000000000..dd114997920
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/gomp/pr98183.c
@@ -0,0 +1,15 @@
+/* PR middle-end/98183 */
+/* { dg-additional-options "-fexceptions -O0" } */
+
+void bar (void);
+int x, y;
+
+void
+foo (void)
+{
+#pragma omp target data map(tofrom: x)
+  {
+#pragma omp target data map(tofrom: y)
+    bar ();
+  }
+}


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2021-04-22 16:49 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-04-22 16:49 [gcc r8-10869] openmp, openacc: Fix up handling of data regions [PR98183] Jakub Jelinek

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).