Debian Codegraph @

flang/test/Lower/OpenMP/simd.f90

raw
1 ! Tests for 2.9.3.1 Simd
2
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 %s
5 ! RUN: bbc -hlfir -emit-hlfir -fopenmp -fopenmp-version=50 %s -o - | FileCheck %s
6
7 !CHECK-LABEL: func @_QPsimd()
8 subroutine simd
9 integer :: i
10 !$OMP SIMD
11 ! CHECK: %[[LB:.*]] = arith.constant 1 : i32
12 ! CHECK-NEXT: %[[UB:.*]] = arith.constant 9 : i32
13 ! CHECK-NEXT: %[[STEP:.*]] = arith.constant 1 : i32
14 ! CHECK-NEXT: omp.simd {
15 ! CHECK-NEXT: omp.loop_nest (%[[I:.*]]) : i32 = (%[[LB]]) to (%[[UB]]) inclusive step (%[[STEP]]) {
16 do i=1, 9
17 ! CHECK: fir.store %[[I]] to %[[LOCAL:.*]]#1 : !fir.ref<i32>
18 ! CHECK: %[[LD:.*]] = fir.load %[[LOCAL]]#0 : !fir.ref<i32>
19 ! CHECK: fir.call @_FortranAioOutputInteger32({{.*}}, %[[LD]]) {{.*}}: (!fir.ref<i8>, i32) -> i1
20 print*, i
21 end do
22 !$OMP END SIMD
23 end subroutine
24
25 !CHECK-LABEL: func @_QPsimd_with_if_clause
26 subroutine simd_with_if_clause(n, threshold)
27 ! CHECK: %[[ARG_N:.*]]:2 = hlfir.declare %{{.*}} dummy_scope %{{[0-9]+}} {uniq_name = "_QFsimd_with_if_clauseEn"} : (!fir.ref<i32>, !fir.dscope) -> (!fir.ref<i32>, !fir.ref<i32>)
28 integer :: i, n, threshold
29 !$OMP SIMD IF( n .GE. threshold )
30 ! CHECK: %[[COND:.*]] = arith.cmpi sge
31 ! CHECK: %[[LB:.*]] = arith.constant 1 : i32
32 ! CHECK: %[[UB:.*]] = fir.load %[[ARG_N]]#0
33 ! CHECK: %[[STEP:.*]] = arith.constant 1 : i32
34 ! CHECK: omp.simd if(%[[COND:.*]]) {
35 ! CHECK-NEXT: omp.loop_nest (%[[I:.*]]) : i32 = (%[[LB]]) to (%[[UB]]) inclusive step (%[[STEP]]) {
36 do i = 1, n
37 ! CHECK: fir.store %[[I]] to %[[LOCAL:.*]]#1 : !fir.ref<i32>
38 ! CHECK: %[[LD:.*]] = fir.load %[[LOCAL]]#0 : !fir.ref<i32>
39 ! CHECK: fir.call @_FortranAioOutputInteger32({{.*}}, %[[LD]]) {{.*}}: (!fir.ref<i8>, i32) -> i1
40 print*, i
41 end do
42 !$OMP END SIMD
43 end subroutine
44
45 !CHECK-LABEL: func @_QPsimd_with_simdlen_clause
46 subroutine simd_with_simdlen_clause(n, threshold)
47 ! CHECK: %[[ARG_N:.*]]:2 = hlfir.declare %{{.*}} dummy_scope %{{[0-9]+}} {uniq_name = "_QFsimd_with_simdlen_clauseEn"} : (!fir.ref<i32>, !fir.dscope) -> (!fir.ref<i32>, !fir.ref<i32>)
48 integer :: i, n, threshold
49 !$OMP SIMD SIMDLEN(2)
50 ! CHECK: %[[LB:.*]] = arith.constant 1 : i32
51 ! CHECK: %[[UB:.*]] = fir.load %[[ARG_N]]#0
52 ! CHECK: %[[STEP:.*]] = arith.constant 1 : i32
53 ! CHECK: omp.simd simdlen(2) {
54 ! CHECK-NEXT: omp.loop_nest (%[[I:.*]]) : i32 = (%[[LB]]) to (%[[UB]]) inclusive step (%[[STEP]]) {
55 do i = 1, n
56 ! CHECK: fir.store %[[I]] to %[[LOCAL:.*]]#1 : !fir.ref<i32>
57 ! CHECK: %[[LD:.*]] = fir.load %[[LOCAL]]#0 : !fir.ref<i32>
58 ! CHECK: fir.call @_FortranAioOutputInteger32({{.*}}, %[[LD]]) {{.*}}: (!fir.ref<i8>, i32) -> i1
59 print*, i
60 end do
61 !$OMP END SIMD
62 end subroutine
63
64 !CHECK-LABEL: func @_QPsimd_with_simdlen_clause_from_param
65 subroutine simd_with_simdlen_clause_from_param(n, threshold)
66 ! CHECK: %[[ARG_N:.*]]:2 = hlfir.declare %{{.*}} dummy_scope %{{[0-9]+}} {uniq_name = "_QFsimd_with_simdlen_clause_from_paramEn"} : (!fir.ref<i32>, !fir.dscope) -> (!fir.ref<i32>, !fir.ref<i32>)
67 integer :: i, n, threshold
68 integer, parameter :: simdlen = 2;
69 !$OMP SIMD SIMDLEN(simdlen)
70 ! CHECK: %[[LB:.*]] = arith.constant 1 : i32
71 ! CHECK: %[[UB:.*]] = fir.load %[[ARG_N]]#0
72 ! CHECK: %[[STEP:.*]] = arith.constant 1 : i32
73 ! CHECK: omp.simd simdlen(2) {
74 ! CHECK-NEXT: omp.loop_nest (%[[I:.*]]) : i32 = (%[[LB]]) to (%[[UB]]) inclusive step (%[[STEP]]) {
75 do i = 1, n
76 ! CHECK: fir.store %[[I]] to %[[LOCAL:.*]]#1 : !fir.ref<i32>
77 ! CHECK: %[[LD:.*]] = fir.load %[[LOCAL]]#0 : !fir.ref<i32>
78 ! CHECK: fir.call @_FortranAioOutputInteger32({{.*}}, %[[LD]]) {{.*}}: (!fir.ref<i8>, i32) -> i1
79 print*, i
80 end do
81 !$OMP END SIMD
82 end subroutine
83
84 !CHECK-LABEL: func @_QPsimd_with_simdlen_clause_from_expr_from_param
85 subroutine simd_with_simdlen_clause_from_expr_from_param(n, threshold)
86 ! CHECK: %[[ARG_N:.*]]:2 = hlfir.declare %{{.*}} dummy_scope %{{[0-9]+}} {uniq_name = "_QFsimd_with_simdlen_clause_from_expr_from_paramEn"} : (!fir.ref<i32>, !fir.dscope) -> (!fir.ref<i32>, !fir.ref<i32>)
87 integer :: i, n, threshold
88 integer, parameter :: simdlen = 2;
89 !$OMP SIMD SIMDLEN(simdlen*2 + 2)
90 ! CHECK: %[[LB:.*]] = arith.constant 1 : i32
91 ! CHECK: %[[UB:.*]] = fir.load %[[ARG_N]]#0
92 ! CHECK: %[[STEP:.*]] = arith.constant 1 : i32
93 ! CHECK: omp.simd simdlen(6) {
94 ! CHECK-NEXT: omp.loop_nest (%[[I:.*]]) : i32 = (%[[LB]]) to (%[[UB]]) inclusive step (%[[STEP]]) {
95 do i = 1, n
96 ! CHECK: fir.store %[[I]] to %[[LOCAL:.*]]#1 : !fir.ref<i32>
97 ! CHECK: %[[LD:.*]] = fir.load %[[LOCAL]]#0 : !fir.ref<i32>
98 ! CHECK: fir.call @_FortranAioOutputInteger32({{.*}}, %[[LD]]) {{.*}}: (!fir.ref<i8>, i32) -> i1
99 print*, i
100 end do
101 !$OMP END SIMD
102 end subroutine
103
104 !CHECK-LABEL: func @_QPsimd_with_safelen_clause
105 subroutine simd_with_safelen_clause(n, threshold)
106 ! CHECK: %[[ARG_N:.*]]:2 = hlfir.declare %{{.*}} dummy_scope %{{[0-9]+}} {uniq_name = "_QFsimd_with_safelen_clauseEn"} : (!fir.ref<i32>, !fir.dscope) -> (!fir.ref<i32>, !fir.ref<i32>)
107 integer :: i, n, threshold
108 !$OMP SIMD SAFELEN(2)
109 ! CHECK: %[[LB:.*]] = arith.constant 1 : i32
110 ! CHECK: %[[UB:.*]] = fir.load %[[ARG_N]]#0
111 ! CHECK: %[[STEP:.*]] = arith.constant 1 : i32
112 ! CHECK: omp.simd safelen(2) {
113 ! CHECK-NEXT: omp.loop_nest (%[[I:.*]]) : i32 = (%[[LB]]) to (%[[UB]]) inclusive step (%[[STEP]]) {
114 do i = 1, n
115 ! CHECK: fir.store %[[I]] to %[[LOCAL:.*]]#1 : !fir.ref<i32>
116 ! CHECK: %[[LD:.*]] = fir.load %[[LOCAL]]#0 : !fir.ref<i32>
117 ! CHECK: fir.call @_FortranAioOutputInteger32({{.*}}, %[[LD]]) {{.*}}: (!fir.ref<i8>, i32) -> i1
118 print*, i
119 end do
120 !$OMP END SIMD
121 end subroutine
122
123 !CHECK-LABEL: func @_QPsimd_with_safelen_clause_from_expr_from_param
124 subroutine simd_with_safelen_clause_from_expr_from_param(n, threshold)
125 ! CHECK: %[[ARG_N:.*]]:2 = hlfir.declare %{{.*}} dummy_scope %{{[0-9]+}} {uniq_name = "_QFsimd_with_safelen_clause_from_expr_from_paramEn"} : (!fir.ref<i32>, !fir.dscope) -> (!fir.ref<i32>, !fir.ref<i32>)
126 integer :: i, n, threshold
127 integer, parameter :: safelen = 2;
128 !$OMP SIMD SAFELEN(safelen*2 + 2)
129 ! CHECK: %[[LB:.*]] = arith.constant 1 : i32
130 ! CHECK: %[[UB:.*]] = fir.load %[[ARG_N]]#0
131 ! CHECK: %[[STEP:.*]] = arith.constant 1 : i32
132 ! CHECK: omp.simd safelen(6) {
133 ! CHECK-NEXT: omp.loop_nest (%[[I:.*]]) : i32 = (%[[LB]]) to (%[[UB]]) inclusive step (%[[STEP]]) {
134 do i = 1, n
135 ! CHECK: fir.store %[[I]] to %[[LOCAL:.*]]#1 : !fir.ref<i32>
136 ! CHECK: %[[LD:.*]] = fir.load %[[LOCAL]]#0 : !fir.ref<i32>
137 ! CHECK: fir.call @_FortranAioOutputInteger32({{.*}}, %[[LD]]) {{.*}}: (!fir.ref<i8>, i32) -> i1
138 print*, i
139 end do
140 !$OMP END SIMD
141 end subroutine
142
143 !CHECK-LABEL: func @_QPsimd_with_simdlen_safelen_clause
144 subroutine simd_with_simdlen_safelen_clause(n, threshold)
145 ! CHECK: %[[ARG_N:.*]]:2 = hlfir.declare %{{.*}} dummy_scope %{{[0-9]+}} {uniq_name = "_QFsimd_with_simdlen_safelen_clauseEn"} : (!fir.ref<i32>, !fir.dscope) -> (!fir.ref<i32>, !fir.ref<i32>)
146 integer :: i, n, threshold
147 !$OMP SIMD SIMDLEN(1) SAFELEN(2)
148 ! CHECK: %[[LB:.*]] = arith.constant 1 : i32
149 ! CHECK: %[[UB:.*]] = fir.load %[[ARG_N]]#0
150 ! CHECK: %[[STEP:.*]] = arith.constant 1 : i32
151 ! CHECK: omp.simd safelen(2) simdlen(1) {
152 ! CHECK-NEXT: omp.loop_nest (%[[I:.*]]) : i32 = (%[[LB]]) to (%[[UB]]) inclusive step (%[[STEP]]) {
153 do i = 1, n
154 ! CHECK: fir.store %[[I]] to %[[LOCAL:.*]]#1 : !fir.ref<i32>
155 ! CHECK: %[[LD:.*]] = fir.load %[[LOCAL]]#0 : !fir.ref<i32>
156 ! CHECK: fir.call @_FortranAioOutputInteger32({{.*}}, %[[LD]]) {{.*}}: (!fir.ref<i8>, i32) -> i1
157 print*, i
158 end do
159 !$OMP END SIMD
160 end subroutine
161
162 !CHECK-LABEL: func @_QPsimd_with_collapse_clause
163 subroutine simd_with_collapse_clause(n)
164 integer :: i, j, n
165 integer :: A(n,n)
166 ! CHECK: %[[LOWER_I:.*]] = arith.constant 1 : i32
167 ! CHECK: %[[UPPER_I:.*]] = fir.load %[[PARAM_ARG:.*]] : !fir.ref<i32>
168 ! CHECK: %[[STEP_I:.*]] = arith.constant 1 : i32
169 ! CHECK: %[[LOWER_J:.*]] = arith.constant 1 : i32
170 ! CHECK: %[[UPPER_J:.*]] = fir.load %[[PARAM_ARG:.*]] : !fir.ref<i32>
171 ! CHECK: %[[STEP_J:.*]] = arith.constant 1 : i32
172 ! CHECK: omp.simd {
173 ! CHECK-NEXT: omp.loop_nest (%[[ARG_0:.*]], %[[ARG_1:.*]]) : i32 = (
174 ! CHECK-SAME: %[[LOWER_I]], %[[LOWER_J]]) to (
175 ! CHECK-SAME: %[[UPPER_I]], %[[UPPER_J]]) inclusive step (
176 ! CHECK-SAME: %[[STEP_I]], %[[STEP_J]]) {
177 !$OMP SIMD COLLAPSE(2)
178 do i = 1, n
179 do j = 1, n
180 A(i,j) = i + j
181 end do
182 end do
183 !$OMP END SIMD
184 end subroutine
185
186
187 !CHECK: func.func @_QPsimdloop_aligned_cptr(%[[ARG_A:.*]]: !fir.ref
188 !CHECK-SAME: <!fir.type<_QM__fortran_builtinsT__builtin_c_ptr
189 !CHECK-SAME: {__address:i64}>> {fir.bindc_name = "a"}) {
190 !CHECK: %[[A_DECL:.*]]:2 = hlfir.declare %[[ARG_A]] dummy_scope %0
191 !CHECK-SAME: {uniq_name = "_QFsimdloop_aligned_cptrEa"} :
192 !CHECK-SAME: (!fir.ref<!fir.type<_QM__fortran_builtinsT__builtin_c_ptr{__address:i64}>>, !fir.dscope) ->
193 !CHECK-SAME: (!fir.ref<!fir.type<_QM__fortran_builtinsT__builtin_c_ptr{__address:i64}>>,
194 !CHECK-SAME: !fir.ref<!fir.type<_QM__fortran_builtinsT__builtin_c_ptr{__address:i64}>>)
195 subroutine simdloop_aligned_cptr( A)
196 use iso_c_binding
197 integer :: i
198 type (c_ptr) :: A
199 !CHECK: omp.simd aligned(%[[A_DECL]]#1 : !fir.ref
200 !CHECK-SAME: <!fir.type<_QM__fortran_builtinsT__builtin_c_ptr{__address:i64}>>
201 !CHECK-SAME: -> 256 : i64)
202 !$OMP SIMD ALIGNED(A:256)
203 do i = 1, 10
204 call c_test_call(A)
205 end do
206 !$OMP END SIMD
207 end subroutine
208
209 !CHECK-LABEL: func @_QPsimdloop_aligned_allocatable
210 subroutine simdloop_aligned_allocatable()
211 integer :: i
212 integer, allocatable :: A(:)
213 allocate(A(10))
214 !CHECK: %[[A_PTR:.*]] = fir.alloca !fir.box<!fir.heap<!fir.array<?xi32>>> {bindc_name = "a",
215 !CHECK-SAME: uniq_name = "_QFsimdloop_aligned_allocatableEa"}
216 !CHECK: %[[A_DECL:.*]]:2 = hlfir.declare %[[A_PTR]] {fortran_attrs = #fir.var_attrs<allocatable>,
217 !CHECK-SAME: uniq_name = "_QFsimdloop_aligned_allocatableEa"} :
218 !CHECK-SAME: (!fir.ref<!fir.box<!fir.heap<!fir.array<?xi32>>>>) ->
219 !CHECK-SAME: (!fir.ref<!fir.box<!fir.heap<!fir.array<?xi32>>>>, !fir.ref<!fir.box<!fir.heap<!fir.array<?xi32>>>>)
220 !CHECK: omp.simd aligned(%[[A_DECL]]#1 : !fir.ref<!fir.box<!fir.heap<!fir.array<?xi32>>>> -> 256 : i64)
221 !$OMP SIMD ALIGNED(A:256)
222 do i = 1, 10
223 A(i) = i
224 end do
225 end subroutine