Skip to content

Commit e0433a6

Browse files
authored
[fir] Add fir to fir affine demotion test
1 parent fb1c4bf commit e0433a6

File tree

1 file changed

+68
-0
lines changed

1 file changed

+68
-0
lines changed

flang/test/Fir/affine-demotion.fir

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
// Test affine demotion pass
2+
3+
// RUN: fir-opt --split-input-file --demote-affine %s | FileCheck %s
4+
5+
#map0 = affine_map<()[s0, s1] -> (s1 - s0 + 1)>
6+
#map1 = affine_map<()[s0] -> (s0 + 1)>
7+
#map2 = affine_map<(d0)[s0, s1, s2] -> (d0 * s2 - s0)>
8+
module {
9+
func @calc(%arg0: !fir.ref<!fir.array<?xf32>>, %arg1: !fir.ref<!fir.array<?xf32>>, %arg2: !fir.ref<!fir.array<?xf32>>) {
10+
%c1 = constant 1 : index
11+
%c100 = constant 100 : index
12+
%0 = fir.shape %c100 : (index) -> !fir.shape<1>
13+
%1 = affine.apply #map0()[%c1, %c100]
14+
%2 = fir.alloca !fir.array<?xf32>, %1
15+
%3 = fir.convert %arg0 : (!fir.ref<!fir.array<?xf32>>) -> memref<?xf32>
16+
%4 = fir.convert %arg1 : (!fir.ref<!fir.array<?xf32>>) -> memref<?xf32>
17+
%5 = fir.convert %2 : (!fir.ref<!fir.array<?xf32>>) -> memref<?xf32>
18+
affine.for %arg3 = %c1 to #map1()[%c100] {
19+
%7 = affine.apply #map2(%arg3)[%c1, %c100, %c1]
20+
%8 = affine.load %3[%7] : memref<?xf32>
21+
%9 = affine.load %4[%7] : memref<?xf32>
22+
%10 = addf %8, %9 : f32
23+
affine.store %10, %5[%7] : memref<?xf32>
24+
}
25+
%6 = fir.convert %arg2 : (!fir.ref<!fir.array<?xf32>>) -> memref<?xf32>
26+
affine.for %arg3 = %c1 to #map1()[%c100] {
27+
%7 = affine.apply #map2(%arg3)[%c1, %c100, %c1]
28+
%8 = affine.load %5[%7] : memref<?xf32>
29+
%9 = affine.load %4[%7] : memref<?xf32>
30+
%10 = mulf %8, %9 : f32
31+
affine.store %10, %6[%7] : memref<?xf32>
32+
}
33+
return
34+
}
35+
}
36+
37+
// CHECK: func @calc(%[[VAL_0:.*]]: !fir.ref<!fir.array<?xf32>>, %[[VAL_1:.*]]: !fir.ref<!fir.array<?xf32>>, %[[VAL_2:.*]]: !fir.ref<!fir.array<?xf32>>) {
38+
// CHECK: %[[VAL_3:.*]] = constant 1 : index
39+
// CHECK: %[[VAL_4:.*]] = constant 100 : index
40+
// CHECK: %[[VAL_5:.*]] = fir.shape %[[VAL_4]] : (index) -> !fir.shape<1>
41+
// CHECK: %[[VAL_6:.*]] = constant 100 : index
42+
// CHECK: %[[VAL_7:.*]] = fir.alloca !fir.array<?xf32>, %[[VAL_6]]
43+
// CHECK: %[[VAL_8:.*]] = fir.convert %[[VAL_0]] : (!fir.ref<!fir.array<?xf32>>) -> !fir.ref<!fir.array<?xf32>>
44+
// CHECK: %[[VAL_9:.*]] = fir.convert %[[VAL_1]] : (!fir.ref<!fir.array<?xf32>>) -> !fir.ref<!fir.array<?xf32>>
45+
// CHECK: %[[VAL_10:.*]] = fir.convert %[[VAL_7]] : (!fir.ref<!fir.array<?xf32>>) -> !fir.ref<!fir.array<?xf32>>
46+
// CHECK: affine.for %[[VAL_11:.*]] = 1 to 101 {
47+
// CHECK: %[[VAL_12:.*]] = affine.apply #map(%[[VAL_11]]){{\[}}%[[VAL_3]], %[[VAL_4]], %[[VAL_3]]]
48+
// CHECK: %[[VAL_13:.*]] = fir.coordinate_of %[[VAL_8]], %[[VAL_12]] : (!fir.ref<!fir.array<?xf32>>, index) -> !fir.ref<f32>
49+
// CHECK: %[[VAL_14:.*]] = fir.load %[[VAL_13]] : !fir.ref<f32>
50+
// CHECK: %[[VAL_15:.*]] = fir.coordinate_of %[[VAL_9]], %[[VAL_12]] : (!fir.ref<!fir.array<?xf32>>, index) -> !fir.ref<f32>
51+
// CHECK: %[[VAL_16:.*]] = fir.load %[[VAL_15]] : !fir.ref<f32>
52+
// CHECK: %[[VAL_17:.*]] = addf %[[VAL_14]], %[[VAL_16]] : f32
53+
// CHECK: %[[VAL_18:.*]] = fir.coordinate_of %[[VAL_10]], %[[VAL_12]] : (!fir.ref<!fir.array<?xf32>>, index) -> !fir.ref<f32>
54+
// CHECK: fir.store %[[VAL_17]] to %[[VAL_18]] : !fir.ref<f32>
55+
// CHECK: }
56+
// CHECK: %[[VAL_19:.*]] = fir.convert %[[VAL_2]] : (!fir.ref<!fir.array<?xf32>>) -> !fir.ref<!fir.array<?xf32>>
57+
// CHECK: affine.for %[[VAL_20:.*]] = 1 to 101 {
58+
// CHECK: %[[VAL_21:.*]] = affine.apply #map(%[[VAL_20]]){{\[}}%[[VAL_3]], %[[VAL_4]], %[[VAL_3]]]
59+
// CHECK: %[[VAL_22:.*]] = fir.coordinate_of %[[VAL_10]], %[[VAL_21]] : (!fir.ref<!fir.array<?xf32>>, index) -> !fir.ref<f32>
60+
// CHECK: %[[VAL_23:.*]] = fir.load %[[VAL_22]] : !fir.ref<f32>
61+
// CHECK: %[[VAL_24:.*]] = fir.coordinate_of %[[VAL_9]], %[[VAL_21]] : (!fir.ref<!fir.array<?xf32>>, index) -> !fir.ref<f32>
62+
// CHECK: %[[VAL_25:.*]] = fir.load %[[VAL_24]] : !fir.ref<f32>
63+
// CHECK: %[[VAL_26:.*]] = mulf %[[VAL_23]], %[[VAL_25]] : f32
64+
// CHECK: %[[VAL_27:.*]] = fir.coordinate_of %[[VAL_19]], %[[VAL_21]] : (!fir.ref<!fir.array<?xf32>>, index) -> !fir.ref<f32>
65+
// CHECK: fir.store %[[VAL_26]] to %[[VAL_27]] : !fir.ref<f32>
66+
// CHECK: }
67+
// CHECK: return
68+
// CHECK: }

0 commit comments

Comments
 (0)