1 // RUN: fir-opt --loop-versioning %s | FileCheck %s
4 // subroutine sum1d(a, n)
13 // end subroutine sum1d
14 module attributes {dlti.dl_spec = #dlti.dl_spec<#dlti.dl_entry<f80, dense<128> : vector<2xi64>>, #dlti.dl_entry<i128, dense<128> : vector<2xi64>>, #dlti.dl_entry<i64, dense<64> : vector<2xi64>>, #dlti.dl_entry<!llvm.ptr<272>, dense<64> : vector<4xi64>>, #dlti.dl_entry<!llvm.ptr<271>, dense<32> : vector<4xi64>>, #dlti.dl_entry<!llvm.ptr<270>, dense<32> : vector<4xi64>>, #dlti.dl_entry<f128, dense<128> : vector<2xi64>>, #dlti.dl_entry<f64, dense<64> : vector<2xi64>>, #dlti.dl_entry<f16, dense<16> : vector<2xi64>>, #dlti.dl_entry<i32, dense<32> : vector<2xi64>>, #dlti.dl_entry<i16, dense<16> : vector<2xi64>>, #dlti.dl_entry<i8, dense<8> : vector<2xi64>>, #dlti.dl_entry<i1, dense<8> : vector<2xi64>>, #dlti.dl_entry<!llvm.ptr, dense<64> : vector<4xi64>>, #dlti.dl_entry<"dlti.endianness", "little">, #dlti.dl_entry<"dlti.stack_alignment", 128 : i64>>} {
15 func.func @sum1d(%arg0: !fir.box<!fir.array<?xf64>> {fir.bindc_name = "a"}, %arg1: !fir.ref<i32> {fir.bindc_name = "n"}) {
16 %decl = fir.declare %arg0 {uniq_name = "a"} : (!fir.box<!fir.array<?xf64>>) -> !fir.box<!fir.array<?xf64>>
17 %rebox = fir.rebox %decl : (!fir.box<!fir.array<?xf64>>) -> !fir.box<!fir.array<?xf64>>
18 %0 = fir.alloca i32 {bindc_name = "i", uniq_name = "_QMmoduleFsum1dEi"}
19 %1 = fir.alloca f64 {bindc_name = "sum", uniq_name = "_QMmoduleFsum1dEsum"}
20 %cst = arith.constant 0.000000e+00 : f64
21 fir.store %cst to %1 : !fir.ref<f64>
22 %c1_i32 = arith.constant 1 : i32
23 %2 = fir.convert %c1_i32 : (i32) -> index
24 %3 = fir.load %arg1 : !fir.ref<i32>
25 %4 = fir.convert %3 : (i32) -> index
26 %c1 = arith.constant 1 : index
27 %5 = fir.convert %2 : (index) -> i32
28 %6:2 = fir.do_loop %arg2 = %2 to %4 step %c1 iter_args(%arg3 = %5) -> (index, i32) {
29 fir.store %arg3 to %0 : !fir.ref<i32>
30 %7 = fir.load %1 : !fir.ref<f64>
31 %8 = fir.load %0 : !fir.ref<i32>
32 %9 = fir.convert %8 : (i32) -> i64
33 %c1_i64 = arith.constant 1 : i64
34 %10 = arith.subi %9, %c1_i64 : i64
35 %11 = fir.coordinate_of %rebox, %10 : (!fir.box<!fir.array<?xf64>>, i64) -> !fir.ref<f64>
36 %12 = fir.load %11 : !fir.ref<f64>
37 %13 = arith.addf %7, %12 fastmath<contract> : f64
38 fir.store %13 to %1 : !fir.ref<f64>
39 %14 = arith.addi %arg2, %c1 : index
40 %15 = fir.convert %c1 : (index) -> i32
41 %16 = fir.load %0 : !fir.ref<i32>
42 %17 = arith.addi %16, %15 : i32
43 fir.result %14, %17 : index, i32
45 fir.store %6#1 to %0 : !fir.ref<i32>
49 // Note this only checks the expected transformation, not the entire generated code:
50 // CHECK-LABEL: func.func @sum1d(
51 // CHECK-SAME: %[[ARG0:.*]]: !fir.box<!fir.array<?xf64>> {{.*}})
52 // CHECK: %[[DECL:.*]] = fir.declare %arg0 {uniq_name = "a"} : (!fir.box<!fir.array<?xf64>>) -> !fir.box<!fir.array<?xf64>>
53 // CHECK: %[[REBOX:.*]] = fir.rebox %[[DECL]]
54 // CHECK: %[[ZERO:.*]] = arith.constant 0 : index
55 // CHECK: %[[DIMS:.*]]:3 = fir.box_dims %[[REBOX]], %[[ZERO]] : {{.*}}
56 // CHECK: %[[SIZE:.*]] = arith.constant 8 : index
57 // CHECK: %[[CMP:.*]] = arith.cmpi eq, %[[DIMS]]#2, %[[SIZE]]
58 // CHECK: %[[IF_RES:.*]]:2 = fir.if %[[CMP]] -> {{.*}}
59 // CHECK: %[[NEWARR:.*]] = fir.convert %[[REBOX]]
60 // CHECK: %[[BOXADDR:.*]] = fir.box_addr %[[NEWARR]] : {{.*}} -> !fir.ref<!fir.array<?xf64>>
61 // CHECK: %[[LOOP_RES:.*]]:2 = fir.do_loop {{.*}}
62 // CHECK: %[[COORD:.*]] = fir.coordinate_of %[[BOXADDR]], %{{.*}} : (!fir.ref<!fir.array<?xf64>>, index) -> !fir.ref<f64>
63 // CHECK: %{{.*}} = fir.load %[[COORD]] : !fir.ref<f64>
64 // CHECK: fir.result %{{.*}}, %{{.*}}
66 // CHECK fir.result %[[LOOP_RES]]#0, %[[LOOP_RES]]#1
68 // CHECK: %[[LOOP_RES2:.*]]:2 = fir.do_loop {{.*}}
69 // CHECK: %[[COORD2:.*]] = fir.coordinate_of %[[REBOX]], %{{.*}} : (!fir.box<!fir.array<?xf64>>, i64) -> !fir.ref<f64>
70 // CHECK: %{{.*}}= fir.load %[[COORD2]] : !fir.ref<f64>
71 // CHECK: fir.result %{{.*}}, %{{.*}}
73 // CHECK fir.result %[[LOOP_RES2]]#0, %[[LOOP_RES2]]#1
75 // CHECK: fir.store %[[IF_RES]]#1 to %{{.*}}
80 // Test that loop-versioning pass doesn't expand known size arrays.
81 func.func @sum1dfixed(%arg0: !fir.ref<!fir.array<?xf64>> {fir.bindc_name = "a"}, %arg1: !fir.ref<i32> {fir.bindc_name = "n"}) {
82 %0 = fir.alloca i32 {bindc_name = "i", uniq_name = "_QFsum1dfixedEi"}
83 %1 = fir.alloca f64 {bindc_name = "sum", uniq_name = "_QFsum1dfixedEsum"}
84 %cst = arith.constant 0.000000e+00 : f64
85 fir.store %cst to %1 : !fir.ref<f64>
86 %c1_i32 = arith.constant 1 : i32
87 %2 = fir.convert %c1_i32 : (i32) -> index
88 %3 = fir.load %arg1 : !fir.ref<i32>
89 %4 = fir.convert %3 : (i32) -> index
90 %c1 = arith.constant 1 : index
91 %5 = fir.convert %2 : (index) -> i32
92 %6:2 = fir.do_loop %arg2 = %2 to %4 step %c1 iter_args(%arg3 = %5) -> (index, i32) {
93 fir.store %arg3 to %0 : !fir.ref<i32>
94 %7 = fir.load %1 : !fir.ref<f64>
95 %8 = fir.load %0 : !fir.ref<i32>
96 %9 = fir.convert %8 : (i32) -> i64
97 %c1_i64 = arith.constant 1 : i64
98 %10 = arith.subi %9, %c1_i64 : i64
99 %11 = fir.coordinate_of %arg0, %10 : (!fir.ref<!fir.array<?xf64>>, i64) -> !fir.ref<f64>
100 %12 = fir.load %11 : !fir.ref<f64>
101 %13 = arith.addf %7, %12 fastmath<contract> : f64
102 fir.store %13 to %1 : !fir.ref<f64>
103 %14 = arith.addi %arg2, %c1 : index
104 %15 = fir.convert %c1 : (index) -> i32
105 %16 = fir.load %0 : !fir.ref<i32>
106 %17 = arith.addi %16, %15 : i32
107 fir.result %14, %17 : index, i32
109 fir.store %6#1 to %0 : !fir.ref<i32>
113 // CHECK-LABEL: func.func @sum1dfixed(
114 // CHECK-SAME: %[[ARG0:.*]]: !fir.ref<!fir.array<?xf64>> {{.*}})
115 // CHECK: fir.do_loop {{.*}}
116 // CHECK: %[[COORD:.*]] = fir.coordinate_of %[[ARG0]], {{.*}}
117 // CHECK: %{{.*}} = fir.load %[[COORD]]
121 // Check that "no result" from a versioned loop works correctly
122 // This code was the basis for this, but `read` is replaced with a function called Func
123 // subroutine test3(x, y)
129 func.func @test3(%arg0: !fir.box<!fir.array<?xi32>> {fir.bindc_name = "x"}, %arg1: !fir.box<!fir.array<?xi32>> {fir.bindc_name = "y"}) {
130 %c0 = arith.constant 0 : index
131 %3:3 = fir.box_dims %arg1, %c0 : (!fir.box<!fir.array<?xi32>>, index) -> (index, index, index)
132 %c1 = arith.constant 1 : index
133 %4 = fir.slice %c1, %3#1, %c1 : (index, index, index) -> !fir.slice<1>
134 %c1_0 = arith.constant 1 : index
135 %c0_1 = arith.constant 0 : index
136 %5 = arith.subi %3#1, %c1_0 : index
137 fir.do_loop %arg2 = %c0_1 to %5 step %c1_0 {
138 %7 = fir.coordinate_of %arg1, %arg2 : (!fir.box<!fir.array<?xi32>>, index) -> !fir.ref<i32>
139 %8 = fir.load %7 : !fir.ref<i32>
140 %9 = fir.convert %8 : (i32) -> index
141 %10 = fir.array_coor %arg0 [%4] %9 : (!fir.box<!fir.array<?xi32>>, !fir.slice<1>, index) -> !fir.ref<i32>
142 %12 = fir.call @Func(%10) fastmath<contract> : (!fir.ref<i32>) -> i1
146 func.func private @Func(!fir.ref<i8>, !fir.ref<i32>) -> i1
148 // CHECK-LABEL: func.func @test3(
149 // CHECK-SAME: %[[X:.*]]: !fir.box<!fir.array<?xi32>> {{.*}},
150 // CHECK-SAME: %[[Y:.*]]: !fir.box<!fir.array<?xi32>> {{.*}}) {
151 // Look for arith.subi to locate the correct part of code.
152 // CHECK: {{.*}} arith.subi {{.*}}
153 // CHECK: %[[ZERO:.*]] = arith.constant 0 : index
154 // CHECK: %[[DIMS:.*]]:3 = fir.box_dims %[[Y]], %[[ZERO]]
155 // CHECK: %[[FOUR:.*]] = arith.constant 4 : index
156 // CHECK: %[[COMP:.*]] = arith.cmpi eq, %[[DIMS]]#2, %[[FOUR]] : index
157 // CHECK: fir.if %[[COMP]] {
158 // CHECK: %[[CONV:.*]] = fir.convert %[[Y]] : {{.*}}
159 // CHECK: %[[BOX_ADDR:.*]] = fir.box_addr %[[CONV]] : {{.*}}
160 // CHECK: fir.do_loop %[[INDEX:.*]] = {{.*}}
161 // CHECK: %[[YADDR:.*]] = fir.coordinate_of %[[BOX_ADDR]], %[[INDEX]]
162 // CHECK: %[[YINT:.*]] = fir.load %[[YADDR]] : {{.*}}
163 // CHECK: %[[YINDEX:.*]] = fir.convert %[[YINT]]
164 // CHECK: %[[XADDR:.*]] = fir.array_coor %[[X]] [%{{.*}}] %[[YINDEX]]
165 // CHECK: fir.call @Func(%[[XADDR]])
167 // CHECK-NEXT: } else {
168 // CHECK: fir.do_loop %[[INDEX2:.*]] = {{.*}}
169 // CHECK: %[[YADDR2:.*]] = fir.coordinate_of %[[Y]], %[[INDEX2]]
170 // CHECK: %[[YINT2:.*]] = fir.load %[[YADDR2]] : {{.*}}
171 // CHECK: %[[YINDEX2:.*]] = fir.convert %[[YINT2]]
172 // CHECK: %[[XADDR2:.*]] = fir.array_coor %[[X]] [%{{.*}}] %[[YINDEX2]]
173 // CHECK: fir.call @Func(%[[XADDR2]])
179 // Test array initialization.
181 // This code has been modified to simplify it - removing the realloc generated to grow
183 //subroutine test4(a, b, n1, m1)
187 // a = [ ((b(i,j), j=1,n1,m1), i=1,n1,m1) ]
188 //end subroutine test4
190 func.func @test4(%arg0: !fir.box<!fir.array<?xf32>> {fir.bindc_name = "a"}, %arg1: !fir.box<!fir.array<?x?xf32>> {fir.bindc_name = "b"}, %arg2: !fir.ref<i32> {fir.bindc_name = "n1"}, %arg3: !fir.ref<i32> {fir.bindc_name = "m1"}) {
191 %0 = fir.alloca index {bindc_name = ".buff.pos"}
192 %1 = fir.alloca index {bindc_name = ".buff.size"}
193 %c0 = arith.constant 0 : index
194 %2:3 = fir.box_dims %arg0, %c0 : (!fir.box<!fir.array<?xf32>>, index) -> (index, index, index)
195 %3 = fir.array_load %arg0 : (!fir.box<!fir.array<?xf32>>) -> !fir.array<?xf32>
196 %c0_0 = arith.constant 0 : index
197 fir.store %c0_0 to %0 : !fir.ref<index>
198 %c32 = arith.constant 32 : index
199 %4 = fir.allocmem f32, %c32
200 fir.store %c32 to %1 : !fir.ref<index>
201 %c1_i64 = arith.constant 1 : i64
202 %5 = fir.convert %c1_i64 : (i64) -> index
203 %6 = fir.load %arg2 : !fir.ref<i32>
204 %7 = fir.convert %6 : (i32) -> i64
205 %8 = fir.convert %7 : (i64) -> index
206 %9 = fir.load %arg3 : !fir.ref<i32>
207 %10 = fir.convert %9 : (i32) -> i64
208 %11 = fir.convert %10 : (i64) -> index
209 %12 = fir.do_loop %arg4 = %5 to %8 step %11 iter_args(%arg5 = %4) -> (!fir.heap<f32>) {
210 %c1_i64_2 = arith.constant 1 : i64
211 %19 = fir.convert %c1_i64_2 : (i64) -> index
212 %20 = fir.load %arg2 : !fir.ref<i32>
213 %21 = fir.convert %20 : (i32) -> i64
214 %22 = fir.convert %21 : (i64) -> index
215 %23 = fir.load %arg3 : !fir.ref<i32>
216 %24 = fir.convert %23 : (i32) -> i64
217 %25 = fir.convert %24 : (i64) -> index
218 %26 = fir.do_loop %arg6 = %19 to %22 step %25 iter_args(%arg7 = %arg5) -> (!fir.heap<f32>) {
219 %27 = fir.convert %arg4 : (index) -> i32
220 %28 = fir.convert %27 : (i32) -> i64
221 %c1_i64_3 = arith.constant 1 : i64
222 %29 = arith.subi %28, %c1_i64_3 : i64
223 %30 = fir.convert %arg6 : (index) -> i32
224 %31 = fir.convert %30 : (i32) -> i64
225 %c1_i64_4 = arith.constant 1 : i64
226 %32 = arith.subi %31, %c1_i64_4 : i64
227 %33 = fir.coordinate_of %arg1, %29, %32 : (!fir.box<!fir.array<?x?xf32>>, i64, i64) -> !fir.ref<f32>
228 %34 = fir.load %33 : !fir.ref<f32>
229 %c1_5 = arith.constant 1 : index
230 %35 = fir.zero_bits !fir.ref<!fir.array<?xf32>>
231 %36 = fir.coordinate_of %35, %c1_5 : (!fir.ref<!fir.array<?xf32>>, index) -> !fir.ref<f32>
232 %37 = fir.convert %36 : (!fir.ref<f32>) -> index
233 %38 = fir.load %0 : !fir.ref<index>
234 %39 = fir.load %1 : !fir.ref<index>
235 %c1_6 = arith.constant 1 : index
236 %40 = arith.addi %38, %c1_6 : index
238 fir.store %40 to %0 : !fir.ref<index>
239 fir.result %arg7 : !fir.heap<f32>
241 fir.result %26 : !fir.heap<f32>
243 %13 = fir.convert %12 : (!fir.heap<f32>) -> !fir.heap<!fir.array<?xf32>>
244 %14 = fir.load %0 : !fir.ref<index>
245 %15 = fir.shape %14 : (index) -> !fir.shape<1>
246 %16 = fir.array_load %13(%15) : (!fir.heap<!fir.array<?xf32>>, !fir.shape<1>) -> !fir.array<?xf32>
247 %c1 = arith.constant 1 : index
248 %c0_1 = arith.constant 0 : index
249 %17 = arith.subi %2#1, %c1 : index
250 %18 = fir.do_loop %arg4 = %c0_1 to %17 step %c1 unordered iter_args(%arg5 = %3) -> (!fir.array<?xf32>) {
251 %19 = fir.array_fetch %16, %arg4 : (!fir.array<?xf32>, index) -> f32
252 %20 = fir.array_update %arg5, %19, %arg4 : (!fir.array<?xf32>, f32, index) -> !fir.array<?xf32>
253 fir.result %20 : !fir.array<?xf32>
255 fir.array_merge_store %3, %18 to %arg0 : !fir.array<?xf32>, !fir.array<?xf32>, !fir.box<!fir.array<?xf32>>
256 fir.freemem %13 : !fir.heap<!fir.array<?xf32>>
260 // CHECK: func.func @test4(
261 // CHECK-SAME: %[[A:.*]]: !fir.box<!fir.array<?xf32>>
262 // CHECK-SAME: %[[B:.*]]: !fir.box<!fir.array<?x?xf32>>
263 // CHECK-SAME: %[[N1:.*]]: !fir.ref<i32> {{.*}},
264 // CHECK-SAME: %[[M1:.*]]: !fir.ref<i32> {{.*}}) {
265 // CHECK: fir.do_loop
266 // CHECK: %[[FOUR:.*]] = arith.constant 4 : index
267 // CHECK: %[[COMP:.*]] = arith.cmpi {{.*}}, %[[FOUR]]
268 // CHECK: fir.if %[[COMP]] -> {{.*}} {
269 // CHECK: %[[CONV:.*]] = fir.convert %[[B]] :
270 // CHECK: %[[BOX_ADDR:.*]] = fir.box_addr %[[CONV]]
271 // CHECK: %[[RES:.*]] = fir.do_loop {{.*}} {
272 // CHECK: %[[ADDR:.*]] = fir.coordinate_of %[[BOX_ADDR]], %{{.*}}
273 // CHECK: %{{.*}} = fir.load %[[ADDR]] : !fir.ref<f32>
275 // CHECK: fir.result %[[RES]] : {{.*}}
277 // CHECK: %[[RES2:.*]] = fir.do_loop
278 // CHECK: %{{.*}} = fir.coordinate_of %[[B]], %{{.*}}
280 // CHECK: fir.result %[[RES2]]
286 // Check that 2D arrays are identified and converted.
288 // subroutine sum2d(a, nx, ny)
296 // sum = sum + a(j,i)
299 // end subroutine sum2d
301 func.func @sum2d(%arg0: !fir.box<!fir.array<?x?xf64>> {fir.bindc_name = "a"}, %arg1: !fir.ref<i32> {fir.bindc_name = "nx"}, %arg2: !fir.ref<i32> {fir.bindc_name = "ny"}) {
302 %0 = fir.alloca i32 {bindc_name = "i", uniq_name = "_QMmoduleFsum2dEi"}
303 %1 = fir.alloca i32 {bindc_name = "j", uniq_name = "_QMmoduleFsum2dEj"}
304 %2 = fir.alloca f64 {bindc_name = "sum", uniq_name = "_QMmoduleFsum2dEsum"}
305 %cst = arith.constant 0.000000e+00 : f64
306 fir.store %cst to %2 : !fir.ref<f64>
307 %c1_i32 = arith.constant 1 : i32
308 %3 = fir.convert %c1_i32 : (i32) -> index
309 %4 = fir.load %arg1 : !fir.ref<i32>
310 %5 = fir.convert %4 : (i32) -> index
311 %c1 = arith.constant 1 : index
312 %6 = fir.convert %3 : (index) -> i32
313 %7:2 = fir.do_loop %arg3 = %3 to %5 step %c1 iter_args(%arg4 = %6) -> (index, i32) {
314 fir.store %arg4 to %0 : !fir.ref<i32>
315 %c1_i32_0 = arith.constant 1 : i32
316 %8 = fir.convert %c1_i32_0 : (i32) -> index
317 %9 = fir.load %arg2 : !fir.ref<i32>
318 %10 = fir.convert %9 : (i32) -> index
319 %c1_1 = arith.constant 1 : index
320 %11 = fir.convert %8 : (index) -> i32
321 %12:2 = fir.do_loop %arg5 = %8 to %10 step %c1_1 iter_args(%arg6 = %11) -> (index, i32) {
322 fir.store %arg6 to %1 : !fir.ref<i32>
323 %17 = fir.load %2 : !fir.ref<f64>
324 %18 = fir.load %1 : !fir.ref<i32>
325 %19 = fir.convert %18 : (i32) -> i64
326 %c1_i64 = arith.constant 1 : i64
327 %20 = arith.subi %19, %c1_i64 : i64
328 %21 = fir.load %0 : !fir.ref<i32>
329 %22 = fir.convert %21 : (i32) -> i64
330 %c1_i64_2 = arith.constant 1 : i64
331 %23 = arith.subi %22, %c1_i64_2 : i64
332 %24 = fir.coordinate_of %arg0, %20, %23 : (!fir.box<!fir.array<?x?xf64>>, i64, i64) -> !fir.ref<f64>
333 %25 = fir.load %24 : !fir.ref<f64>
334 %26 = arith.addf %17, %25 fastmath<contract> : f64
335 fir.store %26 to %2 : !fir.ref<f64>
336 %27 = arith.addi %arg5, %c1_1 : index
337 %28 = fir.convert %c1_1 : (index) -> i32
338 %29 = fir.load %1 : !fir.ref<i32>
339 %30 = arith.addi %29, %28 : i32
340 fir.result %27, %30 : index, i32
342 fir.store %12#1 to %1 : !fir.ref<i32>
343 %13 = arith.addi %arg3, %c1 : index
344 %14 = fir.convert %c1 : (index) -> i32
345 %15 = fir.load %0 : !fir.ref<i32>
346 %16 = arith.addi %15, %14 : i32
347 fir.result %13, %16 : index, i32
349 fir.store %7#1 to %0 : !fir.ref<i32>
353 // Note this only checks the expected transformation, not the entire generated code:
354 // CHECK-LABEL: func.func @sum2d(
355 // CHECK-SAME: %[[ARG0:.*]]: !fir.box<!fir.array<?x?xf64>> {{.*}})
356 // Only inner loop should be verisoned.
357 // CHECK: fir.do_loop
358 // CHECK: %[[ZERO:.*]] = arith.constant 0 : index
359 // CHECK: %[[DIMS0:.*]]:3 = fir.box_dims %[[ARG0]], %[[ZERO]] : {{.*}}
360 // CHECK: %[[ONE:.*]] = arith.constant 1 : index
361 // CHECK: %[[DIMS1:.*]]:3 = fir.box_dims %[[ARG0]], %[[ONE]] : {{.*}}
362 // CHECK: %[[SIZE:.*]] = arith.constant 8 : index
363 // CHECK: %[[CMP:.*]] = arith.cmpi eq, %[[DIMS0]]#2, %[[SIZE]]
364 // CHECK: %[[IF_RES:.*]]:2 = fir.if %[[CMP]] -> {{.*}}
365 // CHECK: %[[NEWARR:.*]] = fir.convert %[[ARG0]]
366 // CHECK: %[[BOXADDR:.*]] = fir.box_addr %[[NEWARR]] : {{.*}} -> !fir.ref<!fir.array<?xf64>>
367 // CHECK: %[[LOOP_RES:.*]]:2 = fir.do_loop {{.*}}
368 // Check the 2D -> 1D coordinate conversion, should have a multiply and a final add.
369 // Some other operations are checked to synch the different parts.
370 // CHECK: %[[OUTER_IDX:.*]] = arith.muli %[[DIMS1]]#2, {{.*}}
371 // CHECK: %[[INNER_IDX:.*]] = fir.convert {{.*}}
372 // CHECK: %[[ITEMSHIFT:.*]] = arith.constant 3 : index
373 // CHECK: %[[OUTER_DIV:.*]] = arith.shrsi %[[OUTER_IDX]], %[[ITEMSHIFT]]
374 // CHECK: %[[C2D:.*]] = arith.addi %[[OUTER_DIV]], %[[INNER_IDX]]
375 // CHECK: %[[COORD:.*]] = fir.coordinate_of %[[BOXADDR]], %[[C2D]] : (!fir.ref<!fir.array<?xf64>>, index) -> !fir.ref<f64>
376 // CHECK: %{{.*}} = fir.load %[[COORD]] : !fir.ref<f64>
377 // CHECK: fir.result %{{.*}}, %{{.*}}
379 // CHECK fir.result %[[LOOP_RES]]#0, %[[LOOP_RES]]#1
381 // CHECK: %[[LOOP_RES2:.*]]:2 = fir.do_loop {{.*}}
382 // CHECK: %[[COORD2:.*]] = fir.coordinate_of %[[ARG0]], %{{.*}} : (!fir.box<!fir.array<?x?xf64>>, i64, i64) -> !fir.ref<f64>
383 // CHECK: %{{.*}}= fir.load %[[COORD2]] : !fir.ref<f64>
384 // CHECK: fir.result %{{.*}}, %{{.*}}
386 // CHECK fir.result %[[LOOP_RES2]]#0, %[[LOOP_RES2]]#1
388 // CHECK: fir.store %[[IF_RES]]#1 to %{{.*}}
393 // subroutine sum3d(a, nx, ny, nz)
394 // real*8 :: a(:, :, :)
395 // integer :: nx, ny, nz
397 // integer :: i, j, k
402 // sum = sum + a(i, j, k)
406 // end subroutine sum3d
409 func.func @sum3d(%arg0: !fir.box<!fir.array<?x?x?xf64>> {fir.bindc_name = "a"}, %arg1: !fir.ref<i32> {fir.bindc_name = "nx"}, %arg2: !fir.ref<i32> {fir.bindc_name = "ny"}, %arg3: !fir.ref<i32> {fir.bindc_name = "nz"}) {
410 %0 = fir.alloca i32 {bindc_name = "i", uniq_name = "_QMmoduleFsum3dEi"}
411 %1 = fir.alloca i32 {bindc_name = "j", uniq_name = "_QMmoduleFsum3dEj"}
412 %2 = fir.alloca i32 {bindc_name = "k", uniq_name = "_QMmoduleFsum3dEk"}
413 %3 = fir.alloca f64 {bindc_name = "sum", uniq_name = "_QMmoduleFsum3dEsum"}
414 %cst = arith.constant 0.000000e+00 : f64
415 fir.store %cst to %3 : !fir.ref<f64>
416 %c1_i32 = arith.constant 1 : i32
417 %4 = fir.convert %c1_i32 : (i32) -> index
418 %5 = fir.load %arg3 : !fir.ref<i32>
419 %6 = fir.convert %5 : (i32) -> index
420 %c1 = arith.constant 1 : index
421 %7 = fir.convert %4 : (index) -> i32
422 %8:2 = fir.do_loop %arg4 = %4 to %6 step %c1 iter_args(%arg5 = %7) -> (index, i32) {
423 fir.store %arg5 to %2 : !fir.ref<i32>
424 %c1_i32_0 = arith.constant 1 : i32
425 %9 = fir.convert %c1_i32_0 : (i32) -> index
426 %10 = fir.load %arg2 : !fir.ref<i32>
427 %11 = fir.convert %10 : (i32) -> index
428 %c1_1 = arith.constant 1 : index
429 %12 = fir.convert %9 : (index) -> i32
430 %13:2 = fir.do_loop %arg6 = %9 to %11 step %c1_1 iter_args(%arg7 = %12) -> (index, i32) {
431 fir.store %arg7 to %1 : !fir.ref<i32>
432 %c0_i32 = arith.constant 0 : i32
433 %18 = fir.convert %c0_i32 : (i32) -> index
434 %19 = fir.load %arg1 : !fir.ref<i32>
435 %20 = fir.convert %19 : (i32) -> index
436 %c1_2 = arith.constant 1 : index
437 %21 = fir.convert %18 : (index) -> i32
438 %22:2 = fir.do_loop %arg8 = %18 to %20 step %c1_2 iter_args(%arg9 = %21) -> (index, i32) {
439 fir.store %arg9 to %0 : !fir.ref<i32>
440 %27 = fir.load %3 : !fir.ref<f64>
441 %28 = fir.load %0 : !fir.ref<i32>
442 %29 = fir.convert %28 : (i32) -> i64
443 %c1_i64 = arith.constant 1 : i64
444 %30 = arith.subi %29, %c1_i64 : i64
445 %31 = fir.load %1 : !fir.ref<i32>
446 %32 = fir.convert %31 : (i32) -> i64
447 %c1_i64_3 = arith.constant 1 : i64
448 %33 = arith.subi %32, %c1_i64_3 : i64
449 %34 = fir.load %2 : !fir.ref<i32>
450 %35 = fir.convert %34 : (i32) -> i64
451 %c1_i64_4 = arith.constant 1 : i64
452 %36 = arith.subi %35, %c1_i64_4 : i64
453 %37 = fir.coordinate_of %arg0, %30, %33, %36 : (!fir.box<!fir.array<?x?x?xf64>>, i64, i64, i64) -> !fir.ref<f64>
454 %38 = fir.load %37 : !fir.ref<f64>
455 %39 = arith.addf %27, %38 fastmath<contract> : f64
456 fir.store %39 to %3 : !fir.ref<f64>
457 %40 = arith.addi %arg8, %c1_2 : index
458 %41 = fir.convert %c1_2 : (index) -> i32
459 %42 = fir.load %0 : !fir.ref<i32>
460 %43 = arith.addi %42, %41 : i32
461 fir.result %40, %43 : index, i32
463 fir.store %22#1 to %0 : !fir.ref<i32>
464 %23 = arith.addi %arg6, %c1_1 : index
465 %24 = fir.convert %c1_1 : (index) -> i32
466 %25 = fir.load %1 : !fir.ref<i32>
467 %26 = arith.addi %25, %24 : i32
468 fir.result %23, %26 : index, i32
470 fir.store %13#1 to %1 : !fir.ref<i32>
471 %14 = arith.addi %arg4, %c1 : index
472 %15 = fir.convert %c1 : (index) -> i32
473 %16 = fir.load %2 : !fir.ref<i32>
474 %17 = arith.addi %16, %15 : i32
475 fir.result %14, %17 : index, i32
477 fir.store %8#1 to %2 : !fir.ref<i32>
481 // Note this only checks the expected transformation, not the entire generated code:
482 // CHECK-LABEL: func.func @sum3d(
483 // CHECK-SAME: %[[ARG0:.*]]: !fir.box<!fir.array<?x?x?xf64>> {{.*}})
484 // Only inner loop should be verisoned.
485 // CHECK: fir.do_loop
486 // CHECK: %[[ZERO:.*]] = arith.constant 0 : index
487 // CHECK: %[[DIMS0:.*]]:3 = fir.box_dims %[[ARG0]], %[[ZERO]] : {{.*}}
488 // CHECK: %[[ONE:.*]] = arith.constant 1 : index
489 // CHECK: %[[DIMS1:.*]]:3 = fir.box_dims %[[ARG0]], %[[ONE]] : {{.*}}
490 // CHECK: %[[TWO:.*]] = arith.constant 2 : index
491 // CHECK: %[[DIMS2:.*]]:3 = fir.box_dims %[[ARG0]], %[[TWO]] : {{.*}}
492 // CHECK: %[[SIZE:.*]] = arith.constant 8 : index
493 // CHECK: %[[CMP:.*]] = arith.cmpi eq, %[[DIMS0]]#2, %[[SIZE]]
494 // CHECK: %[[IF_RES:.*]]:2 = fir.if %[[CMP]] -> {{.*}}
495 // CHECK: %[[NEWARR:.*]] = fir.convert %[[ARG0]]
496 // CHECK: %[[BOXADDR:.*]] = fir.box_addr %[[NEWARR]] : {{.*}} -> !fir.ref<!fir.array<?xf64>>
497 // CHECK: %[[LOOP_RES:.*]]:2 = fir.do_loop {{.*}}
498 // Check the 3D -> 1D coordinate conversion, should have a multiply and a final add.
499 // Some other operations are checked to synch the different parts.
500 // CHECK: %[[OUTER_IDX:.*]] = arith.muli %[[DIMS2]]#2, {{.*}}
501 // CHECK: %[[MIDDLE_IDX:.*]] = arith.muli %[[DIMS1]]#2, {{.*}}
502 // CHECK: %[[MIDDLE_SUM:.*]] = arith.addi %[[MIDDLE_IDX]], %[[OUTER_IDX]]
503 // CHECK: %[[INNER_IDX:.*]] = fir.convert {{.*}}
504 // CHECK: %[[ITEMSHIFT:.*]] = arith.constant 3 : index
505 // CHECK: %[[MIDDLE_DIV:.*]] = arith.shrsi %[[MIDDLE_SUM]], %[[ITEMSHIFT]]
506 // CHECK: %[[C3D:.*]] = arith.addi %[[MIDDLE_DIV]], %[[INNER_IDX]]
507 // CHECK: %[[COORD:.*]] = fir.coordinate_of %[[BOXADDR]], %[[C3D]] : (!fir.ref<!fir.array<?xf64>>, index) -> !fir.ref<f64>
508 // CHECK: %{{.*}} = fir.load %[[COORD]] : !fir.ref<f64>
509 // CHECK: fir.result %{{.*}}, %{{.*}}
511 // CHECK fir.result %[[LOOP_RES]]#0, %[[LOOP_RES]]#1
513 // CHECK: %[[LOOP_RES2:.*]]:2 = fir.do_loop {{.*}}
514 // CHECK: %[[COORD2:.*]] = fir.coordinate_of %[[ARG0]], %{{.*}} : (!fir.box<!fir.array<?x?x?xf64>>, i64, i64, i64) -> !fir.ref<f64>
515 // CHECK: %{{.*}}= fir.load %[[COORD2]] : !fir.ref<f64>
516 // CHECK: fir.result %{{.*}}, %{{.*}}
518 // CHECK fir.result %[[LOOP_RES2]]#0, %[[LOOP_RES2]]#1
520 // CHECK: fir.store %[[IF_RES]]#1 to %{{.*}}
523 // Check that OPTIONAL argument's box is not accessed illegally
525 func.func @test_optional_arg(%arg0: !fir.box<!fir.array<?xf32>> {fir.bindc_name = "x", fir.optional}) {
526 %c1 = arith.constant 1 : index
527 %c20 = arith.constant 20 : index
528 %c0_i64 = arith.constant 0 : i64
529 %0 = fir.alloca i32 {bindc_name = "i", uniq_name = "_QMcheck_modFtestEi"}
530 %1 = fir.convert %c1 : (index) -> i32
531 %2:2 = fir.do_loop %arg1 = %c1 to %c20 step %c1 iter_args(%arg2 = %1) -> (index, i32) {
532 fir.store %arg2 to %0 : !fir.ref<i32>
533 %3 = fir.is_present %arg0 : (!fir.box<!fir.array<?xf32>>) -> i1
535 %8 = fir.coordinate_of %arg0, %c0_i64 : (!fir.box<!fir.array<?xf32>>, i64) -> !fir.ref<f32>
538 %4 = arith.addi %arg1, %c1 : index
539 %5 = fir.convert %c1 : (index) -> i32
540 %6 = fir.load %0 : !fir.ref<i32>
541 %7 = arith.addi %6, %5 : i32
542 fir.result %4, %7 : index, i32
544 fir.store %2#1 to %0 : !fir.ref<i32>
547 // CHECK-LABEL: func.func @test_optional_arg(
548 // CHECK-SAME: %[[VAL_0:.*]]: !fir.box<!fir.array<?xf32>> {fir.bindc_name = "x", fir.optional}) {
549 // CHECK-NEXT: %[[VAL_1:.*]] = arith.constant 1 : index
550 // CHECK-NEXT: %[[VAL_2:.*]] = arith.constant 20 : index
551 // CHECK-NEXT: %[[VAL_3:.*]] = arith.constant 0 : i64
552 // CHECK-NEXT: %[[VAL_4:.*]] = fir.alloca i32 {bindc_name = "i", uniq_name = "_QMcheck_modFtestEi"}
553 // CHECK-NEXT: %[[VAL_5:.*]] = fir.convert %[[VAL_1]] : (index) -> i32
554 // CHECK-NEXT: %[[VAL_6:.*]]:2 = fir.do_loop %[[VAL_7:.*]] = %[[VAL_1]] to %[[VAL_2]] step %[[VAL_1]] iter_args(%[[VAL_8:.*]] = %[[VAL_5]]) -> (index, i32) {
555 // CHECK-NEXT: fir.store %[[VAL_8]] to %[[VAL_4]] : !fir.ref<i32>
556 // CHECK-NEXT: %[[VAL_9:.*]] = fir.is_present %[[VAL_0]] : (!fir.box<!fir.array<?xf32>>) -> i1
557 // CHECK-NEXT: fir.if %[[VAL_9]] {
558 // CHECK-NEXT: %[[VAL_10:.*]] = fir.coordinate_of %[[VAL_0]], %[[VAL_3]] : (!fir.box<!fir.array<?xf32>>, i64) -> !fir.ref<f32>
559 // CHECK-NEXT: } else {
561 // CHECK-NEXT: %[[VAL_11:.*]] = arith.addi %[[VAL_7]], %[[VAL_1]] : index
562 // CHECK-NEXT: %[[VAL_12:.*]] = fir.convert %[[VAL_1]] : (index) -> i32
563 // CHECK-NEXT: %[[VAL_13:.*]] = fir.load %[[VAL_4]] : !fir.ref<i32>
564 // CHECK-NEXT: %[[VAL_14:.*]] = arith.addi %[[VAL_13]], %[[VAL_12]] : i32
565 // CHECK-NEXT: fir.result %[[VAL_11]], %[[VAL_14]] : index, i32
567 // CHECK-NEXT: fir.store %[[VAL_15:.*]]#1 to %[[VAL_4]] : !fir.ref<i32>
568 // CHECK-NEXT: return
571 // test sum1d with hlfir lowering
572 func.func @_QPsum1d(%arg0: !fir.box<!fir.array<?xf64>> {fir.bindc_name = "a"}, %arg1: !fir.ref<i32> {fir.bindc_name = "n"}) {
573 %c1 = arith.constant 1 : index
574 %cst = arith.constant 0.000000e+00 : f64
575 %0 = fir.declare %arg0 {uniq_name = "_QFsum1dEa"} : (!fir.box<!fir.array<?xf64>>) -> !fir.box<!fir.array<?xf64>>
576 %1 = fir.rebox %0 : (!fir.box<!fir.array<?xf64>>) -> !fir.box<!fir.array<?xf64>>
577 %2 = fir.alloca i32 {bindc_name = "i", uniq_name = "_QFsum1dEi"}
578 %3 = fir.declare %2 {uniq_name = "_QFsum1dEi"} : (!fir.ref<i32>) -> !fir.ref<i32>
579 %4 = fir.declare %arg1 {uniq_name = "_QFsum1dEn"} : (!fir.ref<i32>) -> !fir.ref<i32>
580 %5 = fir.alloca f64 {bindc_name = "sum", uniq_name = "_QFsum1dEsum"}
581 %6 = fir.declare %5 {uniq_name = "_QFsum1dEsum"} : (!fir.ref<f64>) -> !fir.ref<f64>
582 fir.store %cst to %6 : !fir.ref<f64>
583 %7 = fir.load %4 : !fir.ref<i32>
584 %8 = fir.convert %7 : (i32) -> index
585 %9 = fir.convert %c1 : (index) -> i32
586 %10:2 = fir.do_loop %arg2 = %c1 to %8 step %c1 iter_args(%arg3 = %9) -> (index, i32) {
587 fir.store %arg3 to %3 : !fir.ref<i32>
588 %11 = fir.load %6 : !fir.ref<f64>
589 %12 = fir.load %3 : !fir.ref<i32>
590 %13 = fir.convert %12 : (i32) -> i64
591 %14 = fir.array_coor %1 %13 : (!fir.box<!fir.array<?xf64>>, i64) -> !fir.ref<f64>
592 %15 = fir.load %14 : !fir.ref<f64>
593 %16 = arith.addf %11, %15 fastmath<contract> : f64
594 fir.store %16 to %6 : !fir.ref<f64>
595 %17 = arith.addi %arg2, %c1 : index
596 %18 = fir.load %3 : !fir.ref<i32>
597 %19 = arith.addi %18, %9 : i32
598 fir.result %17, %19 : index, i32
600 fir.store %10#1 to %3 : !fir.ref<i32>
603 // CHECK-LABEL: func.func @_QPsum1d(
604 // CHECK-SAME: %[[VAL_0:.*]]: !fir.box<!fir.array<?xf64>> {fir.bindc_name = "a"},
605 // CHECK-SAME: %[[VAL_1:.*]]: !fir.ref<i32> {fir.bindc_name = "n"}) {
606 // CHECK: %[[VAL_2:.*]] = arith.constant 1 : index
607 // CHECK: %[[VAL_3:.*]] = arith.constant 0.000000e+00 : f64
608 // CHECK: %[[VAL_4:.*]] = fir.declare %[[VAL_0]] {uniq_name = "_QFsum1dEa"} : (!fir.box<!fir.array<?xf64>>) -> !fir.box<!fir.array<?xf64>>
609 // CHECK: %[[VAL_5:.*]] = fir.rebox %[[VAL_4]] : (!fir.box<!fir.array<?xf64>>) -> !fir.box<!fir.array<?xf64>>
610 // CHECK: %[[VAL_6:.*]] = fir.alloca i32 {bindc_name = "i", uniq_name = "_QFsum1dEi"}
611 // CHECK: %[[VAL_7:.*]] = fir.declare %[[VAL_6]] {uniq_name = "_QFsum1dEi"} : (!fir.ref<i32>) -> !fir.ref<i32>
612 // CHECK: %[[VAL_8:.*]] = fir.declare %[[VAL_1]] {uniq_name = "_QFsum1dEn"} : (!fir.ref<i32>) -> !fir.ref<i32>
613 // CHECK: %[[VAL_9:.*]] = fir.alloca f64 {bindc_name = "sum", uniq_name = "_QFsum1dEsum"}
614 // CHECK: %[[VAL_10:.*]] = fir.declare %[[VAL_9]] {uniq_name = "_QFsum1dEsum"} : (!fir.ref<f64>) -> !fir.ref<f64>
615 // CHECK: fir.store %[[VAL_3]] to %[[VAL_10]] : !fir.ref<f64>
616 // CHECK: %[[VAL_11:.*]] = fir.load %[[VAL_8]] : !fir.ref<i32>
617 // CHECK: %[[VAL_12:.*]] = fir.convert %[[VAL_11]] : (i32) -> index
618 // CHECK: %[[VAL_13:.*]] = fir.convert %[[VAL_2]] : (index) -> i32
619 // CHECK: %[[VAL_14:.*]] = arith.constant 0 : index
620 // CHECK: %[[VAL_15:.*]]:3 = fir.box_dims %[[VAL_5]], %[[VAL_14]] : (!fir.box<!fir.array<?xf64>>, index) -> (index, index, index)
621 // CHECK: %[[VAL_16:.*]] = arith.constant 8 : index
622 // CHECK: %[[VAL_17:.*]] = arith.cmpi eq, %[[VAL_15]]#2, %[[VAL_16]] : index
623 // CHECK: %[[VAL_18:.*]]:2 = fir.if %[[VAL_17]] -> (index, i32) {
624 // CHECK: %[[VAL_19:.*]] = fir.convert %[[VAL_5]] : (!fir.box<!fir.array<?xf64>>) -> !fir.box<!fir.array<?xf64>>
625 // CHECK: %[[VAL_20:.*]] = fir.box_addr %[[VAL_19]] : (!fir.box<!fir.array<?xf64>>) -> !fir.ref<!fir.array<?xf64>>
626 // CHECK: %[[VAL_21:.*]]:2 = fir.do_loop %[[VAL_22:.*]] = %[[VAL_2]] to %[[VAL_12]] step %[[VAL_2]] iter_args(%[[VAL_23:.*]] = %[[VAL_13]]) -> (index, i32) {
627 // CHECK: fir.store %[[VAL_23]] to %[[VAL_7]] : !fir.ref<i32>
628 // CHECK: %[[VAL_24:.*]] = fir.load %[[VAL_10]] : !fir.ref<f64>
629 // CHECK: %[[VAL_25:.*]] = fir.load %[[VAL_7]] : !fir.ref<i32>
630 // CHECK: %[[VAL_26:.*]] = fir.convert %[[VAL_25]] : (i32) -> i64
631 // CHECK: %[[VAL_27:.*]] = arith.constant 1 : i64
632 // CHECK: %[[VAL_28:.*]] = arith.subi %[[VAL_26]], %[[VAL_27]] : i64
633 // CHECK: %[[VAL_29:.*]] = fir.convert %[[VAL_28]] : (i64) -> index
634 // CHECK: %[[VAL_30:.*]] = fir.coordinate_of %[[VAL_20]], %[[VAL_29]] : (!fir.ref<!fir.array<?xf64>>, index) -> !fir.ref<f64>
635 // CHECK: %[[VAL_31:.*]] = fir.load %[[VAL_30]] : !fir.ref<f64>
636 // CHECK: %[[VAL_32:.*]] = arith.addf %[[VAL_24]], %[[VAL_31]] fastmath<contract> : f64
637 // CHECK: fir.store %[[VAL_32]] to %[[VAL_10]] : !fir.ref<f64>
638 // CHECK: %[[VAL_33:.*]] = arith.addi %[[VAL_22]], %[[VAL_2]] : index
639 // CHECK: %[[VAL_34:.*]] = fir.load %[[VAL_7]] : !fir.ref<i32>
640 // CHECK: %[[VAL_35:.*]] = arith.addi %[[VAL_34]], %[[VAL_13]] : i32
641 // CHECK: fir.result %[[VAL_33]], %[[VAL_35]] : index, i32
643 // CHECK: fir.result %[[VAL_36:.*]]#0, %[[VAL_36]]#1 : index, i32
645 // CHECK: %[[VAL_37:.*]]:2 = fir.do_loop %[[VAL_38:.*]] = %[[VAL_2]] to %[[VAL_12]] step %[[VAL_2]] iter_args(%[[VAL_39:.*]] = %[[VAL_13]]) -> (index, i32) {
646 // CHECK: fir.store %[[VAL_39]] to %[[VAL_7]] : !fir.ref<i32>
647 // CHECK: %[[VAL_40:.*]] = fir.load %[[VAL_10]] : !fir.ref<f64>
648 // CHECK: %[[VAL_41:.*]] = fir.load %[[VAL_7]] : !fir.ref<i32>
649 // CHECK: %[[VAL_42:.*]] = fir.convert %[[VAL_41]] : (i32) -> i64
650 // CHECK: %[[VAL_43:.*]] = fir.array_coor %[[VAL_5]] %[[VAL_42]] : (!fir.box<!fir.array<?xf64>>, i64) -> !fir.ref<f64>
651 // CHECK: %[[VAL_44:.*]] = fir.load %[[VAL_43]] : !fir.ref<f64>
652 // CHECK: %[[VAL_45:.*]] = arith.addf %[[VAL_40]], %[[VAL_44]] fastmath<contract> : f64
653 // CHECK: fir.store %[[VAL_45]] to %[[VAL_10]] : !fir.ref<f64>
654 // CHECK: %[[VAL_46:.*]] = arith.addi %[[VAL_38]], %[[VAL_2]] : index
655 // CHECK: %[[VAL_47:.*]] = fir.load %[[VAL_7]] : !fir.ref<i32>
656 // CHECK: %[[VAL_48:.*]] = arith.addi %[[VAL_47]], %[[VAL_13]] : i32
657 // CHECK: fir.result %[[VAL_46]], %[[VAL_48]] : index, i32
659 // CHECK: fir.result %[[VAL_49:.*]]#0, %[[VAL_49]]#1 : index, i32
661 // CHECK: fir.store %[[VAL_50:.*]]#1 to %[[VAL_7]] : !fir.ref<i32>
665 // test sum2d with hlfir lowering
666 func.func @_QPsum2d(%arg0: !fir.box<!fir.array<?x?xf64>> {fir.bindc_name = "a"}, %arg1: !fir.ref<i32> {fir.bindc_name = "nx"}, %arg2: !fir.ref<i32> {fir.bindc_name = "ny"}) {
667 %c1 = arith.constant 1 : index
668 %cst = arith.constant 0.000000e+00 : f64
669 %0 = fir.declare %arg0 {uniq_name = "_QFsum2dEa"} : (!fir.box<!fir.array<?x?xf64>>) -> !fir.box<!fir.array<?x?xf64>>
670 %1 = fir.rebox %0 : (!fir.box<!fir.array<?x?xf64>>) -> !fir.box<!fir.array<?x?xf64>>
671 %2 = fir.alloca i32 {bindc_name = "i", uniq_name = "_QFsum2dEi"}
672 %3 = fir.declare %2 {uniq_name = "_QFsum2dEi"} : (!fir.ref<i32>) -> !fir.ref<i32>
673 %4 = fir.alloca i32 {bindc_name = "j", uniq_name = "_QFsum2dEj"}
674 %5 = fir.declare %4 {uniq_name = "_QFsum2dEj"} : (!fir.ref<i32>) -> !fir.ref<i32>
675 %6 = fir.declare %arg1 {uniq_name = "_QFsum2dEnx"} : (!fir.ref<i32>) -> !fir.ref<i32>
676 %7 = fir.declare %arg2 {uniq_name = "_QFsum2dEny"} : (!fir.ref<i32>) -> !fir.ref<i32>
677 %8 = fir.alloca f64 {bindc_name = "sum", uniq_name = "_QFsum2dEsum"}
678 %9 = fir.declare %8 {uniq_name = "_QFsum2dEsum"} : (!fir.ref<f64>) -> !fir.ref<f64>
679 fir.store %cst to %9 : !fir.ref<f64>
680 %10 = fir.load %6 : !fir.ref<i32>
681 %11 = fir.convert %10 : (i32) -> index
682 %12 = fir.convert %c1 : (index) -> i32
683 %13:2 = fir.do_loop %arg3 = %c1 to %11 step %c1 iter_args(%arg4 = %12) -> (index, i32) {
684 fir.store %arg4 to %3 : !fir.ref<i32>
685 %14 = fir.load %7 : !fir.ref<i32>
686 %15 = fir.convert %14 : (i32) -> index
687 %16:2 = fir.do_loop %arg5 = %c1 to %15 step %c1 iter_args(%arg6 = %12) -> (index, i32) {
688 fir.store %arg6 to %5 : !fir.ref<i32>
689 %20 = fir.load %9 : !fir.ref<f64>
690 %21 = fir.load %5 : !fir.ref<i32>
691 %22 = fir.convert %21 : (i32) -> i64
692 %23 = fir.load %3 : !fir.ref<i32>
693 %24 = fir.convert %23 : (i32) -> i64
694 %25 = fir.array_coor %1 %22, %24 : (!fir.box<!fir.array<?x?xf64>>, i64, i64) -> !fir.ref<f64>
695 %26 = fir.load %25 : !fir.ref<f64>
696 %27 = arith.addf %20, %26 fastmath<contract> : f64
697 fir.store %27 to %9 : !fir.ref<f64>
698 %28 = arith.addi %arg5, %c1 : index
699 %29 = fir.load %5 : !fir.ref<i32>
700 %30 = arith.addi %29, %12 : i32
701 fir.result %28, %30 : index, i32
703 fir.store %16#1 to %5 : !fir.ref<i32>
704 %17 = arith.addi %arg3, %c1 : index
705 %18 = fir.load %3 : !fir.ref<i32>
706 %19 = arith.addi %18, %12 : i32
707 fir.result %17, %19 : index, i32
709 fir.store %13#1 to %3 : !fir.ref<i32>
712 // CHECK-LABEL: func.func @_QPsum2d(
713 // CHECK-SAME: %[[VAL_0:.*]]: !fir.box<!fir.array<?x?xf64>> {fir.bindc_name = "a"},
714 // CHECK-SAME: %[[VAL_1:.*]]: !fir.ref<i32> {fir.bindc_name = "nx"},
715 // CHECK-SAME: %[[VAL_2:.*]]: !fir.ref<i32> {fir.bindc_name = "ny"}) {
716 // CHECK: %[[VAL_3:.*]] = arith.constant 1 : index
717 // CHECK: %[[VAL_4:.*]] = arith.constant 0.000000e+00 : f64
718 // CHECK: %[[VAL_5:.*]] = fir.declare %[[VAL_0]] {uniq_name = "_QFsum2dEa"} : (!fir.box<!fir.array<?x?xf64>>) -> !fir.box<!fir.array<?x?xf64>>
719 // CHECK: %[[VAL_6:.*]] = fir.rebox %[[VAL_5]] : (!fir.box<!fir.array<?x?xf64>>) -> !fir.box<!fir.array<?x?xf64>>
720 // CHECK: %[[VAL_7:.*]] = fir.alloca i32 {bindc_name = "i", uniq_name = "_QFsum2dEi"}
721 // CHECK: %[[VAL_8:.*]] = fir.declare %[[VAL_7]] {uniq_name = "_QFsum2dEi"} : (!fir.ref<i32>) -> !fir.ref<i32>
722 // CHECK: %[[VAL_9:.*]] = fir.alloca i32 {bindc_name = "j", uniq_name = "_QFsum2dEj"}
723 // CHECK: %[[VAL_10:.*]] = fir.declare %[[VAL_9]] {uniq_name = "_QFsum2dEj"} : (!fir.ref<i32>) -> !fir.ref<i32>
724 // CHECK: %[[VAL_11:.*]] = fir.declare %[[VAL_1]] {uniq_name = "_QFsum2dEnx"} : (!fir.ref<i32>) -> !fir.ref<i32>
725 // CHECK: %[[VAL_12:.*]] = fir.declare %[[VAL_2]] {uniq_name = "_QFsum2dEny"} : (!fir.ref<i32>) -> !fir.ref<i32>
726 // CHECK: %[[VAL_13:.*]] = fir.alloca f64 {bindc_name = "sum", uniq_name = "_QFsum2dEsum"}
727 // CHECK: %[[VAL_14:.*]] = fir.declare %[[VAL_13]] {uniq_name = "_QFsum2dEsum"} : (!fir.ref<f64>) -> !fir.ref<f64>
728 // CHECK: fir.store %[[VAL_4]] to %[[VAL_14]] : !fir.ref<f64>
729 // CHECK: %[[VAL_15:.*]] = fir.load %[[VAL_11]] : !fir.ref<i32>
730 // CHECK: %[[VAL_16:.*]] = fir.convert %[[VAL_15]] : (i32) -> index
731 // CHECK: %[[VAL_17:.*]] = fir.convert %[[VAL_3]] : (index) -> i32
732 // CHECK: %[[VAL_18:.*]]:2 = fir.do_loop %[[VAL_19:.*]] = %[[VAL_3]] to %[[VAL_16]] step %[[VAL_3]] iter_args(%[[VAL_20:.*]] = %[[VAL_17]]) -> (index, i32) {
733 // CHECK: fir.store %[[VAL_20]] to %[[VAL_8]] : !fir.ref<i32>
734 // CHECK: %[[VAL_21:.*]] = fir.load %[[VAL_12]] : !fir.ref<i32>
735 // CHECK: %[[VAL_22:.*]] = fir.convert %[[VAL_21]] : (i32) -> index
736 // CHECK: %[[VAL_23:.*]] = arith.constant 0 : index
737 // CHECK: %[[VAL_24:.*]]:3 = fir.box_dims %[[VAL_6]], %[[VAL_23]] : (!fir.box<!fir.array<?x?xf64>>, index) -> (index, index, index)
738 // CHECK: %[[VAL_25:.*]] = arith.constant 1 : index
739 // CHECK: %[[VAL_26:.*]]:3 = fir.box_dims %[[VAL_6]], %[[VAL_25]] : (!fir.box<!fir.array<?x?xf64>>, index) -> (index, index, index)
740 // CHECK: %[[VAL_27:.*]] = arith.constant 8 : index
741 // CHECK: %[[VAL_28:.*]] = arith.cmpi eq, %[[VAL_24]]#2, %[[VAL_27]] : index
742 // CHECK: %[[VAL_29:.*]]:2 = fir.if %[[VAL_28]] -> (index, i32) {
743 // CHECK: %[[VAL_30:.*]] = fir.convert %[[VAL_6]] : (!fir.box<!fir.array<?x?xf64>>) -> !fir.box<!fir.array<?xf64>>
744 // CHECK: %[[VAL_31:.*]] = fir.box_addr %[[VAL_30]] : (!fir.box<!fir.array<?xf64>>) -> !fir.ref<!fir.array<?xf64>>
745 // CHECK: %[[VAL_32:.*]]:2 = fir.do_loop %[[VAL_33:.*]] = %[[VAL_3]] to %[[VAL_22]] step %[[VAL_3]] iter_args(%[[VAL_34:.*]] = %[[VAL_17]]) -> (index, i32) {
746 // CHECK: fir.store %[[VAL_34]] to %[[VAL_10]] : !fir.ref<i32>
747 // CHECK: %[[VAL_35:.*]] = fir.load %[[VAL_14]] : !fir.ref<f64>
748 // CHECK: %[[VAL_36:.*]] = fir.load %[[VAL_10]] : !fir.ref<i32>
749 // CHECK: %[[VAL_37:.*]] = fir.convert %[[VAL_36]] : (i32) -> i64
750 // CHECK: %[[VAL_38:.*]] = fir.load %[[VAL_8]] : !fir.ref<i32>
751 // CHECK: %[[VAL_39:.*]] = fir.convert %[[VAL_38]] : (i32) -> i64
752 // CHECK: %[[VAL_40:.*]] = arith.constant 1 : i64
753 // CHECK: %[[VAL_41:.*]] = arith.subi %[[VAL_39]], %[[VAL_40]] : i64
754 // CHECK: %[[VAL_42:.*]] = fir.convert %[[VAL_41]] : (i64) -> index
755 // CHECK: %[[VAL_43:.*]] = arith.muli %[[VAL_26]]#2, %[[VAL_42]] : index
756 // CHECK: %[[VAL_44:.*]] = arith.constant 1 : i64
757 // CHECK: %[[VAL_45:.*]] = arith.subi %[[VAL_37]], %[[VAL_44]] : i64
758 // CHECK: %[[VAL_46:.*]] = fir.convert %[[VAL_45]] : (i64) -> index
759 // CHECK: %[[VAL_47:.*]] = arith.constant 3 : index
760 // CHECK: %[[VAL_48:.*]] = arith.shrsi %[[VAL_43]], %[[VAL_47]] : index
761 // CHECK: %[[VAL_49:.*]] = arith.addi %[[VAL_48]], %[[VAL_46]] : index
762 // CHECK: %[[VAL_50:.*]] = fir.coordinate_of %[[VAL_31]], %[[VAL_49]] : (!fir.ref<!fir.array<?xf64>>, index) -> !fir.ref<f64>
763 // CHECK: %[[VAL_51:.*]] = fir.load %[[VAL_50]] : !fir.ref<f64>
764 // CHECK: %[[VAL_52:.*]] = arith.addf %[[VAL_35]], %[[VAL_51]] fastmath<contract> : f64
765 // CHECK: fir.store %[[VAL_52]] to %[[VAL_14]] : !fir.ref<f64>
766 // CHECK: %[[VAL_53:.*]] = arith.addi %[[VAL_33]], %[[VAL_3]] : index
767 // CHECK: %[[VAL_54:.*]] = fir.load %[[VAL_10]] : !fir.ref<i32>
768 // CHECK: %[[VAL_55:.*]] = arith.addi %[[VAL_54]], %[[VAL_17]] : i32
769 // CHECK: fir.result %[[VAL_53]], %[[VAL_55]] : index, i32
771 // CHECK: fir.result %[[VAL_56:.*]]#0, %[[VAL_56]]#1 : index, i32
773 // CHECK: %[[VAL_57:.*]]:2 = fir.do_loop %[[VAL_58:.*]] = %[[VAL_3]] to %[[VAL_22]] step %[[VAL_3]] iter_args(%[[VAL_59:.*]] = %[[VAL_17]]) -> (index, i32) {
774 // CHECK: fir.store %[[VAL_59]] to %[[VAL_10]] : !fir.ref<i32>
775 // CHECK: %[[VAL_60:.*]] = fir.load %[[VAL_14]] : !fir.ref<f64>
776 // CHECK: %[[VAL_61:.*]] = fir.load %[[VAL_10]] : !fir.ref<i32>
777 // CHECK: %[[VAL_62:.*]] = fir.convert %[[VAL_61]] : (i32) -> i64
778 // CHECK: %[[VAL_63:.*]] = fir.load %[[VAL_8]] : !fir.ref<i32>
779 // CHECK: %[[VAL_64:.*]] = fir.convert %[[VAL_63]] : (i32) -> i64
780 // CHECK: %[[VAL_65:.*]] = fir.array_coor %[[VAL_6]] %[[VAL_62]], %[[VAL_64]] : (!fir.box<!fir.array<?x?xf64>>, i64, i64) -> !fir.ref<f64>
781 // CHECK: %[[VAL_66:.*]] = fir.load %[[VAL_65]] : !fir.ref<f64>
782 // CHECK: %[[VAL_67:.*]] = arith.addf %[[VAL_60]], %[[VAL_66]] fastmath<contract> : f64
783 // CHECK: fir.store %[[VAL_67]] to %[[VAL_14]] : !fir.ref<f64>
784 // CHECK: %[[VAL_68:.*]] = arith.addi %[[VAL_58]], %[[VAL_3]] : index
785 // CHECK: %[[VAL_69:.*]] = fir.load %[[VAL_10]] : !fir.ref<i32>
786 // CHECK: %[[VAL_70:.*]] = arith.addi %[[VAL_69]], %[[VAL_17]] : i32
787 // CHECK: fir.result %[[VAL_68]], %[[VAL_70]] : index, i32
789 // CHECK: fir.result %[[VAL_71:.*]]#0, %[[VAL_71]]#1 : index, i32
791 // CHECK: fir.store %[[VAL_72:.*]]#1 to %[[VAL_10]] : !fir.ref<i32>
792 // CHECK: %[[VAL_73:.*]] = arith.addi %[[VAL_19]], %[[VAL_3]] : index
793 // CHECK: %[[VAL_74:.*]] = fir.load %[[VAL_8]] : !fir.ref<i32>
794 // CHECK: %[[VAL_75:.*]] = arith.addi %[[VAL_74]], %[[VAL_17]] : i32
795 // CHECK: fir.result %[[VAL_73]], %[[VAL_75]] : index, i32
797 // CHECK: fir.store %[[VAL_76:.*]]#1 to %[[VAL_8]] : !fir.ref<i32>
801 // test sum3d with hlfir lowering
802 func.func @_QPsum3d(%arg0: !fir.box<!fir.array<?x?x?xf64>> {fir.bindc_name = "a"}, %arg1: !fir.ref<i32> {fir.bindc_name = "nx"}, %arg2: !fir.ref<i32> {fir.bindc_name = "ny"}, %arg3: !fir.ref<i32> {fir.bindc_name = "nz"}) {
803 %c0 = arith.constant 0 : index
804 %c1 = arith.constant 1 : index
805 %cst = arith.constant 0.000000e+00 : f64
806 %0 = fir.declare %arg0 {uniq_name = "_QFsum3dEa"} : (!fir.box<!fir.array<?x?x?xf64>>) -> !fir.box<!fir.array<?x?x?xf64>>
807 %1 = fir.rebox %0 : (!fir.box<!fir.array<?x?x?xf64>>) -> !fir.box<!fir.array<?x?x?xf64>>
808 %2 = fir.alloca i32 {bindc_name = "i", uniq_name = "_QFsum3dEi"}
809 %3 = fir.declare %2 {uniq_name = "_QFsum3dEi"} : (!fir.ref<i32>) -> !fir.ref<i32>
810 %4 = fir.alloca i32 {bindc_name = "j", uniq_name = "_QFsum3dEj"}
811 %5 = fir.declare %4 {uniq_name = "_QFsum3dEj"} : (!fir.ref<i32>) -> !fir.ref<i32>
812 %6 = fir.alloca i32 {bindc_name = "k", uniq_name = "_QFsum3dEk"}
813 %7 = fir.declare %6 {uniq_name = "_QFsum3dEk"} : (!fir.ref<i32>) -> !fir.ref<i32>
814 %8 = fir.declare %arg1 {uniq_name = "_QFsum3dEnx"} : (!fir.ref<i32>) -> !fir.ref<i32>
815 %9 = fir.declare %arg2 {uniq_name = "_QFsum3dEny"} : (!fir.ref<i32>) -> !fir.ref<i32>
816 %10 = fir.declare %arg3 {uniq_name = "_QFsum3dEnz"} : (!fir.ref<i32>) -> !fir.ref<i32>
817 %11 = fir.alloca f64 {bindc_name = "sum", uniq_name = "_QFsum3dEsum"}
818 %12 = fir.declare %11 {uniq_name = "_QFsum3dEsum"} : (!fir.ref<f64>) -> !fir.ref<f64>
819 fir.store %cst to %12 : !fir.ref<f64>
820 %13 = fir.load %10 : !fir.ref<i32>
821 %14 = fir.convert %13 : (i32) -> index
822 %15 = fir.convert %c1 : (index) -> i32
823 %16:2 = fir.do_loop %arg4 = %c1 to %14 step %c1 iter_args(%arg5 = %15) -> (index, i32) {
824 fir.store %arg5 to %7 : !fir.ref<i32>
825 %17 = fir.load %9 : !fir.ref<i32>
826 %18 = fir.convert %17 : (i32) -> index
827 %19:2 = fir.do_loop %arg6 = %c1 to %18 step %c1 iter_args(%arg7 = %15) -> (index, i32) {
828 fir.store %arg7 to %5 : !fir.ref<i32>
829 %23 = fir.load %8 : !fir.ref<i32>
830 %24 = fir.convert %23 : (i32) -> index
831 %25 = fir.convert %c0 : (index) -> i32
832 %26:2 = fir.do_loop %arg8 = %c0 to %24 step %c1 iter_args(%arg9 = %25) -> (index, i32) {
833 fir.store %arg9 to %3 : !fir.ref<i32>
834 %30 = fir.load %12 : !fir.ref<f64>
835 %31 = fir.load %3 : !fir.ref<i32>
836 %32 = fir.convert %31 : (i32) -> i64
837 %33 = fir.load %5 : !fir.ref<i32>
838 %34 = fir.convert %33 : (i32) -> i64
839 %35 = fir.load %7 : !fir.ref<i32>
840 %36 = fir.convert %35 : (i32) -> i64
841 %37 = fir.array_coor %1 %32, %34, %36 : (!fir.box<!fir.array<?x?x?xf64>>, i64, i64, i64) -> !fir.ref<f64>
842 %38 = fir.load %37 : !fir.ref<f64>
843 %39 = arith.addf %30, %38 fastmath<contract> : f64
844 fir.store %39 to %12 : !fir.ref<f64>
845 %40 = arith.addi %arg8, %c1 : index
846 %41 = fir.load %3 : !fir.ref<i32>
847 %42 = arith.addi %41, %15 : i32
848 fir.result %40, %42 : index, i32
850 fir.store %26#1 to %3 : !fir.ref<i32>
851 %27 = arith.addi %arg6, %c1 : index
852 %28 = fir.load %5 : !fir.ref<i32>
853 %29 = arith.addi %28, %15 : i32
854 fir.result %27, %29 : index, i32
856 fir.store %19#1 to %5 : !fir.ref<i32>
857 %20 = arith.addi %arg4, %c1 : index
858 %21 = fir.load %7 : !fir.ref<i32>
859 %22 = arith.addi %21, %15 : i32
860 fir.result %20, %22 : index, i32
862 fir.store %16#1 to %7 : !fir.ref<i32>
865 // CHECK-LABEL: func.func @_QPsum3d(
866 // CHECK-SAME: %[[VAL_0:.*]]: !fir.box<!fir.array<?x?x?xf64>> {fir.bindc_name = "a"},
867 // CHECK-SAME: %[[VAL_1:.*]]: !fir.ref<i32> {fir.bindc_name = "nx"},
868 // CHECK-SAME: %[[VAL_2:.*]]: !fir.ref<i32> {fir.bindc_name = "ny"},
869 // CHECK-SAME: %[[VAL_3:.*]]: !fir.ref<i32> {fir.bindc_name = "nz"}) {
870 // CHECK: %[[VAL_4:.*]] = arith.constant 0 : index
871 // CHECK: %[[VAL_5:.*]] = arith.constant 1 : index
872 // CHECK: %[[VAL_6:.*]] = arith.constant 0.000000e+00 : f64
873 // CHECK: %[[VAL_7:.*]] = fir.declare %[[VAL_0]] {uniq_name = "_QFsum3dEa"} : (!fir.box<!fir.array<?x?x?xf64>>) -> !fir.box<!fir.array<?x?x?xf64>>
874 // CHECK: %[[VAL_8:.*]] = fir.rebox %[[VAL_7]] : (!fir.box<!fir.array<?x?x?xf64>>) -> !fir.box<!fir.array<?x?x?xf64>>
875 // CHECK: %[[VAL_9:.*]] = fir.alloca i32 {bindc_name = "i", uniq_name = "_QFsum3dEi"}
876 // CHECK: %[[VAL_10:.*]] = fir.declare %[[VAL_9]] {uniq_name = "_QFsum3dEi"} : (!fir.ref<i32>) -> !fir.ref<i32>
877 // CHECK: %[[VAL_11:.*]] = fir.alloca i32 {bindc_name = "j", uniq_name = "_QFsum3dEj"}
878 // CHECK: %[[VAL_12:.*]] = fir.declare %[[VAL_11]] {uniq_name = "_QFsum3dEj"} : (!fir.ref<i32>) -> !fir.ref<i32>
879 // CHECK: %[[VAL_13:.*]] = fir.alloca i32 {bindc_name = "k", uniq_name = "_QFsum3dEk"}
880 // CHECK: %[[VAL_14:.*]] = fir.declare %[[VAL_13]] {uniq_name = "_QFsum3dEk"} : (!fir.ref<i32>) -> !fir.ref<i32>
881 // CHECK: %[[VAL_15:.*]] = fir.declare %[[VAL_1]] {uniq_name = "_QFsum3dEnx"} : (!fir.ref<i32>) -> !fir.ref<i32>
882 // CHECK: %[[VAL_16:.*]] = fir.declare %[[VAL_2]] {uniq_name = "_QFsum3dEny"} : (!fir.ref<i32>) -> !fir.ref<i32>
883 // CHECK: %[[VAL_17:.*]] = fir.declare %[[VAL_3]] {uniq_name = "_QFsum3dEnz"} : (!fir.ref<i32>) -> !fir.ref<i32>
884 // CHECK: %[[VAL_18:.*]] = fir.alloca f64 {bindc_name = "sum", uniq_name = "_QFsum3dEsum"}
885 // CHECK: %[[VAL_19:.*]] = fir.declare %[[VAL_18]] {uniq_name = "_QFsum3dEsum"} : (!fir.ref<f64>) -> !fir.ref<f64>
886 // CHECK: fir.store %[[VAL_6]] to %[[VAL_19]] : !fir.ref<f64>
887 // CHECK: %[[VAL_20:.*]] = fir.load %[[VAL_17]] : !fir.ref<i32>
888 // CHECK: %[[VAL_21:.*]] = fir.convert %[[VAL_20]] : (i32) -> index
889 // CHECK: %[[VAL_22:.*]] = fir.convert %[[VAL_5]] : (index) -> i32
890 // CHECK: %[[VAL_23:.*]]:2 = fir.do_loop %[[VAL_24:.*]] = %[[VAL_5]] to %[[VAL_21]] step %[[VAL_5]] iter_args(%[[VAL_25:.*]] = %[[VAL_22]]) -> (index, i32) {
891 // CHECK: fir.store %[[VAL_25]] to %[[VAL_14]] : !fir.ref<i32>
892 // CHECK: %[[VAL_26:.*]] = fir.load %[[VAL_16]] : !fir.ref<i32>
893 // CHECK: %[[VAL_27:.*]] = fir.convert %[[VAL_26]] : (i32) -> index
894 // CHECK: %[[VAL_28:.*]]:2 = fir.do_loop %[[VAL_29:.*]] = %[[VAL_5]] to %[[VAL_27]] step %[[VAL_5]] iter_args(%[[VAL_30:.*]] = %[[VAL_22]]) -> (index, i32) {
895 // CHECK: fir.store %[[VAL_30]] to %[[VAL_12]] : !fir.ref<i32>
896 // CHECK: %[[VAL_31:.*]] = fir.load %[[VAL_15]] : !fir.ref<i32>
897 // CHECK: %[[VAL_32:.*]] = fir.convert %[[VAL_31]] : (i32) -> index
898 // CHECK: %[[VAL_33:.*]] = fir.convert %[[VAL_4]] : (index) -> i32
899 // CHECK: %[[VAL_34:.*]] = arith.constant 0 : index
900 // CHECK: %[[VAL_35:.*]]:3 = fir.box_dims %[[VAL_8]], %[[VAL_34]] : (!fir.box<!fir.array<?x?x?xf64>>, index) -> (index, index, index)
901 // CHECK: %[[VAL_36:.*]] = arith.constant 1 : index
902 // CHECK: %[[VAL_37:.*]]:3 = fir.box_dims %[[VAL_8]], %[[VAL_36]] : (!fir.box<!fir.array<?x?x?xf64>>, index) -> (index, index, index)
903 // CHECK: %[[VAL_38:.*]] = arith.constant 2 : index
904 // CHECK: %[[VAL_39:.*]]:3 = fir.box_dims %[[VAL_8]], %[[VAL_38]] : (!fir.box<!fir.array<?x?x?xf64>>, index) -> (index, index, index)
905 // CHECK: %[[VAL_40:.*]] = arith.constant 8 : index
906 // CHECK: %[[VAL_41:.*]] = arith.cmpi eq, %[[VAL_35]]#2, %[[VAL_40]] : index
907 // CHECK: %[[VAL_42:.*]]:2 = fir.if %[[VAL_41]] -> (index, i32) {
908 // CHECK: %[[VAL_43:.*]] = fir.convert %[[VAL_8]] : (!fir.box<!fir.array<?x?x?xf64>>) -> !fir.box<!fir.array<?xf64>>
909 // CHECK: %[[VAL_44:.*]] = fir.box_addr %[[VAL_43]] : (!fir.box<!fir.array<?xf64>>) -> !fir.ref<!fir.array<?xf64>>
910 // CHECK: %[[VAL_45:.*]]:2 = fir.do_loop %[[VAL_46:.*]] = %[[VAL_4]] to %[[VAL_32]] step %[[VAL_5]] iter_args(%[[VAL_47:.*]] = %[[VAL_33]]) -> (index, i32) {
911 // CHECK: fir.store %[[VAL_47]] to %[[VAL_10]] : !fir.ref<i32>
912 // CHECK: %[[VAL_48:.*]] = fir.load %[[VAL_19]] : !fir.ref<f64>
913 // CHECK: %[[VAL_49:.*]] = fir.load %[[VAL_10]] : !fir.ref<i32>
914 // CHECK: %[[VAL_50:.*]] = fir.convert %[[VAL_49]] : (i32) -> i64
915 // CHECK: %[[VAL_51:.*]] = fir.load %[[VAL_12]] : !fir.ref<i32>
916 // CHECK: %[[VAL_52:.*]] = fir.convert %[[VAL_51]] : (i32) -> i64
917 // CHECK: %[[VAL_53:.*]] = fir.load %[[VAL_14]] : !fir.ref<i32>
918 // CHECK: %[[VAL_54:.*]] = fir.convert %[[VAL_53]] : (i32) -> i64
919 // CHECK: %[[VAL_55:.*]] = arith.constant 1 : i64
920 // CHECK: %[[VAL_56:.*]] = arith.subi %[[VAL_54]], %[[VAL_55]] : i64
921 // CHECK: %[[VAL_57:.*]] = fir.convert %[[VAL_56]] : (i64) -> index
922 // CHECK: %[[VAL_58:.*]] = arith.muli %[[VAL_39]]#2, %[[VAL_57]] : index
923 // CHECK: %[[VAL_59:.*]] = arith.constant 1 : i64
924 // CHECK: %[[VAL_60:.*]] = arith.subi %[[VAL_52]], %[[VAL_59]] : i64
925 // CHECK: %[[VAL_61:.*]] = fir.convert %[[VAL_60]] : (i64) -> index
926 // CHECK: %[[VAL_62:.*]] = arith.muli %[[VAL_37]]#2, %[[VAL_61]] : index
927 // CHECK: %[[VAL_63:.*]] = arith.addi %[[VAL_62]], %[[VAL_58]] : index
928 // CHECK: %[[VAL_64:.*]] = arith.constant 1 : i64
929 // CHECK: %[[VAL_65:.*]] = arith.subi %[[VAL_50]], %[[VAL_64]] : i64
930 // CHECK: %[[VAL_66:.*]] = fir.convert %[[VAL_65]] : (i64) -> index
931 // CHECK: %[[VAL_67:.*]] = arith.constant 3 : index
932 // CHECK: %[[VAL_68:.*]] = arith.shrsi %[[VAL_63]], %[[VAL_67]] : index
933 // CHECK: %[[VAL_69:.*]] = arith.addi %[[VAL_68]], %[[VAL_66]] : index
934 // CHECK: %[[VAL_70:.*]] = fir.coordinate_of %[[VAL_44]], %[[VAL_69]] : (!fir.ref<!fir.array<?xf64>>, index) -> !fir.ref<f64>
935 // CHECK: %[[VAL_71:.*]] = fir.load %[[VAL_70]] : !fir.ref<f64>
936 // CHECK: %[[VAL_72:.*]] = arith.addf %[[VAL_48]], %[[VAL_71]] fastmath<contract> : f64
937 // CHECK: fir.store %[[VAL_72]] to %[[VAL_19]] : !fir.ref<f64>
938 // CHECK: %[[VAL_73:.*]] = arith.addi %[[VAL_46]], %[[VAL_5]] : index
939 // CHECK: %[[VAL_74:.*]] = fir.load %[[VAL_10]] : !fir.ref<i32>
940 // CHECK: %[[VAL_75:.*]] = arith.addi %[[VAL_74]], %[[VAL_22]] : i32
941 // CHECK: fir.result %[[VAL_73]], %[[VAL_75]] : index, i32
943 // CHECK: fir.result %[[VAL_76:.*]]#0, %[[VAL_76]]#1 : index, i32
945 // CHECK: %[[VAL_77:.*]]:2 = fir.do_loop %[[VAL_78:.*]] = %[[VAL_4]] to %[[VAL_32]] step %[[VAL_5]] iter_args(%[[VAL_79:.*]] = %[[VAL_33]]) -> (index, i32) {
946 // CHECK: fir.store %[[VAL_79]] to %[[VAL_10]] : !fir.ref<i32>
947 // CHECK: %[[VAL_80:.*]] = fir.load %[[VAL_19]] : !fir.ref<f64>
948 // CHECK: %[[VAL_81:.*]] = fir.load %[[VAL_10]] : !fir.ref<i32>
949 // CHECK: %[[VAL_82:.*]] = fir.convert %[[VAL_81]] : (i32) -> i64
950 // CHECK: %[[VAL_83:.*]] = fir.load %[[VAL_12]] : !fir.ref<i32>
951 // CHECK: %[[VAL_84:.*]] = fir.convert %[[VAL_83]] : (i32) -> i64
952 // CHECK: %[[VAL_85:.*]] = fir.load %[[VAL_14]] : !fir.ref<i32>
953 // CHECK: %[[VAL_86:.*]] = fir.convert %[[VAL_85]] : (i32) -> i64
954 // CHECK: %[[VAL_87:.*]] = fir.array_coor %[[VAL_8]] %[[VAL_82]], %[[VAL_84]], %[[VAL_86]] : (!fir.box<!fir.array<?x?x?xf64>>, i64, i64, i64) -> !fir.ref<f64>
955 // CHECK: %[[VAL_88:.*]] = fir.load %[[VAL_87]] : !fir.ref<f64>
956 // CHECK: %[[VAL_89:.*]] = arith.addf %[[VAL_80]], %[[VAL_88]] fastmath<contract> : f64
957 // CHECK: fir.store %[[VAL_89]] to %[[VAL_19]] : !fir.ref<f64>
958 // CHECK: %[[VAL_90:.*]] = arith.addi %[[VAL_78]], %[[VAL_5]] : index
959 // CHECK: %[[VAL_91:.*]] = fir.load %[[VAL_10]] : !fir.ref<i32>
960 // CHECK: %[[VAL_92:.*]] = arith.addi %[[VAL_91]], %[[VAL_22]] : i32
961 // CHECK: fir.result %[[VAL_90]], %[[VAL_92]] : index, i32
963 // CHECK: fir.result %[[VAL_93:.*]]#0, %[[VAL_93]]#1 : index, i32
965 // CHECK: fir.store %[[VAL_94:.*]]#1 to %[[VAL_10]] : !fir.ref<i32>
966 // CHECK: %[[VAL_95:.*]] = arith.addi %[[VAL_29]], %[[VAL_5]] : index
967 // CHECK: %[[VAL_96:.*]] = fir.load %[[VAL_12]] : !fir.ref<i32>
968 // CHECK: %[[VAL_97:.*]] = arith.addi %[[VAL_96]], %[[VAL_22]] : i32
969 // CHECK: fir.result %[[VAL_95]], %[[VAL_97]] : index, i32
971 // CHECK: fir.store %[[VAL_98:.*]]#1 to %[[VAL_12]] : !fir.ref<i32>
972 // CHECK: %[[VAL_99:.*]] = arith.addi %[[VAL_24]], %[[VAL_5]] : index
973 // CHECK: %[[VAL_100:.*]] = fir.load %[[VAL_14]] : !fir.ref<i32>
974 // CHECK: %[[VAL_101:.*]] = arith.addi %[[VAL_100]], %[[VAL_22]] : i32
975 // CHECK: fir.result %[[VAL_99]], %[[VAL_101]] : index, i32
977 // CHECK: fir.store %[[VAL_102:.*]]#1 to %[[VAL_14]] : !fir.ref<i32>
981 // test non-default lower bounds are handled correctly
982 func.func @_QPlbounds_repro(%arg0: !fir.box<!fir.array<?x?x?xf32>> {fir.bindc_name = "u"}, %arg1: !fir.ref<i32> {fir.bindc_name = "ims"}, %arg2: !fir.ref<i32> {fir.bindc_name = "jms"}, %arg3: !fir.ref<i32> {fir.bindc_name = "kms"}, %arg4: !fir.ref<i32> {fir.bindc_name = "ips"}, %arg5: !fir.ref<i32> {fir.bindc_name = "ipe"}, %arg6: !fir.ref<i32> {fir.bindc_name = "jps"}, %arg7: !fir.ref<i32> {fir.bindc_name = "jpe"}, %arg8: !fir.ref<i32> {fir.bindc_name = "kps"}, %arg9: !fir.ref<i32> {fir.bindc_name = "kpe"}) {
983 %c1_i32 = arith.constant 1 : i32
984 %c1 = arith.constant 1 : index
985 %0 = fir.alloca i32 {bindc_name = "i", uniq_name = "_QFlbounds_reproEi"}
986 %1 = fir.declare %0 {uniq_name = "_QFlbounds_reproEi"} : (!fir.ref<i32>) -> !fir.ref<i32>
987 %2 = fir.declare %arg1 {fortran_attrs = #fir.var_attrs<intent_in>, uniq_name = "_QFlbounds_reproEims"} : (!fir.ref<i32>) -> !fir.ref<i32>
988 %3 = fir.declare %arg5 {fortran_attrs = #fir.var_attrs<intent_in>, uniq_name = "_QFlbounds_reproEipe"} : (!fir.ref<i32>) -> !fir.ref<i32>
989 %4 = fir.declare %arg4 {fortran_attrs = #fir.var_attrs<intent_in>, uniq_name = "_QFlbounds_reproEips"} : (!fir.ref<i32>) -> !fir.ref<i32>
990 %5 = fir.alloca i32 {bindc_name = "j", uniq_name = "_QFlbounds_reproEj"}
991 %6 = fir.declare %5 {uniq_name = "_QFlbounds_reproEj"} : (!fir.ref<i32>) -> !fir.ref<i32>
992 %7 = fir.declare %arg2 {fortran_attrs = #fir.var_attrs<intent_in>, uniq_name = "_QFlbounds_reproEjms"} : (!fir.ref<i32>) -> !fir.ref<i32>
993 %8 = fir.declare %arg7 {fortran_attrs = #fir.var_attrs<intent_in>, uniq_name = "_QFlbounds_reproEjpe"} : (!fir.ref<i32>) -> !fir.ref<i32>
994 %9 = fir.declare %arg6 {fortran_attrs = #fir.var_attrs<intent_in>, uniq_name = "_QFlbounds_reproEjps"} : (!fir.ref<i32>) -> !fir.ref<i32>
995 %10 = fir.alloca i32 {bindc_name = "k", uniq_name = "_QFlbounds_reproEk"}
996 %11 = fir.declare %10 {uniq_name = "_QFlbounds_reproEk"} : (!fir.ref<i32>) -> !fir.ref<i32>
997 %12 = fir.declare %arg3 {fortran_attrs = #fir.var_attrs<intent_in>, uniq_name = "_QFlbounds_reproEkms"} : (!fir.ref<i32>) -> !fir.ref<i32>
998 %13 = fir.declare %arg9 {fortran_attrs = #fir.var_attrs<intent_in>, uniq_name = "_QFlbounds_reproEkpe"} : (!fir.ref<i32>) -> !fir.ref<i32>
999 %14 = fir.declare %arg8 {fortran_attrs = #fir.var_attrs<intent_in>, uniq_name = "_QFlbounds_reproEkps"} : (!fir.ref<i32>) -> !fir.ref<i32>
1000 %15 = fir.alloca f32 {bindc_name = "vmax", uniq_name = "_QFlbounds_reproEvmax"}
1001 %16 = fir.declare %15 {uniq_name = "_QFlbounds_reproEvmax"} : (!fir.ref<f32>) -> !fir.ref<f32>
1002 %17 = fir.load %12 : !fir.ref<i32>
1003 %18 = fir.convert %17 : (i32) -> index
1004 %19 = fir.load %2 : !fir.ref<i32>
1005 %20 = fir.convert %19 : (i32) -> index
1006 %21 = fir.load %7 : !fir.ref<i32>
1007 %22 = fir.convert %21 : (i32) -> index
1008 %23 = fir.shift %18, %20, %22 : (index, index, index) -> !fir.shift<3>
1009 %24 = fir.declare %arg0(%23) {fortran_attrs = #fir.var_attrs<intent_in>, uniq_name = "_QFlbounds_reproEu"} : (!fir.box<!fir.array<?x?x?xf32>>, !fir.shift<3>) -> !fir.box<!fir.array<?x?x?xf32>>
1010 %25 = fir.rebox %24(%23) : (!fir.box<!fir.array<?x?x?xf32>>, !fir.shift<3>) -> !fir.box<!fir.array<?x?x?xf32>>
1011 %26 = fir.array_coor %25(%23) %c1, %c1, %c1 : (!fir.box<!fir.array<?x?x?xf32>>, !fir.shift<3>, index, index, index) -> !fir.ref<f32>
1012 %27 = fir.load %26 : !fir.ref<f32>
1013 fir.store %27 to %16 : !fir.ref<f32>
1014 %28 = fir.load %9 : !fir.ref<i32>
1015 %29 = fir.convert %28 : (i32) -> index
1016 %30 = fir.load %8 : !fir.ref<i32>
1017 %31 = arith.subi %30, %c1_i32 : i32
1018 %32 = fir.convert %31 : (i32) -> index
1019 %33 = fir.convert %29 : (index) -> i32
1020 %34:2 = fir.do_loop %arg10 = %29 to %32 step %c1 iter_args(%arg11 = %33) -> (index, i32) {
1021 fir.store %arg11 to %6 : !fir.ref<i32>
1022 %35 = fir.load %4 : !fir.ref<i32>
1023 %36 = fir.convert %35 : (i32) -> index
1024 %37 = fir.load %3 : !fir.ref<i32>
1025 %38 = fir.convert %37 : (i32) -> index
1026 %39 = fir.convert %36 : (index) -> i32
1027 %40:2 = fir.do_loop %arg12 = %36 to %38 step %c1 iter_args(%arg13 = %39) -> (index, i32) {
1028 fir.store %arg13 to %1 : !fir.ref<i32>
1029 %45 = fir.load %14 : !fir.ref<i32>
1030 %46 = fir.convert %45 : (i32) -> index
1031 %47 = fir.load %13 : !fir.ref<i32>
1032 %48 = arith.subi %47, %c1_i32 : i32
1033 %49 = fir.convert %48 : (i32) -> index
1034 %50 = fir.convert %46 : (index) -> i32
1035 %51:2 = fir.do_loop %arg14 = %46 to %49 step %c1 iter_args(%arg15 = %50) -> (index, i32) {
1036 fir.store %arg15 to %11 : !fir.ref<i32>
1037 %56 = fir.load %11 : !fir.ref<i32>
1038 %57 = fir.convert %56 : (i32) -> i64
1039 %58 = fir.load %1 : !fir.ref<i32>
1040 %59 = fir.convert %58 : (i32) -> i64
1041 %60 = fir.load %6 : !fir.ref<i32>
1042 %61 = fir.convert %60 : (i32) -> i64
1043 %62 = fir.array_coor %25(%23) %57, %59, %61 : (!fir.box<!fir.array<?x?x?xf32>>, !fir.shift<3>, i64, i64, i64) -> !fir.ref<f32>
1044 %63 = fir.load %62 : !fir.ref<f32>
1045 %64 = fir.load %16 : !fir.ref<f32>
1046 %65 = arith.cmpf ogt, %63, %64 : f32
1048 %70 = fir.load %11 : !fir.ref<i32>
1049 %71 = fir.convert %70 : (i32) -> i64
1050 %72 = fir.load %1 : !fir.ref<i32>
1051 %73 = fir.convert %72 : (i32) -> i64
1052 %74 = fir.load %6 : !fir.ref<i32>
1053 %75 = fir.convert %74 : (i32) -> i64
1054 %76 = fir.array_coor %25(%23) %71, %73, %75 : (!fir.box<!fir.array<?x?x?xf32>>, !fir.shift<3>, i64, i64, i64) -> !fir.ref<f32>
1055 %77 = fir.load %76 : !fir.ref<f32>
1056 fir.store %77 to %16 : !fir.ref<f32>
1059 %66 = arith.addi %arg14, %c1 : index
1060 %67 = fir.convert %c1 : (index) -> i32
1061 %68 = fir.load %11 : !fir.ref<i32>
1062 %69 = arith.addi %68, %67 : i32
1063 fir.result %66, %69 : index, i32
1065 fir.store %51#1 to %11 : !fir.ref<i32>
1066 %52 = arith.addi %arg12, %c1 : index
1067 %53 = fir.convert %c1 : (index) -> i32
1068 %54 = fir.load %1 : !fir.ref<i32>
1069 %55 = arith.addi %54, %53 : i32
1070 fir.result %52, %55 : index, i32
1072 fir.store %40#1 to %1 : !fir.ref<i32>
1073 %41 = arith.addi %arg10, %c1 : index
1074 %42 = fir.convert %c1 : (index) -> i32
1075 %43 = fir.load %6 : !fir.ref<i32>
1076 %44 = arith.addi %43, %42 : i32
1077 fir.result %41, %44 : index, i32
1079 fir.store %34#1 to %6 : !fir.ref<i32>
1082 // CHECK-LABEL: func.func @_QPlbounds_repro(
1083 // CHECK-SAME: %[[VAL_0:.*]]: !fir.box<!fir.array<?x?x?xf32>> {fir.bindc_name = "u"},
1084 // CHECK-SAME: %[[VAL_1:.*]]: !fir.ref<i32> {fir.bindc_name = "ims"},
1085 // CHECK-SAME: %[[VAL_2:.*]]: !fir.ref<i32> {fir.bindc_name = "jms"},
1086 // CHECK-SAME: %[[VAL_3:.*]]: !fir.ref<i32> {fir.bindc_name = "kms"},
1087 // CHECK-SAME: %[[VAL_4:.*]]: !fir.ref<i32> {fir.bindc_name = "ips"},
1088 // CHECK-SAME: %[[VAL_5:.*]]: !fir.ref<i32> {fir.bindc_name = "ipe"},
1089 // CHECK-SAME: %[[VAL_6:.*]]: !fir.ref<i32> {fir.bindc_name = "jps"},
1090 // CHECK-SAME: %[[VAL_7:.*]]: !fir.ref<i32> {fir.bindc_name = "jpe"},
1091 // CHECK-SAME: %[[VAL_8:.*]]: !fir.ref<i32> {fir.bindc_name = "kps"},
1092 // CHECK-SAME: %[[VAL_9:.*]]: !fir.ref<i32> {fir.bindc_name = "kpe"}) {
1093 // CHECK: %[[VAL_10:.*]] = arith.constant 1 : i32
1094 // CHECK: %[[VAL_11:.*]] = arith.constant 1 : index
1095 // CHECK: %[[VAL_12:.*]] = fir.alloca i32 {bindc_name = "i", uniq_name = "_QFlbounds_reproEi"}
1096 // CHECK: %[[VAL_13:.*]] = fir.declare %[[VAL_12]] {uniq_name = "_QFlbounds_reproEi"} : (!fir.ref<i32>) -> !fir.ref<i32>
1097 // CHECK: %[[VAL_14:.*]] = fir.declare %[[VAL_1]] {fortran_attrs = {{.*}}, uniq_name = "_QFlbounds_reproEims"} : (!fir.ref<i32>) -> !fir.ref<i32>
1098 // CHECK: %[[VAL_15:.*]] = fir.declare %[[VAL_5]] {fortran_attrs = {{.*}}, uniq_name = "_QFlbounds_reproEipe"} : (!fir.ref<i32>) -> !fir.ref<i32>
1099 // CHECK: %[[VAL_16:.*]] = fir.declare %[[VAL_4]] {fortran_attrs = {{.*}}, uniq_name = "_QFlbounds_reproEips"} : (!fir.ref<i32>) -> !fir.ref<i32>
1100 // CHECK: %[[VAL_17:.*]] = fir.alloca i32 {bindc_name = "j", uniq_name = "_QFlbounds_reproEj"}
1101 // CHECK: %[[VAL_18:.*]] = fir.declare %[[VAL_17]] {uniq_name = "_QFlbounds_reproEj"} : (!fir.ref<i32>) -> !fir.ref<i32>
1102 // CHECK: %[[VAL_19:.*]] = fir.declare %[[VAL_2]] {fortran_attrs = {{.*}}, uniq_name = "_QFlbounds_reproEjms"} : (!fir.ref<i32>) -> !fir.ref<i32>
1103 // CHECK: %[[VAL_20:.*]] = fir.declare %[[VAL_7]] {fortran_attrs = {{.*}}, uniq_name = "_QFlbounds_reproEjpe"} : (!fir.ref<i32>) -> !fir.ref<i32>
1104 // CHECK: %[[VAL_21:.*]] = fir.declare %[[VAL_6]] {fortran_attrs = {{.*}}, uniq_name = "_QFlbounds_reproEjps"} : (!fir.ref<i32>) -> !fir.ref<i32>
1105 // CHECK: %[[VAL_22:.*]] = fir.alloca i32 {bindc_name = "k", uniq_name = "_QFlbounds_reproEk"}
1106 // CHECK: %[[VAL_23:.*]] = fir.declare %[[VAL_22]] {uniq_name = "_QFlbounds_reproEk"} : (!fir.ref<i32>) -> !fir.ref<i32>
1107 // CHECK: %[[VAL_24:.*]] = fir.declare %[[VAL_3]] {fortran_attrs = {{.*}}, uniq_name = "_QFlbounds_reproEkms"} : (!fir.ref<i32>) -> !fir.ref<i32>
1108 // CHECK: %[[VAL_25:.*]] = fir.declare %[[VAL_9]] {fortran_attrs = {{.*}}, uniq_name = "_QFlbounds_reproEkpe"} : (!fir.ref<i32>) -> !fir.ref<i32>
1109 // CHECK: %[[VAL_26:.*]] = fir.declare %[[VAL_8]] {fortran_attrs = {{.*}}, uniq_name = "_QFlbounds_reproEkps"} : (!fir.ref<i32>) -> !fir.ref<i32>
1110 // CHECK: %[[VAL_27:.*]] = fir.alloca f32 {bindc_name = "vmax", uniq_name = "_QFlbounds_reproEvmax"}
1111 // CHECK: %[[VAL_28:.*]] = fir.declare %[[VAL_27]] {uniq_name = "_QFlbounds_reproEvmax"} : (!fir.ref<f32>) -> !fir.ref<f32>
1112 // CHECK: %[[VAL_29:.*]] = fir.load %[[VAL_24]] : !fir.ref<i32>
1113 // CHECK: %[[VAL_30:.*]] = fir.convert %[[VAL_29]] : (i32) -> index
1114 // CHECK: %[[VAL_31:.*]] = fir.load %[[VAL_14]] : !fir.ref<i32>
1115 // CHECK: %[[VAL_32:.*]] = fir.convert %[[VAL_31]] : (i32) -> index
1116 // CHECK: %[[VAL_33:.*]] = fir.load %[[VAL_19]] : !fir.ref<i32>
1117 // CHECK: %[[VAL_34:.*]] = fir.convert %[[VAL_33]] : (i32) -> index
1118 // CHECK: %[[VAL_35:.*]] = fir.shift %[[VAL_30]], %[[VAL_32]], %[[VAL_34]] : (index, index, index) -> !fir.shift<3>
1119 // CHECK: %[[VAL_36:.*]] = fir.declare %[[VAL_0]](%[[VAL_35]]) {fortran_attrs = {{.*}}, uniq_name = "_QFlbounds_reproEu"} : (!fir.box<!fir.array<?x?x?xf32>>, !fir.shift<3>) -> !fir.box<!fir.array<?x?x?xf32>>
1120 // CHECK: %[[VAL_37:.*]] = fir.rebox %[[VAL_36]](%[[VAL_35]]) : (!fir.box<!fir.array<?x?x?xf32>>, !fir.shift<3>) -> !fir.box<!fir.array<?x?x?xf32>>
1121 // CHECK: %[[VAL_38:.*]] = fir.array_coor %[[VAL_37]](%[[VAL_35]]) %[[VAL_11]], %[[VAL_11]], %[[VAL_11]] : (!fir.box<!fir.array<?x?x?xf32>>, !fir.shift<3>, index, index, index) -> !fir.ref<f32>
1122 // CHECK: %[[VAL_39:.*]] = fir.load %[[VAL_38]] : !fir.ref<f32>
1123 // CHECK: fir.store %[[VAL_39]] to %[[VAL_28]] : !fir.ref<f32>
1124 // CHECK: %[[VAL_40:.*]] = fir.load %[[VAL_21]] : !fir.ref<i32>
1125 // CHECK: %[[VAL_41:.*]] = fir.convert %[[VAL_40]] : (i32) -> index
1126 // CHECK: %[[VAL_42:.*]] = fir.load %[[VAL_20]] : !fir.ref<i32>
1127 // CHECK: %[[VAL_43:.*]] = arith.subi %[[VAL_42]], %[[VAL_10]] : i32
1128 // CHECK: %[[VAL_44:.*]] = fir.convert %[[VAL_43]] : (i32) -> index
1129 // CHECK: %[[VAL_45:.*]] = fir.convert %[[VAL_41]] : (index) -> i32
1130 // CHECK: %[[VAL_46:.*]]:2 = fir.do_loop %[[VAL_47:.*]] = %[[VAL_41]] to %[[VAL_44]] step %[[VAL_11]] iter_args(%[[VAL_48:.*]] = %[[VAL_45]]) -> (index, i32) {
1131 // CHECK: fir.store %[[VAL_48]] to %[[VAL_18]] : !fir.ref<i32>
1132 // CHECK: %[[VAL_49:.*]] = fir.load %[[VAL_16]] : !fir.ref<i32>
1133 // CHECK: %[[VAL_50:.*]] = fir.convert %[[VAL_49]] : (i32) -> index
1134 // CHECK: %[[VAL_51:.*]] = fir.load %[[VAL_15]] : !fir.ref<i32>
1135 // CHECK: %[[VAL_52:.*]] = fir.convert %[[VAL_51]] : (i32) -> index
1136 // CHECK: %[[VAL_53:.*]] = fir.convert %[[VAL_50]] : (index) -> i32
1137 // CHECK: %[[VAL_54:.*]]:2 = fir.do_loop %[[VAL_55:.*]] = %[[VAL_50]] to %[[VAL_52]] step %[[VAL_11]] iter_args(%[[VAL_56:.*]] = %[[VAL_53]]) -> (index, i32) {
1138 // CHECK: fir.store %[[VAL_56]] to %[[VAL_13]] : !fir.ref<i32>
1139 // CHECK: %[[VAL_57:.*]] = fir.load %[[VAL_26]] : !fir.ref<i32>
1140 // CHECK: %[[VAL_58:.*]] = fir.convert %[[VAL_57]] : (i32) -> index
1141 // CHECK: %[[VAL_59:.*]] = fir.load %[[VAL_25]] : !fir.ref<i32>
1142 // CHECK: %[[VAL_60:.*]] = arith.subi %[[VAL_59]], %[[VAL_10]] : i32
1143 // CHECK: %[[VAL_61:.*]] = fir.convert %[[VAL_60]] : (i32) -> index
1144 // CHECK: %[[VAL_62:.*]] = fir.convert %[[VAL_58]] : (index) -> i32
1145 // CHECK: %[[VAL_63:.*]] = arith.constant 0 : index
1146 // CHECK: %[[VAL_64:.*]]:3 = fir.box_dims %[[VAL_37]], %[[VAL_63]] : (!fir.box<!fir.array<?x?x?xf32>>, index) -> (index, index, index)
1147 // CHECK: %[[VAL_65:.*]] = arith.constant 1 : index
1148 // CHECK: %[[VAL_66:.*]]:3 = fir.box_dims %[[VAL_37]], %[[VAL_65]] : (!fir.box<!fir.array<?x?x?xf32>>, index) -> (index, index, index)
1149 // CHECK: %[[VAL_67:.*]] = arith.constant 2 : index
1150 // CHECK: %[[VAL_68:.*]]:3 = fir.box_dims %[[VAL_37]], %[[VAL_67]] : (!fir.box<!fir.array<?x?x?xf32>>, index) -> (index, index, index)
1151 // CHECK: %[[VAL_69:.*]] = arith.constant 4 : index
1152 // CHECK: %[[VAL_70:.*]] = arith.cmpi eq, %[[VAL_64]]#2, %[[VAL_69]] : index
1153 // CHECK: %[[VAL_71:.*]]:2 = fir.if %[[VAL_70]] -> (index, i32) {
1154 // CHECK: %[[VAL_72:.*]] = fir.convert %[[VAL_37]] : (!fir.box<!fir.array<?x?x?xf32>>) -> !fir.box<!fir.array<?xf32>>
1155 // CHECK: %[[VAL_73:.*]] = fir.box_addr %[[VAL_72]] : (!fir.box<!fir.array<?xf32>>) -> !fir.ref<!fir.array<?xf32>>
1156 // CHECK: %[[VAL_74:.*]]:2 = fir.do_loop %[[VAL_75:.*]] = %[[VAL_58]] to %[[VAL_61]] step %[[VAL_11]] iter_args(%[[VAL_76:.*]] = %[[VAL_62]]) -> (index, i32) {
1157 // CHECK: fir.store %[[VAL_76]] to %[[VAL_23]] : !fir.ref<i32>
1158 // CHECK: %[[VAL_77:.*]] = fir.load %[[VAL_23]] : !fir.ref<i32>
1159 // CHECK: %[[VAL_78:.*]] = fir.convert %[[VAL_77]] : (i32) -> i64
1160 // CHECK: %[[VAL_79:.*]] = fir.load %[[VAL_13]] : !fir.ref<i32>
1161 // CHECK: %[[VAL_80:.*]] = fir.convert %[[VAL_79]] : (i32) -> i64
1162 // CHECK: %[[VAL_81:.*]] = fir.load %[[VAL_18]] : !fir.ref<i32>
1163 // CHECK: %[[VAL_82:.*]] = fir.convert %[[VAL_81]] : (i32) -> i64
1164 // CHECK: %[[VAL_83:.*]] = fir.convert %[[VAL_34]] : (index) -> i64
1165 // CHECK: %[[VAL_84:.*]] = arith.subi %[[VAL_82]], %[[VAL_83]] : i64
1166 // CHECK: %[[VAL_85:.*]] = fir.convert %[[VAL_84]] : (i64) -> index
1167 // CHECK: %[[VAL_86:.*]] = arith.muli %[[VAL_68]]#2, %[[VAL_85]] : index
1168 // CHECK: %[[VAL_87:.*]] = fir.convert %[[VAL_32]] : (index) -> i64
1169 // CHECK: %[[VAL_88:.*]] = arith.subi %[[VAL_80]], %[[VAL_87]] : i64
1170 // CHECK: %[[VAL_89:.*]] = fir.convert %[[VAL_88]] : (i64) -> index
1171 // CHECK: %[[VAL_90:.*]] = arith.muli %[[VAL_66]]#2, %[[VAL_89]] : index
1172 // CHECK: %[[VAL_91:.*]] = arith.addi %[[VAL_90]], %[[VAL_86]] : index
1173 // CHECK: %[[VAL_92:.*]] = fir.convert %[[VAL_30]] : (index) -> i64
1174 // CHECK: %[[VAL_93:.*]] = arith.subi %[[VAL_78]], %[[VAL_92]] : i64
1175 // CHECK: %[[VAL_94:.*]] = fir.convert %[[VAL_93]] : (i64) -> index
1176 // CHECK: %[[VAL_95:.*]] = arith.constant 2 : index
1177 // CHECK: %[[VAL_96:.*]] = arith.shrsi %[[VAL_91]], %[[VAL_95]] : index
1178 // CHECK: %[[VAL_97:.*]] = arith.addi %[[VAL_96]], %[[VAL_94]] : index
1179 // CHECK: %[[VAL_98:.*]] = fir.coordinate_of %[[VAL_73]], %[[VAL_97]] : (!fir.ref<!fir.array<?xf32>>, index) -> !fir.ref<f32>
1180 // CHECK: %[[VAL_99:.*]] = fir.load %[[VAL_98]] : !fir.ref<f32>
1181 // CHECK: %[[VAL_100:.*]] = fir.load %[[VAL_28]] : !fir.ref<f32>
1182 // CHECK: %[[VAL_101:.*]] = arith.cmpf ogt, %[[VAL_99]], %[[VAL_100]] : f32
1183 // CHECK: fir.if %[[VAL_101]] {
1184 // CHECK: %[[VAL_102:.*]] = fir.load %[[VAL_23]] : !fir.ref<i32>
1185 // CHECK: %[[VAL_103:.*]] = fir.convert %[[VAL_102]] : (i32) -> i64
1186 // CHECK: %[[VAL_104:.*]] = fir.load %[[VAL_13]] : !fir.ref<i32>
1187 // CHECK: %[[VAL_105:.*]] = fir.convert %[[VAL_104]] : (i32) -> i64
1188 // CHECK: %[[VAL_106:.*]] = fir.load %[[VAL_18]] : !fir.ref<i32>
1189 // CHECK: %[[VAL_107:.*]] = fir.convert %[[VAL_106]] : (i32) -> i64
1190 // CHECK: %[[VAL_108:.*]] = fir.convert %[[VAL_34]] : (index) -> i64
1191 // CHECK: %[[VAL_109:.*]] = arith.subi %[[VAL_107]], %[[VAL_108]] : i64
1192 // CHECK: %[[VAL_110:.*]] = fir.convert %[[VAL_109]] : (i64) -> index
1193 // CHECK: %[[VAL_111:.*]] = arith.muli %[[VAL_68]]#2, %[[VAL_110]] : index
1194 // CHECK: %[[VAL_112:.*]] = fir.convert %[[VAL_32]] : (index) -> i64
1195 // CHECK: %[[VAL_113:.*]] = arith.subi %[[VAL_105]], %[[VAL_112]] : i64
1196 // CHECK: %[[VAL_114:.*]] = fir.convert %[[VAL_113]] : (i64) -> index
1197 // CHECK: %[[VAL_115:.*]] = arith.muli %[[VAL_66]]#2, %[[VAL_114]] : index
1198 // CHECK: %[[VAL_116:.*]] = arith.addi %[[VAL_115]], %[[VAL_111]] : index
1199 // CHECK: %[[VAL_117:.*]] = fir.convert %[[VAL_30]] : (index) -> i64
1200 // CHECK: %[[VAL_118:.*]] = arith.subi %[[VAL_103]], %[[VAL_117]] : i64
1201 // CHECK: %[[VAL_119:.*]] = fir.convert %[[VAL_118]] : (i64) -> index
1202 // CHECK: %[[VAL_120:.*]] = arith.constant 2 : index
1203 // CHECK: %[[VAL_121:.*]] = arith.shrsi %[[VAL_116]], %[[VAL_120]] : index
1204 // CHECK: %[[VAL_122:.*]] = arith.addi %[[VAL_121]], %[[VAL_119]] : index
1205 // CHECK: %[[VAL_123:.*]] = fir.coordinate_of %[[VAL_73]], %[[VAL_122]] : (!fir.ref<!fir.array<?xf32>>, index) -> !fir.ref<f32>
1206 // CHECK: %[[VAL_124:.*]] = fir.load %[[VAL_123]] : !fir.ref<f32>
1207 // CHECK: fir.store %[[VAL_124]] to %[[VAL_28]] : !fir.ref<f32>
1210 // CHECK: %[[VAL_125:.*]] = arith.addi %[[VAL_75]], %[[VAL_11]] : index
1211 // CHECK: %[[VAL_126:.*]] = fir.convert %[[VAL_11]] : (index) -> i32
1212 // CHECK: %[[VAL_127:.*]] = fir.load %[[VAL_23]] : !fir.ref<i32>
1213 // CHECK: %[[VAL_128:.*]] = arith.addi %[[VAL_127]], %[[VAL_126]] : i32
1214 // CHECK: fir.result %[[VAL_125]], %[[VAL_128]] : index, i32
1216 // CHECK: fir.result %[[VAL_129:.*]]#0, %[[VAL_129]]#1 : index, i32
1218 // CHECK: %[[VAL_130:.*]]:2 = fir.do_loop %[[VAL_131:.*]] = %[[VAL_58]] to %[[VAL_61]] step %[[VAL_11]] iter_args(%[[VAL_132:.*]] = %[[VAL_62]]) -> (index, i32) {
1219 // CHECK: fir.store %[[VAL_132]] to %[[VAL_23]] : !fir.ref<i32>
1220 // CHECK: %[[VAL_133:.*]] = fir.load %[[VAL_23]] : !fir.ref<i32>
1221 // CHECK: %[[VAL_134:.*]] = fir.convert %[[VAL_133]] : (i32) -> i64
1222 // CHECK: %[[VAL_135:.*]] = fir.load %[[VAL_13]] : !fir.ref<i32>
1223 // CHECK: %[[VAL_136:.*]] = fir.convert %[[VAL_135]] : (i32) -> i64
1224 // CHECK: %[[VAL_137:.*]] = fir.load %[[VAL_18]] : !fir.ref<i32>
1225 // CHECK: %[[VAL_138:.*]] = fir.convert %[[VAL_137]] : (i32) -> i64
1226 // CHECK: %[[VAL_139:.*]] = fir.array_coor %[[VAL_37]](%[[VAL_35]]) %[[VAL_134]], %[[VAL_136]], %[[VAL_138]] : (!fir.box<!fir.array<?x?x?xf32>>, !fir.shift<3>, i64, i64, i64) -> !fir.ref<f32>
1227 // CHECK: %[[VAL_140:.*]] = fir.load %[[VAL_139]] : !fir.ref<f32>
1228 // CHECK: %[[VAL_141:.*]] = fir.load %[[VAL_28]] : !fir.ref<f32>
1229 // CHECK: %[[VAL_142:.*]] = arith.cmpf ogt, %[[VAL_140]], %[[VAL_141]] : f32
1230 // CHECK: fir.if %[[VAL_142]] {
1231 // CHECK: %[[VAL_143:.*]] = fir.load %[[VAL_23]] : !fir.ref<i32>
1232 // CHECK: %[[VAL_144:.*]] = fir.convert %[[VAL_143]] : (i32) -> i64
1233 // CHECK: %[[VAL_145:.*]] = fir.load %[[VAL_13]] : !fir.ref<i32>
1234 // CHECK: %[[VAL_146:.*]] = fir.convert %[[VAL_145]] : (i32) -> i64
1235 // CHECK: %[[VAL_147:.*]] = fir.load %[[VAL_18]] : !fir.ref<i32>
1236 // CHECK: %[[VAL_148:.*]] = fir.convert %[[VAL_147]] : (i32) -> i64
1237 // CHECK: %[[VAL_149:.*]] = fir.array_coor %[[VAL_37]](%[[VAL_35]]) %[[VAL_144]], %[[VAL_146]], %[[VAL_148]] : (!fir.box<!fir.array<?x?x?xf32>>, !fir.shift<3>, i64, i64, i64) -> !fir.ref<f32>
1238 // CHECK: %[[VAL_150:.*]] = fir.load %[[VAL_149]] : !fir.ref<f32>
1239 // CHECK: fir.store %[[VAL_150]] to %[[VAL_28]] : !fir.ref<f32>
1242 // CHECK: %[[VAL_151:.*]] = arith.addi %[[VAL_131]], %[[VAL_11]] : index
1243 // CHECK: %[[VAL_152:.*]] = fir.convert %[[VAL_11]] : (index) -> i32
1244 // CHECK: %[[VAL_153:.*]] = fir.load %[[VAL_23]] : !fir.ref<i32>
1245 // CHECK: %[[VAL_154:.*]] = arith.addi %[[VAL_153]], %[[VAL_152]] : i32
1246 // CHECK: fir.result %[[VAL_151]], %[[VAL_154]] : index, i32
1248 // CHECK: fir.result %[[VAL_155:.*]]#0, %[[VAL_155]]#1 : index, i32
1250 // CHECK: fir.store %[[VAL_156:.*]]#1 to %[[VAL_23]] : !fir.ref<i32>
1251 // CHECK: %[[VAL_157:.*]] = arith.addi %[[VAL_55]], %[[VAL_11]] : index
1252 // CHECK: %[[VAL_158:.*]] = fir.convert %[[VAL_11]] : (index) -> i32
1253 // CHECK: %[[VAL_159:.*]] = fir.load %[[VAL_13]] : !fir.ref<i32>
1254 // CHECK: %[[VAL_160:.*]] = arith.addi %[[VAL_159]], %[[VAL_158]] : i32
1255 // CHECK: fir.result %[[VAL_157]], %[[VAL_160]] : index, i32
1257 // CHECK: fir.store %[[VAL_161:.*]]#1 to %[[VAL_13]] : !fir.ref<i32>
1258 // CHECK: %[[VAL_162:.*]] = arith.addi %[[VAL_47]], %[[VAL_11]] : index
1259 // CHECK: %[[VAL_163:.*]] = fir.convert %[[VAL_11]] : (index) -> i32
1260 // CHECK: %[[VAL_164:.*]] = fir.load %[[VAL_18]] : !fir.ref<i32>
1261 // CHECK: %[[VAL_165:.*]] = arith.addi %[[VAL_164]], %[[VAL_163]] : i32
1262 // CHECK: fir.result %[[VAL_162]], %[[VAL_165]] : index, i32
1264 // CHECK: fir.store %[[VAL_166:.*]]#1 to %[[VAL_18]] : !fir.ref<i32>
1268 // ! Verify that neither of the loops is versioned
1269 // ! due to the array section in the inner loop:
1270 // subroutine test_slice(x)
1276 // end subroutine test_slice
1277 func.func @_QPtest_slice(%arg0: !fir.box<!fir.array<?x?xf32>> {fir.bindc_name = "x"}) {
1278 %c10 = arith.constant 10 : index
1279 %c100 = arith.constant 100 : index
1280 %c6_i64 = arith.constant 6 : i64
1281 %c3 = arith.constant 3 : index
1282 %c2 = arith.constant 2 : index
1283 %c5 = arith.constant 5 : index
1284 %cst = arith.constant 2.000000e+00 : f32
1285 %c0 = arith.constant 0 : index
1286 %c1_i64 = arith.constant 1 : i64
1287 %cst_0 = arith.constant 1.000000e+00 : f32
1288 %c1 = arith.constant 1 : index
1289 %0 = fir.alloca i32 {bindc_name = "i", uniq_name = "_QFtest_sliceEi"}
1290 %1 = fir.convert %c10 : (index) -> i32
1291 %2:2 = fir.do_loop %arg1 = %c10 to %c100 step %c1 iter_args(%arg2 = %1) -> (index, i32) {
1292 fir.store %arg2 to %0 : !fir.ref<i32>
1293 %3 = fir.load %0 : !fir.ref<i32>
1294 %4 = fir.convert %3 : (i32) -> i64
1295 %5 = arith.subi %4, %c1_i64 : i64
1296 %6 = fir.coordinate_of %arg0, %5, %c6_i64 : (!fir.box<!fir.array<?x?xf32>>, i64, i64) -> !fir.ref<f32>
1297 fir.store %cst_0 to %6 : !fir.ref<f32>
1298 %7 = fir.load %0 : !fir.ref<i32>
1299 %8 = fir.convert %7 : (i32) -> i64
1300 %9 = fir.undefined index
1301 %10 = fir.convert %7 : (i32) -> index
1302 %11 = fir.slice %8, %9, %9, %c3, %c5, %c1 : (i64, index, index, index, index, index) -> !fir.slice<2>
1303 %12 = fir.undefined !fir.array<?x?xf32>
1304 %13 = fir.do_loop %arg3 = %c0 to %c2 step %c1 unordered iter_args(%arg4 = %12) -> (!fir.array<?x?xf32>) {
1305 %18 = arith.addi %arg3, %c1 : index
1306 %19 = fir.array_coor %arg0 [%11] %10, %18 : (!fir.box<!fir.array<?x?xf32>>, !fir.slice<2>, index, index) -> !fir.ref<f32>
1307 fir.store %cst to %19 : !fir.ref<f32>
1308 fir.result %12 : !fir.array<?x?xf32>
1310 %14 = arith.addi %arg1, %c1 : index
1311 %15 = fir.convert %c1 : (index) -> i32
1312 %16 = fir.load %0 : !fir.ref<i32>
1313 %17 = arith.addi %16, %15 : i32
1314 fir.result %14, %17 : index, i32
1316 fir.store %2#1 to %0 : !fir.ref<i32>
1319 // CHECK-LABEL: func.func @_QPtest_slice(
1320 // CHECK-NOT: fir.if
1322 // ! Verify versioning for argument 'x' but not for 'y':
1323 // subroutine test_independent_args(x, y)
1324 // real :: x(:,:), y(:,:)
1329 // end subroutine test_independent_args
1330 func.func @_QPtest_independent_args(%arg0: !fir.box<!fir.array<?x?xf32>> {fir.bindc_name = "x"}, %arg1: !fir.box<!fir.array<?x?xf32>> {fir.bindc_name = "y"}) {
1331 %c10 = arith.constant 10 : index
1332 %c100 = arith.constant 100 : index
1333 %c6_i64 = arith.constant 6 : i64
1334 %c3 = arith.constant 3 : index
1335 %c2 = arith.constant 2 : index
1336 %c5 = arith.constant 5 : index
1337 %cst = arith.constant 2.000000e+00 : f32
1338 %c0 = arith.constant 0 : index
1339 %c1_i64 = arith.constant 1 : i64
1340 %cst_0 = arith.constant 1.000000e+00 : f32
1341 %c1 = arith.constant 1 : index
1342 %0 = fir.alloca i32 {bindc_name = "i", uniq_name = "_QFtest_independent_argsEi"}
1343 %1 = fir.convert %c10 : (index) -> i32
1344 %2:2 = fir.do_loop %arg2 = %c10 to %c100 step %c1 iter_args(%arg3 = %1) -> (index, i32) {
1345 fir.store %arg3 to %0 : !fir.ref<i32>
1346 %3 = fir.load %0 : !fir.ref<i32>
1347 %4 = fir.convert %3 : (i32) -> i64
1348 %5 = arith.subi %4, %c1_i64 : i64
1349 %6 = fir.coordinate_of %arg0, %5, %c6_i64 : (!fir.box<!fir.array<?x?xf32>>, i64, i64) -> !fir.ref<f32>
1350 fir.store %cst_0 to %6 : !fir.ref<f32>
1351 %7 = fir.load %0 : !fir.ref<i32>
1352 %8 = fir.convert %7 : (i32) -> i64
1353 %9 = fir.undefined index
1354 %10 = fir.convert %7 : (i32) -> index
1355 %11 = fir.slice %8, %9, %9, %c3, %c5, %c1 : (i64, index, index, index, index, index) -> !fir.slice<2>
1356 %12 = fir.undefined !fir.array<?x?xf32>
1357 %13 = fir.do_loop %arg4 = %c0 to %c2 step %c1 unordered iter_args(%arg5 = %12) -> (!fir.array<?x?xf32>) {
1358 %18 = arith.addi %arg4, %c1 : index
1359 %19 = fir.array_coor %arg1 [%11] %10, %18 : (!fir.box<!fir.array<?x?xf32>>, !fir.slice<2>, index, index) -> !fir.ref<f32>
1360 fir.store %cst to %19 : !fir.ref<f32>
1361 fir.result %12 : !fir.array<?x?xf32>
1363 %14 = arith.addi %arg2, %c1 : index
1364 %15 = fir.convert %c1 : (index) -> i32
1365 %16 = fir.load %0 : !fir.ref<i32>
1366 %17 = arith.addi %16, %15 : i32
1367 fir.result %14, %17 : index, i32
1369 fir.store %2#1 to %0 : !fir.ref<i32>
1372 // CHECK-LABEL: func.func @_QPtest_independent_args(
1373 // CHECK-SAME: %[[VAL_0:.*]]: !fir.box<!fir.array<?x?xf32>> {fir.bindc_name = "x"},
1374 // CHECK-SAME: %[[VAL_1:.*]]: !fir.box<!fir.array<?x?xf32>> {fir.bindc_name = "y"}) {
1375 // CHECK: %[[VAL_16:.*]]:3 = fir.box_dims %[[VAL_0]], %{{.*}} : (!fir.box<!fir.array<?x?xf32>>, index) -> (index, index, index)
1376 // CHECK: %[[VAL_19:.*]] = arith.constant 4 : index
1377 // CHECK: %[[VAL_20:.*]] = arith.cmpi eq, %[[VAL_16]]#2, %[[VAL_19]] : index
1378 // CHECK: %[[VAL_21:.*]]:2 = fir.if %[[VAL_20]] -> (index, i32) {
1379 // CHECK-NOT: fir.if
1382 // ! Verify that the whole loop nest is versioned
1383 // ! without additional contiguity check for the inner loop:
1384 // subroutine test_loop_nest(x)
1392 // end subroutine test_loop_nest
1393 func.func @_QPtest_loop_nest(%arg0: !fir.box<!fir.array<?xf32>> {fir.bindc_name = "x"}) {
1394 %c10 = arith.constant 10 : index
1395 %c100 = arith.constant 100 : index
1396 %cst = arith.constant 2.000000e+00 : f32
1397 %c1_i64 = arith.constant 1 : i64
1398 %cst_0 = arith.constant 1.000000e+00 : f32
1399 %c1 = arith.constant 1 : index
1400 %0 = fir.alloca i32 {bindc_name = "i", uniq_name = "_QFtest_loop_nestEi"}
1401 %1 = fir.alloca i32 {bindc_name = "j", uniq_name = "_QFtest_loop_nestEj"}
1402 %2 = fir.convert %c10 : (index) -> i32
1403 %3:2 = fir.do_loop %arg1 = %c10 to %c100 step %c1 iter_args(%arg2 = %2) -> (index, i32) {
1404 fir.store %arg2 to %0 : !fir.ref<i32>
1405 %4 = fir.load %0 : !fir.ref<i32>
1406 %5 = fir.convert %4 : (i32) -> i64
1407 %6 = arith.subi %5, %c1_i64 : i64
1408 %7 = fir.coordinate_of %arg0, %6 : (!fir.box<!fir.array<?xf32>>, i64) -> !fir.ref<f32>
1409 fir.store %cst_0 to %7 : !fir.ref<f32>
1410 %8:2 = fir.do_loop %arg3 = %c10 to %c100 step %c1 iter_args(%arg4 = %2) -> (index, i32) {
1411 fir.store %arg4 to %1 : !fir.ref<i32>
1412 %13 = fir.load %1 : !fir.ref<i32>
1413 %14 = fir.convert %13 : (i32) -> i64
1414 %15 = arith.subi %14, %c1_i64 : i64
1415 %16 = fir.coordinate_of %arg0, %15 : (!fir.box<!fir.array<?xf32>>, i64) -> !fir.ref<f32>
1416 fir.store %cst to %16 : !fir.ref<f32>
1417 %17 = arith.addi %arg3, %c1 : index
1418 %18 = fir.convert %c1 : (index) -> i32
1419 %19 = fir.load %1 : !fir.ref<i32>
1420 %20 = arith.addi %19, %18 : i32
1421 fir.result %17, %20 : index, i32
1423 fir.store %8#1 to %1 : !fir.ref<i32>
1424 %9 = arith.addi %arg1, %c1 : index
1425 %10 = fir.convert %c1 : (index) -> i32
1426 %11 = fir.load %0 : !fir.ref<i32>
1427 %12 = arith.addi %11, %10 : i32
1428 fir.result %9, %12 : index, i32
1430 fir.store %3#1 to %0 : !fir.ref<i32>
1433 // CHECK-LABEL: func.func @_QPtest_loop_nest(
1435 // CHECK-NOT: fir.if
1440 // Check that a non-dominating operand isn't causing a problem.
1441 // Just check it compiles, and doesn't version this loop.
1442 func.func @sum1drebox(%arg0: !fir.box<!fir.array<?xf64>> {fir.bindc_name = "a"}, %arg1: !fir.ref<i32> {fir.bindc_name = "n"}) {
1443 %decl = fir.declare %arg0 {uniq_name = "a"} : (!fir.box<!fir.array<?xf64>>) -> !fir.box<!fir.array<?xf64>>
1444 %0 = fir.alloca i32 {bindc_name = "i", uniq_name = "_QMmoduleFsum1dEi"}
1445 %1 = fir.alloca f64 {bindc_name = "sum", uniq_name = "_QMmoduleFsum1dEsum"}
1446 %cst = arith.constant 0.000000e+00 : f64
1447 fir.store %cst to %1 : !fir.ref<f64>
1448 %c1_i32 = arith.constant 1 : i32
1449 %2 = fir.convert %c1_i32 : (i32) -> index
1450 %3 = fir.load %arg1 : !fir.ref<i32>
1451 %4 = fir.convert %3 : (i32) -> index
1452 %c1 = arith.constant 1 : index
1453 %5 = fir.convert %2 : (index) -> i32
1454 %6:2 = fir.do_loop %arg2 = %2 to %4 step %c1 iter_args(%arg3 = %5) -> (index, i32) {
1455 // rebox is not dominating the loop.
1456 %rebox = fir.rebox %decl : (!fir.box<!fir.array<?xf64>>) -> !fir.box<!fir.array<?xf64>>
1457 fir.store %arg3 to %0 : !fir.ref<i32>
1458 %7 = fir.load %1 : !fir.ref<f64>
1459 %8 = fir.load %0 : !fir.ref<i32>
1460 %9 = fir.convert %8 : (i32) -> i64
1461 %c1_i64 = arith.constant 1 : i64
1462 %10 = arith.subi %9, %c1_i64 : i64
1463 %11 = fir.coordinate_of %rebox, %10 : (!fir.box<!fir.array<?xf64>>, i64) -> !fir.ref<f64>
1464 %12 = fir.load %11 : !fir.ref<f64>
1465 %13 = arith.addf %7, %12 fastmath<contract> : f64
1466 fir.store %13 to %1 : !fir.ref<f64>
1467 %14 = arith.addi %arg2, %c1 : index
1468 %15 = fir.convert %c1 : (index) -> i32
1469 %16 = fir.load %0 : !fir.ref<i32>
1470 %17 = arith.addi %16, %15 : i32
1471 fir.result %14, %17 : index, i32
1473 fir.store %6#1 to %0 : !fir.ref<i32>
1476 // CHECK-LABEL: func @sum1drebox
1477 // No versioning -> no if-operation.
1478 // CHECK-NOT: fir.if
1481 // Check for a use in a different block (%12 = do_loop is used inside the if %14 block)
1482 func.func @minloc(%arg0: !fir.box<!fir.array<?xi32>> {fir.bindc_name = "x"}, %arg1: !fir.box<!fir.array<?xi32>> {fir.bindc_name = "mask"}) -> f32 {
1483 %c2147483647_i32 = arith.constant 2147483647 : i32
1484 %c1_i32 = arith.constant 1 : i32
1485 %c0 = arith.constant 0 : index
1486 %c0_i32 = arith.constant 0 : i32
1487 %c5_i32 = arith.constant 5 : i32
1488 %c5 = arith.constant 5 : index
1489 %c1 = arith.constant 1 : index
1491 %1 = fir.alloca !fir.array<1xi32>
1492 %2 = fir.declare %arg1 {uniq_name = "_QFtestEmask"} : (!fir.box<!fir.array<?xi32>>) -> !fir.box<!fir.array<?xi32>>
1493 %3 = fir.rebox %2 : (!fir.box<!fir.array<?xi32>>) -> !fir.box<!fir.array<?xi32>>
1494 %4 = fir.alloca f32 {bindc_name = "test", uniq_name = "_QFtestEtest"}
1495 %5 = fir.declare %4 {uniq_name = "_QFtestEtest"} : (!fir.ref<f32>) -> !fir.ref<f32>
1496 %6 = fir.declare %arg0 {uniq_name = "_QFtestEx"} : (!fir.box<!fir.array<?xi32>>) -> !fir.box<!fir.array<?xi32>>
1497 %7 = fir.rebox %6 : (!fir.box<!fir.array<?xi32>>) -> !fir.box<!fir.array<?xi32>>
1498 %8 = fir.shape %c1 : (index) -> !fir.shape<1>
1499 %9 = fir.array_coor %1(%8) %c1 : (!fir.ref<!fir.array<1xi32>>, !fir.shape<1>, index) -> !fir.ref<i32>
1500 fir.store %c0_i32 to %9 : !fir.ref<i32>
1501 fir.store %c0_i32 to %0 : !fir.ref<i32>
1502 %10:3 = fir.box_dims %7, %c0 : (!fir.box<!fir.array<?xi32>>, index) -> (index, index, index)
1503 %11 = arith.subi %10#1, %c1 : index
1504 %12 = fir.do_loop %arg2 = %c0 to %11 step %c1 iter_args(%arg3 = %c2147483647_i32) -> (i32) {
1505 %18 = arith.addi %arg2, %c1 : index
1506 %19 = fir.array_coor %3 %18 : (!fir.box<!fir.array<?xi32>>, index) -> !fir.ref<i32>
1507 %20 = fir.load %19 : !fir.ref<i32>
1508 %21 = arith.cmpi sge, %20, %c5_i32 : i32
1509 %22 = fir.if %21 -> (i32) {
1510 fir.store %c1_i32 to %0 : !fir.ref<i32>
1511 %23 = arith.subi %10#0, %c1 : index
1512 %24 = arith.addi %18, %23 : index
1513 %25 = fir.array_coor %7 %24 : (!fir.box<!fir.array<?xi32>>, index) -> !fir.ref<i32>
1514 %26 = fir.load %25 : !fir.ref<i32>
1515 %27 = arith.cmpi slt, %26, %arg3 : i32
1516 %28 = fir.if %27 -> (i32) {
1517 %29 = fir.convert %18 : (index) -> i32
1518 fir.store %29 to %9 : !fir.ref<i32>
1519 fir.result %26 : i32
1521 fir.result %arg3 : i32
1523 fir.result %28 : i32
1525 fir.result %arg3 : i32
1527 fir.result %22 : i32
1529 %13 = fir.load %0 : !fir.ref<i32>
1530 %14 = arith.cmpi eq, %13, %c1_i32 : i32
1532 %18 = arith.cmpi eq, %12, %c2147483647_i32 : i32
1534 %19 = fir.array_coor %1(%8) %c0 : (!fir.ref<!fir.array<1xi32>>, !fir.shape<1>, index) -> !fir.ref<i32>
1535 fir.store %c1_i32 to %19 : !fir.ref<i32>
1538 %15 = fir.slice %c5, %c5, %c1 : (index, index, index) -> !fir.slice<1>
1539 %16 = fir.rebox %7 [%15] : (!fir.box<!fir.array<?xi32>>, !fir.slice<1>) -> !fir.box<!fir.array<1xi32>>
1540 fir.do_loop %arg2 = %c1 to %c1 step %c1 unordered {
1541 %18 = fir.array_coor %1(%8) %arg2 : (!fir.ref<!fir.array<1xi32>>, !fir.shape<1>, index) -> !fir.ref<i32>
1542 %19 = fir.load %18 : !fir.ref<i32>
1543 %20 = fir.array_coor %16 %arg2 : (!fir.box<!fir.array<1xi32>>, index) -> !fir.ref<i32>
1544 fir.store %19 to %20 : !fir.ref<i32>
1546 %17 = fir.load %5 : !fir.ref<f32>
1549 // CHECK-LABEL: func @minloc
1550 // CHECK: %[[V17:.*]] = fir.if %{{.*}} -> (i32) {
1551 // CHECK: %[[V27:.*]] = fir.do_loop
1552 // CHECK: fir.result %[[V27]] : i32
1554 // CHECK: %[[V23:.*]] = fir.do_loop
1555 // CHECK: fir.result %[[V23]] : i32
1556 // CHECK: fir.if %{{.*}} {
1557 // CHECK: {{.*}} = arith.cmpi eq, %[[V17]], %c2147483647_i32
1559 func.func @_QPtest_real10(%arg0: !fir.box<!fir.array<?x?xf80>> {fir.bindc_name = "a"}) -> f80 {
1560 %c10 = arith.constant 10 : index
1561 %c1 = arith.constant 1 : index
1562 %cst = arith.constant 0.000000e+00 : f80
1563 %0 = fir.declare %arg0 {fortran_attrs = #fir.var_attrs<intent_in>, uniq_name = "_QFtest_real10Ea"} : (!fir.box<!fir.array<?x?xf80>>) -> !fir.box<!fir.array<?x?xf80>>
1564 %1 = fir.rebox %0 : (!fir.box<!fir.array<?x?xf80>>) -> !fir.box<!fir.array<?x?xf80>>
1565 %2 = fir.alloca i32 {bindc_name = "i", uniq_name = "_QFtest_real10Ei"}
1566 %3 = fir.declare %2 {uniq_name = "_QFtest_real10Ei"} : (!fir.ref<i32>) -> !fir.ref<i32>
1567 %4 = fir.alloca f80 {bindc_name = "res", uniq_name = "_QFtest_real10Eres"}
1568 %5 = fir.declare %4 {uniq_name = "_QFtest_real10Eres"} : (!fir.ref<f80>) -> !fir.ref<f80>
1569 %6 = fir.address_of(@_QFtest_real10ECxdp) : !fir.ref<i32>
1570 %7 = fir.declare %6 {fortran_attrs = #fir.var_attrs<parameter>, uniq_name = "_QFtest_real10ECxdp"} : (!fir.ref<i32>) -> !fir.ref<i32>
1571 fir.store %cst to %5 : !fir.ref<f80>
1572 %8 = fir.convert %c1 : (index) -> i32
1573 %9:2 = fir.do_loop %arg1 = %c1 to %c10 step %c1 iter_args(%arg2 = %8) -> (index, i32) {
1574 fir.store %arg2 to %3 : !fir.ref<i32>
1575 %11 = fir.load %5 : !fir.ref<f80>
1576 %12 = fir.load %3 : !fir.ref<i32>
1577 %13 = fir.convert %12 : (i32) -> i64
1578 %14 = fir.array_coor %1 %13, %13 : (!fir.box<!fir.array<?x?xf80>>, i64, i64) -> !fir.ref<f80>
1579 %15 = fir.load %14 : !fir.ref<f80>
1580 %16 = arith.addf %11, %15 fastmath<contract> : f80
1581 fir.store %16 to %5 : !fir.ref<f80>
1582 %17 = arith.addi %arg1, %c1 : index
1583 %18 = fir.load %3 : !fir.ref<i32>
1584 %19 = arith.addi %18, %8 : i32
1585 fir.result %17, %19 : index, i32
1587 fir.store %9#1 to %3 : !fir.ref<i32>
1588 %10 = fir.load %5 : !fir.ref<f80>
1591 // CHECK-LABEL: func.func @_QPtest_real10(
1593 // CHECK: fir.do_loop
1594 // CHECK-DAG: arith.shrsi %{{[^,]*}}, %[[SHIFT:.*]] : index
1595 // CHECK-DAG: %[[SHIFT]] = arith.constant 4 : index
1596 // CHECK: fir.result
1598 // CHECK: fir.do_loop
1600 func.func @_QPtest_complex10(%arg0: !fir.box<!fir.array<?x?xcomplex<f80>>> {fir.bindc_name = "a"}) -> complex<f80> {
1601 %c10 = arith.constant 10 : index
1602 %c1 = arith.constant 1 : index
1603 %cst = arith.constant 0.000000e+00 : f80
1604 %0 = fir.declare %arg0 {fortran_attrs = #fir.var_attrs<intent_in>, uniq_name = "_QFtest_complex10Ea"} : (!fir.box<!fir.array<?x?xcomplex<f80>>>) -> !fir.box<!fir.array<?x?xcomplex<f80>>>
1605 %1 = fir.rebox %0 : (!fir.box<!fir.array<?x?xcomplex<f80>>>) -> !fir.box<!fir.array<?x?xcomplex<f80>>>
1606 %2 = fir.alloca i32 {bindc_name = "i", uniq_name = "_QFtest_complex10Ei"}
1607 %3 = fir.declare %2 {uniq_name = "_QFtest_complex10Ei"} : (!fir.ref<i32>) -> !fir.ref<i32>
1608 %4 = fir.alloca complex<f80> {bindc_name = "res", uniq_name = "_QFtest_complex10Eres"}
1609 %5 = fir.declare %4 {uniq_name = "_QFtest_complex10Eres"} : (!fir.ref<complex<f80>>) -> !fir.ref<complex<f80>>
1610 %6 = fir.address_of(@_QFtest_complex10ECxdp) : !fir.ref<i32>
1611 %7 = fir.declare %6 {fortran_attrs = #fir.var_attrs<parameter>, uniq_name = "_QFtest_complex10ECxdp"} : (!fir.ref<i32>) -> !fir.ref<i32>
1612 %8 = fir.undefined complex<f80>
1613 %9 = fir.insert_value %8, %cst, [0 : index] : (complex<f80>, f80) -> complex<f80>
1614 %10 = fir.insert_value %9, %cst, [1 : index] : (complex<f80>, f80) -> complex<f80>
1615 fir.store %10 to %5 : !fir.ref<complex<f80>>
1616 %11 = fir.convert %c1 : (index) -> i32
1617 %12:2 = fir.do_loop %arg1 = %c1 to %c10 step %c1 iter_args(%arg2 = %11) -> (index, i32) {
1618 fir.store %arg2 to %3 : !fir.ref<i32>
1619 %14 = fir.load %5 : !fir.ref<complex<f80>>
1620 %15 = fir.load %3 : !fir.ref<i32>
1621 %16 = fir.convert %15 : (i32) -> i64
1622 %17 = fir.array_coor %1 %16, %16 : (!fir.box<!fir.array<?x?xcomplex<f80>>>, i64, i64) -> !fir.ref<complex<f80>>
1623 %18 = fir.load %17 : !fir.ref<complex<f80>>
1624 %19 = fir.addc %14, %18 {fastmath = #arith.fastmath<contract>} : complex<f80>
1625 fir.store %19 to %5 : !fir.ref<complex<f80>>
1626 %20 = arith.addi %arg1, %c1 : index
1627 %21 = fir.load %3 : !fir.ref<i32>
1628 %22 = arith.addi %21, %11 : i32
1629 fir.result %20, %22 : index, i32
1631 fir.store %12#1 to %3 : !fir.ref<i32>
1632 %13 = fir.load %5 : !fir.ref<complex<f80>>
1633 return %13 : complex<f80>
1635 // CHECK-LABEL: func.func @_QPtest_complex10(
1637 // CHECK: fir.do_loop
1638 // CHECK-DAG: arith.shrsi %{{[^,]*}}, %[[SHIFT:.*]] : index
1639 // CHECK-DAG: %[[SHIFT]] = arith.constant 5 : index
1640 // CHECK: fir.result
1642 // CHECK: fir.do_loop