Fortran: Fixes for OpenMP loop-iter privatization (PRs 95109 + 94690)
authorTobias Burnus <tobias@codesourcery.com>
Wed, 9 Sep 2020 07:33:51 +0000 (09:33 +0200)
committerTobias Burnus <tobias@codesourcery.com>
Wed, 9 Sep 2020 07:33:51 +0000 (09:33 +0200)
This commit also fixes a gfortran.dg/gomp/target1.f90 regression;
target1.f90 tests the resolve.c and openmp.c changes.

gcc/fortran/ChangeLog:

PR fortran/95109
PR fortran/94690
* resolve.c (gfc_resolve_code): Also call
gfc_resolve_omp_parallel_blocks for 'distribute parallel do (simd)'.
* openmp.c (gfc_resolve_omp_parallel_blocks): Handle it.
(gfc_resolve_do_iterator): Remove special code for SIMD, which is
not needed.
* trans-openmp.c (gfc_trans_omp_target): For TARGET_PARALLEL_DO_SIMD,
call simd not do processing function.

gcc/testsuite/ChangeLog:

PR fortran/95109
PR fortran/94690
* gfortran.dg/gomp/combined-if.f90: Update scan-tree-dump-times for
'omp simd.*if'.
* gfortran.dg/gomp/openmp-simd-5.f90: New test.

gcc/fortran/openmp.c
gcc/fortran/resolve.c
gcc/fortran/trans-openmp.c
gcc/testsuite/gfortran.dg/gomp/combined-if.f90
gcc/testsuite/gfortran.dg/gomp/openmp-simd-5.f90 [new file with mode: 0644]

index d0e516c472ddd72d5310fdf6e1167fbceb68ceba..1efce33e5194d1b4baf38b4ed33dc7fefb77f27e 100644 (file)
@@ -5962,6 +5962,8 @@ gfc_resolve_omp_parallel_blocks (gfc_code *code, gfc_namespace *ns)
 
   switch (code->op)
     {
+    case EXEC_OMP_DISTRIBUTE_PARALLEL_DO:
+    case EXEC_OMP_DISTRIBUTE_PARALLEL_DO_SIMD:
     case EXEC_OMP_PARALLEL_DO:
     case EXEC_OMP_PARALLEL_DO_SIMD:
     case EXEC_OMP_TARGET_PARALLEL_DO:
@@ -6047,31 +6049,6 @@ gfc_resolve_do_iterator (gfc_code *code, gfc_symbol *sym, bool add_clause)
   if (omp_current_ctx->sharing_clauses->contains (sym))
     return;
 
-  if (omp_current_ctx->is_openmp && omp_current_ctx->code->block)
-    {
-      /* SIMD is handled differently and, hence, ignored here.  */
-      gfc_code *omp_code = omp_current_ctx->code->block;
-      for ( ; omp_code->next; omp_code = omp_code->next)
-       switch (omp_code->op)
-         {
-         case EXEC_OMP_SIMD:
-         case EXEC_OMP_DO_SIMD:
-         case EXEC_OMP_PARALLEL_DO_SIMD:
-         case EXEC_OMP_DISTRIBUTE_SIMD:
-         case EXEC_OMP_DISTRIBUTE_PARALLEL_DO_SIMD:
-         case EXEC_OMP_TEAMS_DISTRIBUTE_SIMD:
-         case EXEC_OMP_TARGET_TEAMS_DISTRIBUTE_SIMD:
-         case EXEC_OMP_TEAMS_DISTRIBUTE_PARALLEL_DO_SIMD:
-         case EXEC_OMP_TARGET_TEAMS_DISTRIBUTE_PARALLEL_DO_SIMD:
-         case EXEC_OMP_TARGET_PARALLEL_DO_SIMD:
-         case EXEC_OMP_TARGET_SIMD:
-         case EXEC_OMP_TASKLOOP_SIMD:
-           return;
-         default:
-           break;
-         }
-    }
-
   if (! omp_current_ctx->private_iterators->add (sym) && add_clause)
     {
       gfc_omp_clauses *omp_clauses = omp_current_ctx->code->ext.omp_clauses;
index ebf89a9b1f52f31557c739673c2e84e4b0889aa6..f4ce49f84323b425cd283714653b34df95a4c998 100644 (file)
@@ -11722,6 +11722,8 @@ gfc_resolve_code (gfc_code *code, gfc_namespace *ns)
              omp_workshare_flag = 1;
              gfc_resolve_omp_parallel_blocks (code, ns);
              break;
+           case EXEC_OMP_DISTRIBUTE_PARALLEL_DO:
+           case EXEC_OMP_DISTRIBUTE_PARALLEL_DO_SIMD:
            case EXEC_OMP_PARALLEL:
            case EXEC_OMP_PARALLEL_DO:
            case EXEC_OMP_PARALLEL_DO_SIMD:
index 7d3365fe7e0045aa1ce68d66a002f34b848e7758..0e1da0426b48b5c5f9c167923899051e5a780f33 100644 (file)
@@ -5591,13 +5591,19 @@ gfc_trans_omp_target (gfc_code *code)
       }
       break;
     case EXEC_OMP_TARGET_PARALLEL_DO:
-    case EXEC_OMP_TARGET_PARALLEL_DO_SIMD:
       stmt = gfc_trans_omp_parallel_do (code, &block, clausesa);
       if (TREE_CODE (stmt) != BIND_EXPR)
        stmt = build3_v (BIND_EXPR, NULL, stmt, poplevel (1, 0));
       else
        poplevel (0, 0);
       break;
+    case EXEC_OMP_TARGET_PARALLEL_DO_SIMD:
+      stmt = gfc_trans_omp_parallel_do_simd (code, &block, clausesa);
+      if (TREE_CODE (stmt) != BIND_EXPR)
+       stmt = build3_v (BIND_EXPR, NULL, stmt, poplevel (1, 0));
+      else
+       poplevel (0, 0);
+      break;
     case EXEC_OMP_TARGET_SIMD:
       stmt = gfc_trans_omp_do (code, EXEC_OMP_SIMD, &block,
                               &clausesa[GFC_OMP_SPLIT_SIMD], NULL_TREE);
index 0bb6c28b286a11e02de5e3fe1c344945ea691aa6..d9e4a26ca0cdc21948ff0796a2901b534e8ccacc 100644 (file)
@@ -104,6 +104,6 @@ contains
 end module
 
 ! { dg-final { scan-tree-dump-times "(?n)#pragma omp target.* if\\(" 9 "omplower" } }
-! { dg-final { scan-tree-dump-times "(?n)#pragma omp simd.* if\\(" 4 "omplower" { target { ! offload_nvptx } } } }
+! { dg-final { scan-tree-dump-times "(?n)#pragma omp simd.* if\\(" 5 "omplower" { target { ! offload_nvptx } } } }
 ! { dg-final { scan-tree-dump-times "(?n)#pragma omp simd.* if\\(" 7 "omplower" { target { offload_nvptx } } } }
 ! { dg-final { scan-tree-dump-times "(?n)#pragma omp parallel.* if\\(" 6 "omplower" } }
diff --git a/gcc/testsuite/gfortran.dg/gomp/openmp-simd-5.f90 b/gcc/testsuite/gfortran.dg/gomp/openmp-simd-5.f90
new file mode 100644 (file)
index 0000000..b6d4cfa
--- /dev/null
@@ -0,0 +1,24 @@
+! { dg-additional-options "-fdump-tree-original" }
+!
+! Related:
+!   PR fortran/95109
+!   PR fortran/94690
+!
+implicit none
+integer :: i, j, k, ll
+integer :: a
+!$omp target parallel do simd collapse(1)
+  do i = 1, 5
+    do j = 1, 5
+      do k = 1, 5
+        a = a + 1
+      end do
+      do ll = 1, 5
+        a = a + 1
+      end do
+    end do
+  end do
+!$omp end target parallel do simd
+end
+
+! { dg-final { scan-tree-dump-times "omp simd linear\\(i:1\\) private\\(j\\) private\\(ll\\) private\\(k\\) collapse\\(1\\)" 1 "original" } }