315 lines · plain
1! Tests for 2.9.3.1 Simd2 3! The "if" clause was added to the "simd" directive in OpenMP 5.0.4! RUN: %flang_fc1 -flang-experimental-hlfir -emit-hlfir -fopenmp -fopenmp-version=50 %s -o - | FileCheck %s5! RUN: bbc -hlfir -emit-hlfir -fopenmp -fopenmp-version=50 %s -o - | FileCheck %s6 7!CHECK: omp.declare_reduction @[[REDUCER:.*]] : i328 9!CHECK-LABEL: func @_QPsimd()10subroutine simd11 integer :: i12 !$OMP SIMD13 ! CHECK: %[[LB:.*]] = arith.constant 1 : i3214 ! CHECK-NEXT: %[[UB:.*]] = arith.constant 9 : i3215 ! CHECK-NEXT: %[[STEP:.*]] = arith.constant 1 : i3216 ! CHECK-NEXT: omp.simd private({{.*}}) {17 ! CHECK-NEXT: omp.loop_nest (%[[I:.*]]) : i32 = (%[[LB]]) to (%[[UB]]) inclusive step (%[[STEP]]) {18 do i=1, 919 ! CHECK: hlfir.assign %[[I]] to %[[LOCAL:.*]]#0 : i32, !fir.ref<i32>20 ! CHECK: %[[LD:.*]] = fir.load %[[LOCAL]]#0 : !fir.ref<i32>21 ! CHECK: fir.call @_FortranAioOutputInteger32({{.*}}, %[[LD]]) {{.*}}: (!fir.ref<i8>, i32) -> i122 print*, i23 end do24 !$OMP END SIMD25end subroutine26 27!CHECK-LABEL: func @_QPsimd_with_if_clause28subroutine simd_with_if_clause(n, threshold)29 ! CHECK: %[[ARG_N:.*]]:2 = hlfir.declare %{{.*}} dummy_scope %{{[0-9]+}} arg {{[0-9]+}} {uniq_name = "_QFsimd_with_if_clauseEn"} : (!fir.ref<i32>, !fir.dscope) -> (!fir.ref<i32>, !fir.ref<i32>)30 integer :: i, n, threshold31 !$OMP SIMD IF( n .GE. threshold )32 ! CHECK: %[[COND:.*]] = arith.cmpi sge33 ! CHECK: %[[LB:.*]] = arith.constant 1 : i3234 ! CHECK: %[[UB:.*]] = fir.load %[[ARG_N]]#035 ! CHECK: %[[STEP:.*]] = arith.constant 1 : i3236 ! CHECK: omp.simd if(%[[COND:.*]]) private({{.*}}) {37 ! CHECK-NEXT: omp.loop_nest (%[[I:.*]]) : i32 = (%[[LB]]) to (%[[UB]]) inclusive step (%[[STEP]]) {38 do i = 1, n39 ! CHECK: hlfir.assign %[[I]] to %[[LOCAL:.*]]#0 : i32, !fir.ref<i32>40 ! CHECK: %[[LD:.*]] = fir.load %[[LOCAL]]#0 : !fir.ref<i32>41 ! CHECK: fir.call @_FortranAioOutputInteger32({{.*}}, %[[LD]]) {{.*}}: (!fir.ref<i8>, i32) -> i142 print*, i43 end do44 !$OMP END SIMD45end subroutine46 47!CHECK-LABEL: func @_QPsimd_with_simdlen_clause48subroutine simd_with_simdlen_clause(n, threshold)49 ! CHECK: %[[ARG_N:.*]]:2 = hlfir.declare %{{.*}} dummy_scope %{{[0-9]+}} arg {{[0-9]+}} {uniq_name = "_QFsimd_with_simdlen_clauseEn"} : (!fir.ref<i32>, !fir.dscope) -> (!fir.ref<i32>, !fir.ref<i32>)50 integer :: i, n, threshold51 !$OMP SIMD SIMDLEN(2)52 ! CHECK: %[[LB:.*]] = arith.constant 1 : i3253 ! CHECK: %[[UB:.*]] = fir.load %[[ARG_N]]#054 ! CHECK: %[[STEP:.*]] = arith.constant 1 : i3255 ! CHECK: omp.simd simdlen(2) private({{.*}}) {56 ! CHECK-NEXT: omp.loop_nest (%[[I:.*]]) : i32 = (%[[LB]]) to (%[[UB]]) inclusive step (%[[STEP]]) {57 do i = 1, n58 ! CHECK: hlfir.assign %[[I]] to %[[LOCAL:.*]]#0 : i32, !fir.ref<i32>59 ! CHECK: %[[LD:.*]] = fir.load %[[LOCAL]]#0 : !fir.ref<i32>60 ! CHECK: fir.call @_FortranAioOutputInteger32({{.*}}, %[[LD]]) {{.*}}: (!fir.ref<i8>, i32) -> i161 print*, i62 end do63 !$OMP END SIMD64end subroutine65 66!CHECK-LABEL: func @_QPsimd_with_simdlen_clause_from_param67subroutine simd_with_simdlen_clause_from_param(n, threshold)68 ! CHECK: %[[ARG_N:.*]]:2 = hlfir.declare %{{.*}} dummy_scope %{{[0-9]+}} arg {{[0-9]+}} {uniq_name = "_QFsimd_with_simdlen_clause_from_paramEn"} : (!fir.ref<i32>, !fir.dscope) -> (!fir.ref<i32>, !fir.ref<i32>)69 integer :: i, n, threshold70 integer, parameter :: simdlen = 2;71 !$OMP SIMD SIMDLEN(simdlen)72 ! CHECK: %[[LB:.*]] = arith.constant 1 : i3273 ! CHECK: %[[UB:.*]] = fir.load %[[ARG_N]]#074 ! CHECK: %[[STEP:.*]] = arith.constant 1 : i3275 ! CHECK: omp.simd simdlen(2) private({{.*}}) {76 ! CHECK-NEXT: omp.loop_nest (%[[I:.*]]) : i32 = (%[[LB]]) to (%[[UB]]) inclusive step (%[[STEP]]) {77 do i = 1, n78 ! CHECK: hlfir.assign %[[I]] to %[[LOCAL:.*]]#0 : i32, !fir.ref<i32>79 ! CHECK: %[[LD:.*]] = fir.load %[[LOCAL]]#0 : !fir.ref<i32>80 ! CHECK: fir.call @_FortranAioOutputInteger32({{.*}}, %[[LD]]) {{.*}}: (!fir.ref<i8>, i32) -> i181 print*, i82 end do83 !$OMP END SIMD84end subroutine85 86!CHECK-LABEL: func @_QPsimd_with_simdlen_clause_from_expr_from_param87subroutine simd_with_simdlen_clause_from_expr_from_param(n, threshold)88 ! CHECK: %[[ARG_N:.*]]:2 = hlfir.declare %{{.*}} dummy_scope %{{[0-9]+}} arg {{[0-9]+}} {uniq_name = "_QFsimd_with_simdlen_clause_from_expr_from_paramEn"} : (!fir.ref<i32>, !fir.dscope) -> (!fir.ref<i32>, !fir.ref<i32>)89 integer :: i, n, threshold90 integer, parameter :: simdlen = 2;91 !$OMP SIMD SIMDLEN(simdlen*2 + 2)92 ! CHECK: %[[LB:.*]] = arith.constant 1 : i3293 ! CHECK: %[[UB:.*]] = fir.load %[[ARG_N]]#094 ! CHECK: %[[STEP:.*]] = arith.constant 1 : i3295 ! CHECK: omp.simd simdlen(6) private({{.*}}) {96 ! CHECK-NEXT: omp.loop_nest (%[[I:.*]]) : i32 = (%[[LB]]) to (%[[UB]]) inclusive step (%[[STEP]]) {97 do i = 1, n98 ! CHECK: hlfir.assign %[[I]] to %[[LOCAL:.*]]#0 : i32, !fir.ref<i32>99 ! CHECK: %[[LD:.*]] = fir.load %[[LOCAL]]#0 : !fir.ref<i32>100 ! CHECK: fir.call @_FortranAioOutputInteger32({{.*}}, %[[LD]]) {{.*}}: (!fir.ref<i8>, i32) -> i1101 print*, i102 end do103 !$OMP END SIMD104end subroutine105 106!CHECK-LABEL: func @_QPsimd_with_safelen_clause107subroutine simd_with_safelen_clause(n, threshold)108 ! CHECK: %[[ARG_N:.*]]:2 = hlfir.declare %{{.*}} dummy_scope %{{[0-9]+}} arg {{[0-9]+}} {uniq_name = "_QFsimd_with_safelen_clauseEn"} : (!fir.ref<i32>, !fir.dscope) -> (!fir.ref<i32>, !fir.ref<i32>)109 integer :: i, n, threshold110 !$OMP SIMD SAFELEN(2)111 ! CHECK: %[[LB:.*]] = arith.constant 1 : i32112 ! CHECK: %[[UB:.*]] = fir.load %[[ARG_N]]#0113 ! CHECK: %[[STEP:.*]] = arith.constant 1 : i32114 ! CHECK: omp.simd safelen(2) private({{.*}}) {115 ! CHECK-NEXT: omp.loop_nest (%[[I:.*]]) : i32 = (%[[LB]]) to (%[[UB]]) inclusive step (%[[STEP]]) {116 do i = 1, n117 ! CHECK: hlfir.assign %[[I]] to %[[LOCAL:.*]]#0 : i32, !fir.ref<i32>118 ! CHECK: %[[LD:.*]] = fir.load %[[LOCAL]]#0 : !fir.ref<i32>119 ! CHECK: fir.call @_FortranAioOutputInteger32({{.*}}, %[[LD]]) {{.*}}: (!fir.ref<i8>, i32) -> i1120 print*, i121 end do122 !$OMP END SIMD123end subroutine124 125!CHECK-LABEL: func @_QPsimd_with_safelen_clause_from_expr_from_param126subroutine simd_with_safelen_clause_from_expr_from_param(n, threshold)127 ! CHECK: %[[ARG_N:.*]]:2 = hlfir.declare %{{.*}} dummy_scope %{{[0-9]+}} arg {{[0-9]+}} {uniq_name = "_QFsimd_with_safelen_clause_from_expr_from_paramEn"} : (!fir.ref<i32>, !fir.dscope) -> (!fir.ref<i32>, !fir.ref<i32>)128 integer :: i, n, threshold129 integer, parameter :: safelen = 2;130 !$OMP SIMD SAFELEN(safelen*2 + 2)131 ! CHECK: %[[LB:.*]] = arith.constant 1 : i32132 ! CHECK: %[[UB:.*]] = fir.load %[[ARG_N]]#0133 ! CHECK: %[[STEP:.*]] = arith.constant 1 : i32134 ! CHECK: omp.simd safelen(6) private({{.*}}) {135 ! CHECK-NEXT: omp.loop_nest (%[[I:.*]]) : i32 = (%[[LB]]) to (%[[UB]]) inclusive step (%[[STEP]]) {136 do i = 1, n137 ! CHECK: hlfir.assign %[[I]] to %[[LOCAL:.*]]#0 : i32, !fir.ref<i32>138 ! CHECK: %[[LD:.*]] = fir.load %[[LOCAL]]#0 : !fir.ref<i32>139 ! CHECK: fir.call @_FortranAioOutputInteger32({{.*}}, %[[LD]]) {{.*}}: (!fir.ref<i8>, i32) -> i1140 print*, i141 end do142 !$OMP END SIMD143end subroutine144 145!CHECK-LABEL: func @_QPsimd_with_simdlen_safelen_clause146subroutine simd_with_simdlen_safelen_clause(n, threshold)147 ! CHECK: %[[ARG_N:.*]]:2 = hlfir.declare %{{.*}} dummy_scope %{{[0-9]+}} arg {{[0-9]+}} {uniq_name = "_QFsimd_with_simdlen_safelen_clauseEn"} : (!fir.ref<i32>, !fir.dscope) -> (!fir.ref<i32>, !fir.ref<i32>)148 integer :: i, n, threshold149 !$OMP SIMD SIMDLEN(1) SAFELEN(2)150 ! CHECK: %[[LB:.*]] = arith.constant 1 : i32151 ! CHECK: %[[UB:.*]] = fir.load %[[ARG_N]]#0152 ! CHECK: %[[STEP:.*]] = arith.constant 1 : i32153 ! CHECK: omp.simd safelen(2) simdlen(1) private({{.*}}) {154 ! CHECK-NEXT: omp.loop_nest (%[[I:.*]]) : i32 = (%[[LB]]) to (%[[UB]]) inclusive step (%[[STEP]]) {155 do i = 1, n156 ! CHECK: hlfir.assign %[[I]] to %[[LOCAL:.*]]#0 : i32, !fir.ref<i32>157 ! CHECK: %[[LD:.*]] = fir.load %[[LOCAL]]#0 : !fir.ref<i32>158 ! CHECK: fir.call @_FortranAioOutputInteger32({{.*}}, %[[LD]]) {{.*}}: (!fir.ref<i8>, i32) -> i1159 print*, i160 end do161 !$OMP END SIMD162end subroutine163 164!CHECK-LABEL: func @_QPsimd_with_collapse_clause165subroutine simd_with_collapse_clause(n)166 integer :: i, j, n167 integer :: A(n,n)168 ! CHECK: %[[LOWER_I:.*]] = arith.constant 1 : i32169 ! CHECK: %[[UPPER_I:.*]] = fir.load %[[PARAM_ARG:.*]] : !fir.ref<i32>170 ! CHECK: %[[STEP_I:.*]] = arith.constant 1 : i32171 ! CHECK: %[[LOWER_J:.*]] = arith.constant 1 : i32172 ! CHECK: %[[UPPER_J:.*]] = fir.load %[[PARAM_ARG:.*]] : !fir.ref<i32>173 ! CHECK: %[[STEP_J:.*]] = arith.constant 1 : i32174 ! CHECK: omp.simd private({{.*}}) {175 ! CHECK-NEXT: omp.loop_nest (%[[ARG_0:.*]], %[[ARG_1:.*]]) : i32 = (176 ! CHECK-SAME: %[[LOWER_I]], %[[LOWER_J]]) to (177 ! CHECK-SAME: %[[UPPER_I]], %[[UPPER_J]]) inclusive step (178 ! CHECK-SAME: %[[STEP_I]], %[[STEP_J]]) collapse(2) {179 !$OMP SIMD COLLAPSE(2)180 do i = 1, n181 do j = 1, n182 A(i,j) = i + j183 end do184 end do185 !$OMP END SIMD186end subroutine187 188 189!CHECK: func.func @_QPsimdloop_aligned_cptr(%[[ARG_A:.*]]: !fir.ref190!CHECK-SAME: <!fir.type<_QM__fortran_builtinsT__builtin_c_ptr191!CHECK-SAME: {__address:i64}>> {fir.bindc_name = "a"}) {192!CHECK: %[[A_DECL:.*]]:2 = hlfir.declare %[[ARG_A]] dummy_scope %0193!CHECK-SAME: {uniq_name = "_QFsimdloop_aligned_cptrEa"} :194!CHECK-SAME: (!fir.ref<!fir.type<_QM__fortran_builtinsT__builtin_c_ptr{__address:i64}>>, !fir.dscope) ->195!CHECK-SAME: (!fir.ref<!fir.type<_QM__fortran_builtinsT__builtin_c_ptr{__address:i64}>>,196!CHECK-SAME: !fir.ref<!fir.type<_QM__fortran_builtinsT__builtin_c_ptr{__address:i64}>>)197subroutine simdloop_aligned_cptr( A)198 use iso_c_binding199 integer :: i200 type (c_ptr) :: A201!CHECK: omp.simd aligned(%[[A_DECL]]#0 : !fir.ref202!CHECK-SAME: <!fir.type<_QM__fortran_builtinsT__builtin_c_ptr{__address:i64}>>203!CHECK-SAME: -> 256 : i64)204 !$OMP SIMD ALIGNED(A:256)205 do i = 1, 10206 call c_test_call(A)207 end do208 !$OMP END SIMD209end subroutine210 211!CHECK-LABEL: func @_QPsimdloop_aligned_allocatable212subroutine simdloop_aligned_allocatable()213 integer :: i214 integer, allocatable :: A(:)215 allocate(A(10))216!CHECK: %[[A_PTR:.*]] = fir.alloca !fir.box<!fir.heap<!fir.array<?xi32>>> {bindc_name = "a",217!CHECK-SAME: uniq_name = "_QFsimdloop_aligned_allocatableEa"}218!CHECK: %[[A_DECL:.*]]:2 = hlfir.declare %[[A_PTR]] {fortran_attrs = #fir.var_attrs<allocatable>,219!CHECK-SAME: uniq_name = "_QFsimdloop_aligned_allocatableEa"} :220!CHECK-SAME: (!fir.ref<!fir.box<!fir.heap<!fir.array<?xi32>>>>) ->221!CHECK-SAME: (!fir.ref<!fir.box<!fir.heap<!fir.array<?xi32>>>>, !fir.ref<!fir.box<!fir.heap<!fir.array<?xi32>>>>)222!CHECK: omp.simd aligned(%[[A_DECL]]#0 : !fir.ref<!fir.box<!fir.heap<!fir.array<?xi32>>>> -> 256 : i64)223 !$OMP SIMD ALIGNED(A:256)224 do i = 1, 10225 A(i) = i226 end do227end subroutine228 229subroutine aligned_non_power_of_two()230 integer :: i231 integer, allocatable :: A(:)232 allocate(A(10))233!CHECK: %[[A_PTR:.*]] = fir.alloca !fir.box<!fir.heap<!fir.array<?xi32>>> {bindc_name = "a",234!CHECK-SAME: uniq_name = "_QFaligned_non_power_of_twoEa"}235!CHECK: %[[A_DECL:.*]]:2 = hlfir.declare %[[A_PTR]] {fortran_attrs = #fir.var_attrs<allocatable>,236!CHECK-SAME: uniq_name = "_QFaligned_non_power_of_twoEa"} :237!CHECK-SAME: (!fir.ref<!fir.box<!fir.heap<!fir.array<?xi32>>>>) ->238!CHECK-SAME: (!fir.ref<!fir.box<!fir.heap<!fir.array<?xi32>>>>, !fir.ref<!fir.box<!fir.heap<!fir.array<?xi32>>>>)239!CHECK: omp.simd private240 !$OMP SIMD ALIGNED(A:257)241 do i = 1, 10242 A(i) = i243 end do244end subroutine245 246!CHECK-LABEL: func @_QPsimd_with_nontemporal_clause247subroutine simd_with_nontemporal_clause(n)248 !CHECK: %[[A_DECL:.*]]:2 = hlfir.declare %{{.*}} {uniq_name = "_QFsimd_with_nontemporal_clauseEa"} : (!fir.ref<i32>) -> (!fir.ref<i32>, !fir.ref<i32>)249 !CHECK: %[[C_DECL:.*]]:2 = hlfir.declare %{{.*}} {uniq_name = "_QFsimd_with_nontemporal_clauseEc"} : (!fir.ref<i32>) -> (!fir.ref<i32>, !fir.ref<i32>)250 integer :: i, n251 integer :: A, B, C252 !CHECK: %[[LB:.*]] = arith.constant 1 : i32253 !CHECK: %[[UB:.*]] = fir.load %{{.*}}#0 : !fir.ref<i32>254 !CHECK: %[[STEP:.*]] = arith.constant 1 : i32255 !CHECK: omp.simd nontemporal(%[[A_DECL]]#0, %[[C_DECL]]#0 : !fir.ref<i32>, !fir.ref<i32>) private({{.*}}) {256 !CHECK-NEXT: omp.loop_nest (%[[I:.*]]) : i32 = (%[[LB]]) to (%[[UB]]) inclusive step (%[[STEP]]) {257 !$OMP SIMD NONTEMPORAL(A, C)258 do i = 1, n259 C = A + B260 end do261 !$OMP END SIMD262end subroutine263 264!CHECK-LABEL: func.func @_QPlastprivate_with_simd() {265subroutine lastprivate_with_simd266 267!CHECK: %[[VAR_SUM:.*]] = fir.alloca f32 {bindc_name = "sum", uniq_name = "_QFlastprivate_with_simdEsum"}268!CHECK: %[[VAR_SUM_DECLARE:.*]]:2 = hlfir.declare %[[VAR_SUM]] {{.*}}269 implicit none270 integer :: i271 real :: sum272 273 274!CHECK: omp.simd private(@_QFlastprivate_with_simdEsum_private_f32 %[[VAR_SUM_DECLARE]]#0 -> %[[VAR_SUM_PINNED:.*]], @{{.*}}) {275!CHECK: omp.loop_nest (%[[ARG:.*]]) : i32 = ({{.*}} to ({{.*}}) inclusive step ({{.*}}) {276!CHECK: %[[VAR_SUM_PINNED_DECLARE:.*]]:2 = hlfir.declare %[[VAR_SUM_PINNED]] {{.*}}277!CHECK: %[[ADD_RESULT:.*]] = arith.addi {{.*}}278!CHECK: %[[ADD_RESULT_CONVERT:.*]] = fir.convert %[[ADD_RESULT]] : (i32) -> f32279!CHECK: hlfir.assign %[[ADD_RESULT_CONVERT]] to %[[VAR_SUM_PINNED_DECLARE]]#0 : f32, !fir.ref<f32>280!CHECK: %[[SELECT_RESULT:.*]] = arith.select {{.*}}, {{.*}}, {{.*}} : i1281!CHECK: fir.if %[[SELECT_RESULT]] {282!CHECK: %[[LOADED_SUM:.*]] = fir.load %[[VAR_SUM_PINNED_DECLARE]]#0 : !fir.ref<f32>283!CHECK: hlfir.assign %[[LOADED_SUM]] to %[[VAR_SUM_DECLARE]]#0 : f32, !fir.ref<f32>284!CHECK: }285!CHECK: omp.yield286!CHECK: }287!CHECK: }288 !$omp simd lastprivate(sum)289 do i = 1, 100290 sum = i + 1291 end do292end subroutine293 294!CHECK-LABEL: func @_QPsimd_with_reduction_clause()295subroutine simd_with_reduction_clause296 integer :: i, x297 x = 0298 ! CHECK: %[[LB:.*]] = arith.constant 1 : i32299 ! CHECK-NEXT: %[[UB:.*]] = arith.constant 9 : i32300 ! CHECK-NEXT: %[[STEP:.*]] = arith.constant 1 : i32301 ! CHECK-NEXT: omp.simd private({{.*}}) reduction(@[[REDUCER]] %[[X:.*]]#0 -> %[[X_RED:.*]] : !fir.ref<i32>) {302 ! CHECK-NEXT: omp.loop_nest (%[[I:.*]]) : i32 = (%[[LB]]) to (%[[UB]]) inclusive step (%[[STEP]]) {303 !$omp simd reduction(+:x)304 do i=1, 9305 ! CHECK: %[[X_DECL:.*]]:2 = hlfir.declare %[[X_RED]] {uniq_name = "_QFsimd_with_reduction_clauseEx"} : (!fir.ref<i32>) -> (!fir.ref<i32>, !fir.ref<i32>)306 ! CHECK: hlfir.assign %[[I]] to %[[LOCAL:.*]]#0 : i32, !fir.ref<i32>307 ! CHECK: %[[X_LD:.*]] = fir.load %[[X_DECL]]#0 : !fir.ref<i32>308 ! CHECK: %[[I_LD:.*]] = fir.load %[[LOCAL]]#0 : !fir.ref<i32>309 ! CHECK: %[[SUM:.*]] = arith.addi %[[X_LD]], %[[I_LD]] : i32310 ! CHECK: hlfir.assign %[[SUM]] to %[[X_DECL]]#0 : i32, !fir.ref<i32>311 x = x+i312 end do313 !$OMP end simd314end subroutine315