| ! Check that offloaded collapsed simd loops whose body uses MODULO, which | |
| ! gfortran expands to FLOOR_MOD_EXPR, take the one-lane fallback like those | |
| ! using MOD, and compute the right result. The dividends are negative and | |
| ! positive, where MODULO and MOD differ. | |
| ! { dg-do run } | |
| ! { dg-additional-options "-O2 -fdump-tree-omplower-details" } | |
| ! { dg-xfail-if "--param=offload-gpu-mode=simt-directed needs the amdgcn SIMT series" { offload_target_amdgcn } } | |
| ! { dg-additional-options "--param=offload-gpu-mode=simt-directed" { target offload_target_amdgcn } } | |
| module fallback_2_m | |
| implicit none | |
| integer, parameter :: ni = 37, nj = 23 | |
| contains | |
| subroutine composite (a, d) | |
| integer :: a(nj, ni), d | |
| integer :: i, j | |
| !$omp target teams distribute parallel do simd collapse(2) map(tofrom: a) | |
| do i = 1, ni | |
| do j = 1, nj | |
| a(j, i) = modulo ((i - 1) * nj + j - 401, d) | |
| end do | |
| end do | |
| end subroutine | |
| subroutine non_composite (a, d) | |
| integer :: a(nj, ni), d | |
| integer :: i, j | |
| !$omp target map(tofrom: a) | |
| !$omp simd collapse(2) | |
| do i = 1, ni | |
| do j = 1, nj | |
| a(j, i) = modulo ((i - 1) * nj + j - 401, d) | |
| end do | |
| end do | |
| !$omp end target | |
| end subroutine | |
| subroutine check (a, d) | |
| integer :: a(nj, ni), d | |
| integer :: i, j, x | |
| do i = 1, ni | |
| do j = 1, nj | |
| x = (i - 1) * nj + j - 401 | |
| if (a(j, i) /= mod (mod (x, d) + d, d)) stop 1 | |
| end do | |
| end do | |
| end subroutine | |
| end module | |
| program fallback_2 | |
| use fallback_2_m | |
| implicit none | |
| integer :: a(nj, ni), d | |
| volatile :: d | |
| d = 7 | |
| a = -1 | |
| call composite (a, d) | |
| call check (a, d) | |
| a = -1 | |
| call non_composite (a, d) | |
| call check (a, d) | |
| end program | |
| ! { dg-final { scan-tree-dump-times "collapsed loop cannot take the SIMT path: integer division or modulo" 2 "omplower" { target { offload_target_amdgcn || offload_target_nvptx } } } } | |
| ! { dg-final { scan-tree-dump-times "collapsed loop cannot take the SIMT path" 2 "omplower" { target { offload_target_amdgcn || offload_target_nvptx } } } } | |
| ! { dg-final { scan-tree-dump-not "_simt_" "omplower" { target { offload_target_amdgcn || offload_target_nvptx } } } } |