diff options
author | Tobias Burnus <tobias@codesourcery.com> | 2022-10-06 18:42:32 +0200 |
---|---|---|
committer | Tobias Burnus <tobias@codesourcery.com> | 2022-10-06 18:44:09 +0200 |
commit | 50c35c691517291dbb77b1661761bc59950ba101 (patch) | |
tree | 3d750d59c788fd9914260ce3a1f62506a462e596 /gcc/testsuite | |
parent | fa258f6894801aef6785f0327594dc803da63fbd (diff) | |
download | gcc-50c35c691517291dbb77b1661761bc59950ba101.zip gcc-50c35c691517291dbb77b1661761bc59950ba101.tar.gz gcc-50c35c691517291dbb77b1661761bc59950ba101.tar.bz2 |
openmp: Map holds clause to IFN_ASSUME for Fortran
Same as r13-3107-g847f5addc4d07a2f3b95f5daa50ab4a64dfd957d did for C/C++.
Convert '!$omp assume holds(cond)' to IFN_ASSUME (cond).
gcc/fortran/
* trans-openmp.cc (gfc_trans_omp_assume): New.
(gfc_trans_omp_directive): Call it.
gcc/testsuite/
* gfortran.dg/gomp/assume-3.f90: New test.
* gfortran.dg/gomp/assume-4.f90: New test.
Diffstat (limited to 'gcc/testsuite')
-rw-r--r-- | gcc/testsuite/gfortran.dg/gomp/assume-3.f90 | 46 | ||||
-rw-r--r-- | gcc/testsuite/gfortran.dg/gomp/assume-4.f90 | 50 |
2 files changed, 96 insertions, 0 deletions
diff --git a/gcc/testsuite/gfortran.dg/gomp/assume-3.f90 b/gcc/testsuite/gfortran.dg/gomp/assume-3.f90 new file mode 100644 index 0000000..e5deace --- /dev/null +++ b/gcc/testsuite/gfortran.dg/gomp/assume-3.f90 @@ -0,0 +1,46 @@ +! { dg-do compile } +! { dg-options "-fopenmp -O2 -fdump-tree-optimized -fdump-tree-original" } + +! { dg-final { scan-tree-dump-times ".ASSUME \\(x == 42\\);" 1 "original" } } +! { dg-final { scan-tree-dump-times ".ASSUME \\(x <= 41\\);" 1 "original" } } +! { dg-final { scan-tree-dump-times ".ASSUME \\(y <= 6\\);" 1 "original" } } +! { dg-final { scan-tree-dump-times ".ASSUME \\(y > 5\\);" 1 "original" } } + +! { dg-final { scan-tree-dump-times "return 42;" 3 "optimized" } } +! { dg-final { scan-tree-dump-not "return -1;" "optimized" } } + +integer function foo (x) + implicit none + integer, value :: x + integer :: y + !$omp assume holds (x == 42) + y = x; + !$omp end assume + foo = y +end + +integer function bar (x) + implicit none + integer, value :: x + !$omp assume holds (x < 42) + block + end block + if (x == 42) then + bar = -1 + return + end if + bar = 42 +end + +integer function foobar (y) + implicit none + integer, value :: y + !$omp assume holds(y > 5) holds (y < 7) + block + if (y == 6) then + foobar = 42 + return + end if + end block + foobar = -1 +end diff --git a/gcc/testsuite/gfortran.dg/gomp/assume-4.f90 b/gcc/testsuite/gfortran.dg/gomp/assume-4.f90 new file mode 100644 index 0000000..45857c4 --- /dev/null +++ b/gcc/testsuite/gfortran.dg/gomp/assume-4.f90 @@ -0,0 +1,50 @@ +! { dg-do compile } +! { dg-options "-fopenmp -O2 -fdump-tree-original -fdump-tree-optimized" } +! { dg-final { scan-tree-dump-times ".ASSUME \\(i_lower_bound \\(\\) < i\\);" 1 "original" } } +! { dg-final { scan-tree-dump-times ".ASSUME \\(TARGET_EXPR <D.\[0-9\]+, D.\[0-9\]+ = j_upper_bound \\(\\);" 1 "original" } } +! { dg-final { scan-tree-dump-times "__builtin_free" 1 "original" } } + +! { dg-final { scan-tree-dump-not "i_lower_bound" "optimized" } } +! { dg-final { scan-tree-dump-not "j_upper_bound" "optimized" } } +! { dg-final { scan-tree-dump-not "__builtin_free" "optimized" } } + +! Note: Currently, the assumption does not help with optimization in either variant. + + +integer function f(i) + implicit none + integer, value :: i + + !$omp assume holds(i > i_lower_bound ()) + block + if (i > 4) then + f = 42 + else + f = -1 + end if + end block +contains + function i_lower_bound () + integer :: i_lower_bound + i_lower_bound = 5 + end function +end + +integer function g(j) + implicit none + integer, value :: j + + !$omp assume holds(j < j_upper_bound ()) + block + if (j < 10) then + g = 42 + else + g = -1 + end if + end block +contains + function j_upper_bound () + integer, allocatable :: j_upper_bound + j_upper_bound = 10 + end function +end |