@@ -112,4 +112,171 @@ func.func @sum1dfixed(%arg0: !fir.ref<!fir.array<?xf64>> {fir.bindc_name = "a"},
112
112
// CHECK: %[[COORD:.*]] = fir.coordinate_of %[[ARG0]], {{.*}}
113
113
// CHECK: %{{.*}} = fir.load %[[COORD]]
114
114
115
+ // -----
116
+
117
+ // RUN: fir-opt --loop-versioning %s | FileCheck %s
118
+
119
+ // Check that "no result" from a versioned loop works correctly
120
+ // This code was the basis for this, but `read` is replaced with a function called Func
121
+ // subroutine test3(x, y)
122
+ // integer :: y(:)
123
+ // integer :: x(:)
124
+ // read(*,*) x(y)
125
+ // end subroutine
126
+
127
+ func.func @test3(%arg0: !fir.box<!fir.array<?xi32>> {fir.bindc_name = "x"}, %arg1: !fir.box<!fir.array<?xi32>> {fir.bindc_name = "y"}) {
128
+ %c0 = arith.constant 0 : index
129
+ %3:3 = fir.box_dims %arg1, %c0 : (!fir.box<!fir.array<?xi32>>, index) -> (index, index, index)
130
+ %c1 = arith.constant 1 : index
131
+ %4 = fir.slice %c1, %3#1, %c1 : (index, index, index) -> !fir.slice<1>
132
+ %c1_0 = arith.constant 1 : index
133
+ %c0_1 = arith.constant 0 : index
134
+ %5 = arith.subi %3#1, %c1_0 : index
135
+ fir.do_loop %arg2 = %c0_1 to %5 step %c1_0 {
136
+ %7 = fir.coordinate_of %arg1, %arg2 : (!fir.box<!fir.array<?xi32>>, index) -> !fir.ref<i32>
137
+ %8 = fir.load %7 : !fir.ref<i32>
138
+ %9 = fir.convert %8 : (i32) -> index
139
+ %10 = fir.array_coor %arg0 [%4] %9 : (!fir.box<!fir.array<?xi32>>, !fir.slice<1>, index) -> !fir.ref<i32>
140
+ %12 = fir.call @Func(%10) fastmath<contract> : (!fir.ref<i32>) -> i1
141
+ }
142
+ return
143
+ }
144
+ func.func private @Func(!fir.ref<i8>, !fir.ref<i32>) -> i1
145
+
146
+ // CHECK-LABEL: func.func @test3(
147
+ // CHECK-SAME: %[[X:.*]]: !fir.box<!fir.array<?xi32>> {{.*}},
148
+ // CHECK-SAME: %[[Y:.*]]: !fir.box<!fir.array<?xi32>> {{.*}}) {
149
+ // Look for arith.subi to locate the correct part of code.
150
+ // CHECK: {{.*}} arith.subi {{.*}}
151
+ // CHECK: %[[ZERO:.*]] = arith.constant 0 : index
152
+ // CHECK: %[[DIMS:.*]]:3 = fir.box_dims %[[Y]], %[[ZERO]]
153
+ // CHECK: %[[FOUR:.*]] = arith.constant 4 : index
154
+ // CHECK: %[[COMP:.*]] = arith.cmpi eq, %[[DIMS]]#2, %[[FOUR]] : index
155
+ // CHECK: fir.if %[[COMP]] {
156
+ // CHECK: %[[CONV:.*]] = fir.convert %[[Y]] : {{.*}}
157
+ // CHECK: %[[BOX_ADDR:.*]] = fir.box_addr %[[CONV]] : {{.*}}
158
+ // CHECK: fir.do_loop %[[INDEX:.*]] = {{.*}}
159
+ // CHECK: %[[IND_PLUS_1:.*]] = arith.addi %{{.*}}, %[[INDEX]]
160
+ // CHECK: %[[YADDR:.*]] = fir.coordinate_of %[[BOX_ADDR]], %[[IND_PLUS_1]]
161
+ // CHECK: %[[YINT:.*]] = fir.load %[[YADDR]] : {{.*}}
162
+ // CHECK: %[[YINDEX:.*]] = fir.convert %[[YINT]]
163
+ // CHECK: %[[XADDR:.*]] = fir.array_coor %[[X]] [%{{.*}}] %[[YINDEX]]
164
+ // CHECK: fir.call @Func(%[[XADDR]])
165
+ // CHECK-NEXT: }
166
+ // CHECK-NEXT: } else {
167
+ // CHECK: fir.do_loop %[[INDEX2:.*]] = {{.*}}
168
+ // CHECK: %[[YADDR2:.*]] = fir.coordinate_of %[[Y]], %[[INDEX2]]
169
+ // CHECK: %[[YINT2:.*]] = fir.load %[[YADDR2]] : {{.*}}
170
+ // CHECK: %[[YINDEX2:.*]] = fir.convert %[[YINT2]]
171
+ // CHECK: %[[XADDR2:.*]] = fir.array_coor %[[X]] [%{{.*}}] %[[YINDEX2]]
172
+ // CHECK: fir.call @Func(%[[XADDR2]])
173
+ // CHECK-NEXT: }
174
+
175
+
176
+ // ----
177
+
178
+ // Test array initialization.
179
+ //
180
+ // This code has been modified to simplify it - removing the realloc generated to grow
181
+ // the constructed
182
+ //subroutine test4(a, b, n1, m1)
183
+ // real :: a(:)
184
+ // real :: b(:,:)
185
+ //
186
+ // a = [ ((b(i,j), j=1,n1,m1), i=1,n1,m1) ]
187
+ //end subroutine test4
188
+
189
+ 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"}) {
190
+ %0 = fir.alloca index {bindc_name = ".buff.pos"}
191
+ %1 = fir.alloca index {bindc_name = ".buff.size"}
192
+ %c0 = arith.constant 0 : index
193
+ %2:3 = fir.box_dims %arg0, %c0 : (!fir.box<!fir.array<?xf32>>, index) -> (index, index, index)
194
+ %3 = fir.array_load %arg0 : (!fir.box<!fir.array<?xf32>>) -> !fir.array<?xf32>
195
+ %c0_0 = arith.constant 0 : index
196
+ fir.store %c0_0 to %0 : !fir.ref<index>
197
+ %c32 = arith.constant 32 : index
198
+ %4 = fir.allocmem f32 , %c32
199
+ fir.store %c32 to %1 : !fir.ref<index>
200
+ %c1_i64 = arith.constant 1 : i64
201
+ %5 = fir.convert %c1_i64 : (i64) -> index
202
+ %6 = fir.load %arg2 : !fir.ref<i32>
203
+ %7 = fir.convert %6 : (i32) -> i64
204
+ %8 = fir.convert %7 : (i64) -> index
205
+ %9 = fir.load %arg3 : !fir.ref<i32>
206
+ %10 = fir.convert %9 : (i32) -> i64
207
+ %11 = fir.convert %10 : (i64) -> index
208
+ %12 = fir.do_loop %arg4 = %5 to %8 step %11 iter_args(%arg5 = %4) -> (!fir.heap<f32>) {
209
+ %c1_i64_2 = arith.constant 1 : i64
210
+ %19 = fir.convert %c1_i64_2 : (i64) -> index
211
+ %20 = fir.load %arg2 : !fir.ref<i32>
212
+ %21 = fir.convert %20 : (i32) -> i64
213
+ %22 = fir.convert %21 : (i64) -> index
214
+ %23 = fir.load %arg3 : !fir.ref<i32>
215
+ %24 = fir.convert %23 : (i32) -> i64
216
+ %25 = fir.convert %24 : (i64) -> index
217
+ %26 = fir.do_loop %arg6 = %19 to %22 step %25 iter_args(%arg7 = %arg5) -> (!fir.heap<f32>) {
218
+ %27 = fir.convert %arg4 : (index) -> i32
219
+ %28 = fir.convert %27 : (i32) -> i64
220
+ %c1_i64_3 = arith.constant 1 : i64
221
+ %29 = arith.subi %28, %c1_i64_3 : i64
222
+ %30 = fir.convert %arg6 : (index) -> i32
223
+ %31 = fir.convert %30 : (i32) -> i64
224
+ %c1_i64_4 = arith.constant 1 : i64
225
+ %32 = arith.subi %31, %c1_i64_4 : i64
226
+ %33 = fir.coordinate_of %arg1, %29, %32 : (!fir.box<!fir.array<?x?xf32>>, i64, i64) -> !fir.ref<f32>
227
+ %34 = fir.load %33 : !fir.ref<f32>
228
+ %c1_5 = arith.constant 1 : index
229
+ %35 = fir.zero_bits !fir.ref<!fir.array<?xf32>>
230
+ %36 = fir.coordinate_of %35, %c1_5 : (!fir.ref<!fir.array<?xf32>>, index) -> !fir.ref<f32>
231
+ %37 = fir.convert %36 : (!fir.ref<f32>) -> index
232
+ %38 = fir.load %0 : !fir.ref<index>
233
+ %39 = fir.load %1 : !fir.ref<index>
234
+ %c1_6 = arith.constant 1 : index
235
+ %40 = arith.addi %38, %c1_6 : index
236
+
237
+ fir.store %40 to %0 : !fir.ref<index>
238
+ fir.result %arg7 : !fir.heap<f32>
239
+ }
240
+ fir.result %26 : !fir.heap<f32>
241
+ }
242
+ %13 = fir.convert %12 : (!fir.heap<f32>) -> !fir.heap<!fir.array<?xf32>>
243
+ %14 = fir.load %0 : !fir.ref<index>
244
+ %15 = fir.shape %14 : (index) -> !fir.shape<1>
245
+ %16 = fir.array_load %13(%15) : (!fir.heap<!fir.array<?xf32>>, !fir.shape<1>) -> !fir.array<?xf32>
246
+ %c1 = arith.constant 1 : index
247
+ %c0_1 = arith.constant 0 : index
248
+ %17 = arith.subi %2#1, %c1 : index
249
+ %18 = fir.do_loop %arg4 = %c0_1 to %17 step %c1 unordered iter_args(%arg5 = %3) -> (!fir.array<?xf32>) {
250
+ %19 = fir.array_fetch %16, %arg4 : (!fir.array<?xf32>, index) -> f32
251
+ %20 = fir.array_update %arg5, %19, %arg4 : (!fir.array<?xf32>, f32, index) -> !fir.array<?xf32>
252
+ fir.result %20 : !fir.array<?xf32>
253
+ }
254
+ fir.array_merge_store %3, %18 to %arg0 : !fir.array<?xf32>, !fir.array<?xf32>, !fir.box<!fir.array<?xf32>>
255
+ fir.freemem %13 : !fir.heap<!fir.array<?xf32>>
256
+ return
257
+ }
258
+
259
+ // CHECK: func.func @test4(
260
+ // CHECK-SAME: %[[A:.*]]: !fir.box<!fir.array<?xf32>>
261
+ // CHECK-SAME: %[[B:.*]]: !fir.box<!fir.array<?x?xf32>>
262
+ // CHECK-SAME: %[[N1:.*]]: !fir.ref<i32> {{.*}},
263
+ // CHECK-SAME: %[[M1:.*]]: !fir.ref<i32> {{.*}}) {
264
+ // CHECK: fir.do_loop
265
+ // CHECL: %[[FOUR:.*]] = arith.constant 4 : index
266
+ // CHECK: %[[COMP:.*]] = arith.cmpi {{.*}}, %[[FOUR]]
267
+ // CHECK: fir.if %[[COMP]] -> {{.*}} {
268
+ // CHECK: %[[CONV:.*]] = fir.convert %[[B]] :
269
+ // CHECK: %[[BOX_ADDR:.*]] = fir.box_addr %[[CONV]]
270
+ // CHECK: %[[RES:.*]] = fir.do_loop {{.*}} {
271
+ // CHECK: %[[ADDR:.*]] = fir.coordinate_of %[[BOX_ADDR]], %{{.*}}
272
+ // CHECK: %45 = fir.load %[[ADDR]] : !fir.ref<f32>
273
+ // CHECK: }
274
+ // CHECK: fir.result %[[RES]] : {{.*}}
275
+ // CHECK: } else {
276
+ // CHECK: %[[RES2:.*]] = fir.do_loop
277
+ // CHECK: %{{.*}} = fir.coordinate_of %[[B]], %{{.*}}
278
+ // CHECK: }
279
+ // CHECK: fir.result %[[RES2]]
280
+ // CHECK: }
281
+
115
282
} // End module
0 commit comments