]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
fortran: Apply if clause to all sub-constructs in combined OpenMP constructs
authorKwok Cheung Yeung <kcy@codesourcery.com>
Thu, 25 Jun 2020 11:40:16 +0000 (04:40 -0700)
committerKwok Cheung Yeung <kcy@codesourcery.com>
Fri, 26 Jun 2020 21:09:20 +0000 (14:09 -0700)
The unmodified 'if' clause should be applied to all the sub-constructs that
accept an 'if' clause in a combined OpenMP construct, and not just to the
'parallel' sub-construct.

This is a backport from master
(commit 1dfa89b0355520ca501054726f25de9733796f48).

2020-06-25  Kwok Cheung Yeung  <kcy@codesourcery.com>

gcc/fortran/

* trans-openmp.c (gfc_split_omp_clauses): Add if clause
to target and simd sub-constructs.

gcc/testsuite/

* gfortran.dg/gomp/combined-if.f90: New.

Reviewed-by: Jakub Jelinek <jakub@redhat.com>
gcc/fortran/ChangeLog.omp
gcc/fortran/trans-openmp.c
gcc/testsuite/ChangeLog.omp
gcc/testsuite/gfortran.dg/gomp/combined-if.f90 [new file with mode: 0644]

index 3e470a7665d3ade0654c09051a24bf624ddda576..ea2fc1f423208fd982bd8d04390e69112e953d40 100644 (file)
@@ -1,3 +1,8 @@
+2020-06-25  Kwok Cheung Yeung  <kcy@codesourcery.com>
+
+       * trans-openmp.c (gfc_split_omp_clauses): Add if clause
+       to target and simd sub-constructs.
+
 2020-03-27  Sandra Loosemore  <sandra@codesourcery.com>
            Gergö Barany <gergo@codesourcery.com>
 
index 646bebcd0e5d9cb522c17b4584ffcf7d8383b796..4a65c7fd5be4f626cd356d338c7d4e30111f1d5a 100644 (file)
@@ -4769,7 +4769,7 @@ gfc_split_omp_clauses (gfc_code *code,
          clausesa[GFC_OMP_SPLIT_TARGET].if_exprs[OMP_IF_TARGET]
            = code->ext.omp_clauses->if_exprs[OMP_IF_TARGET];
          /* And this is copied to all.  */
-         clausesa[GFC_OMP_SPLIT_PARALLEL].if_expr
+         clausesa[GFC_OMP_SPLIT_TARGET].if_expr
            = code->ext.omp_clauses->if_expr;
        }
       if (mask & GFC_OMP_MASK_TEAMS)
@@ -4853,6 +4853,9 @@ gfc_split_omp_clauses (gfc_code *code,
          /* Duplicate collapse.  */
          clausesa[GFC_OMP_SPLIT_SIMD].collapse
            = code->ext.omp_clauses->collapse;
+         /* And this is copied to all.  */
+         clausesa[GFC_OMP_SPLIT_SIMD].if_expr
+           = code->ext.omp_clauses->if_expr;
        }
       if (mask & GFC_OMP_MASK_TASKLOOP)
        {
index 013ecaa573351f2b5c969993baf218f877a9fa44..0c46408323edacf8ac3105b75e3e9d07278bac53 100644 (file)
@@ -1,3 +1,7 @@
+2020-06-25  Kwok Cheung Yeung  <kcy@codesourcery.com>
+
+       * gfortran.dg/gomp/combined-if.f90: New.
+
 2020-06-02  Kwok Cheung Yeung  <kcy@codesourcery.com>
 
        * c-c++-common/goacc/noncontig_array-1.c: Dump Gimple pass.
diff --git a/gcc/testsuite/gfortran.dg/gomp/combined-if.f90 b/gcc/testsuite/gfortran.dg/gomp/combined-if.f90
new file mode 100644 (file)
index 0000000..383086c
--- /dev/null
@@ -0,0 +1,110 @@
+! { dg-do compile }
+! { dg-additional-options "-fdump-tree-omplower" }
+
+module combined_if
+  implicit none
+
+  integer, parameter :: N = 100
+  integer, parameter :: LIMIT = 60
+  integer :: i, j
+  integer, dimension(N) :: a = (/ (i, i = 1,N) /)
+contains
+  subroutine test_parallel_loop_simd
+    do j = 1, N
+      !$omp parallel do simd if(j .lt. LIMIT)
+      do i = 1, N
+        a(i) = a(i) + 1
+      end do
+    end do
+  end subroutine
+
+  ! TODO: This currently fails with an internal compiler error
+  ! (PR 95869)
+  !subroutine test_target_parallel
+  !  do j = 1, N
+  !    !$omp target parallel if(j .lt. LIMIT) map(tofrom: a(1:N))
+  !    do i = 1, N
+  !      a(i) = a(i) + 1
+  !    end do
+  !    !$omp end target parallel
+  !   end do
+  !end subroutine
+
+  subroutine test_target_parallel_loop
+    do j = 1, N
+      !$omp target parallel do if(j .lt. LIMIT) map(tofrom: a(1:N))
+      do i = 1, N
+        a(i) = a(i) + 1
+      end do
+    end do
+  end subroutine
+
+  subroutine test_target_parallel_loop_simd
+    do j = 1, N
+      !$omp target parallel do simd if(j .lt. LIMIT) map(tofrom: a(1:N))
+      do i = 1, N
+        a(i) = a(i) + 1
+      end do
+    end do
+  end subroutine
+
+  subroutine test_target_simd
+    do j = 1, N
+      !$omp target simd if(j .lt. LIMIT) map(tofrom: a(1:N))
+      do i = 1, N
+        a(i) = a(i) + 1
+      end do
+    end do
+  end subroutine
+
+  subroutine test_target_teams
+    do j = 1, N
+      !$omp target teams if(j .lt. LIMIT) map(tofrom: a(1:N))
+      do i = 1, N
+        a(i) = a(i) + 1
+      end do
+      !$omp end target teams
+    end do
+  end subroutine
+
+  subroutine test_target_teams_distribute
+    do j = 1, N
+      !$omp target teams distribute if(j .lt. LIMIT) map(tofrom: a(1:N))
+      do i = 1, N
+        a(i) = a(i) + 1
+      end do
+    end do
+  end subroutine
+
+  subroutine test_target_teams_distibute_simd
+    do j = 1, N
+      !$omp target teams distribute simd if(j .lt. LIMIT) map(tofrom: a(1:N))
+      do i = 1, N
+        a(i) = a(i) + 1
+      end do
+    end do
+  end subroutine
+
+  subroutine test_target_teams_distribute_parallel_loop
+    do j = 1, N
+      !$omp target teams distribute parallel do if(j .lt. LIMIT) map(tofrom: a(1:N))
+      do i = 1, N
+        a(i) = a(i) + 1
+      end do
+    end do
+  end subroutine
+    
+  subroutine test_target_teams_distribute_parallel_loop_simd
+    do j = 1, N
+      !$omp target teams distribute parallel do simd if(j .lt. LIMIT) map(tofrom: a(1:N))
+      do i = 1, N
+        a(i) = a(i) + 1
+      end do
+    end do
+  end subroutine
+
+end module
+
+! { dg-final { scan-tree-dump-times "(?n)#pragma omp target.* if\\(" 8 "omplower" } }
+! { dg-final { scan-tree-dump-times "(?n)#pragma omp simd.* if\\(" 7 "omplower" } }
+! { dg-final { scan-tree-dump-times "(?n)#pragma omp parallel.* if\\(" 5 "omplower" } }