convert-to-cfg.mlir
5.25 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
// RUN: mlir-opt -convert-loop-to-std %s | FileCheck %s
// CHECK-LABEL: func @simple_std_for_loop(%{{.*}}: index, %{{.*}}: index, %{{.*}}: index) {
// CHECK-NEXT: br ^bb1(%{{.*}} : index)
// CHECK-NEXT: ^bb1(%{{.*}}: index): // 2 preds: ^bb0, ^bb2
// CHECK-NEXT: %{{.*}} = cmpi "slt", %{{.*}}, %{{.*}} : index
// CHECK-NEXT: cond_br %{{.*}}, ^bb2, ^bb3
// CHECK-NEXT: ^bb2: // pred: ^bb1
// CHECK-NEXT: %{{.*}} = constant 1 : index
// CHECK-NEXT: %[[iv:.*]] = addi %{{.*}}, %{{.*}} : index
// CHECK-NEXT: br ^bb1(%[[iv]] : index)
// CHECK-NEXT: ^bb3: // pred: ^bb1
// CHECK-NEXT: return
func @simple_std_for_loop(%arg0 : index, %arg1 : index, %arg2 : index) {
loop.for %i0 = %arg0 to %arg1 step %arg2 {
%c1 = constant 1 : index
}
return
}
// CHECK-LABEL: func @simple_std_2_for_loops(%{{.*}}: index, %{{.*}}: index, %{{.*}}: index) {
// CHECK-NEXT: br ^bb1(%{{.*}} : index)
// CHECK-NEXT: ^bb1(%[[ub0:.*]]: index): // 2 preds: ^bb0, ^bb5
// CHECK-NEXT: %[[cond0:.*]] = cmpi "slt", %[[ub0]], %{{.*}} : index
// CHECK-NEXT: cond_br %[[cond0]], ^bb2, ^bb6
// CHECK-NEXT: ^bb2: // pred: ^bb1
// CHECK-NEXT: %{{.*}} = constant 1 : index
// CHECK-NEXT: br ^bb3(%{{.*}} : index)
// CHECK-NEXT: ^bb3(%[[ub1:.*]]: index): // 2 preds: ^bb2, ^bb4
// CHECK-NEXT: %[[cond1:.*]] = cmpi "slt", %{{.*}}, %{{.*}} : index
// CHECK-NEXT: cond_br %[[cond1]], ^bb4, ^bb5
// CHECK-NEXT: ^bb4: // pred: ^bb3
// CHECK-NEXT: %{{.*}} = constant 1 : index
// CHECK-NEXT: %[[iv1:.*]] = addi %{{.*}}, %{{.*}} : index
// CHECK-NEXT: br ^bb3(%[[iv1]] : index)
// CHECK-NEXT: ^bb5: // pred: ^bb3
// CHECK-NEXT: %[[iv0:.*]] = addi %{{.*}}, %{{.*}} : index
// CHECK-NEXT: br ^bb1(%[[iv0]] : index)
// CHECK-NEXT: ^bb6: // pred: ^bb1
// CHECK-NEXT: return
func @simple_std_2_for_loops(%arg0 : index, %arg1 : index, %arg2 : index) {
loop.for %i0 = %arg0 to %arg1 step %arg2 {
%c1 = constant 1 : index
loop.for %i1 = %arg0 to %arg1 step %arg2 {
%c1_0 = constant 1 : index
}
}
return
}
// CHECK-LABEL: func @simple_std_if(%{{.*}}: i1) {
// CHECK-NEXT: cond_br %{{.*}}, ^bb1, ^bb2
// CHECK-NEXT: ^bb1: // pred: ^bb0
// CHECK-NEXT: %{{.*}} = constant 1 : index
// CHECK-NEXT: br ^bb2
// CHECK-NEXT: ^bb2: // 2 preds: ^bb0, ^bb1
// CHECK-NEXT: return
func @simple_std_if(%arg0: i1) {
loop.if %arg0 {
%c1 = constant 1 : index
}
return
}
// CHECK-LABEL: func @simple_std_if_else(%{{.*}}: i1) {
// CHECK-NEXT: cond_br %{{.*}}, ^bb1, ^bb2
// CHECK-NEXT: ^bb1: // pred: ^bb0
// CHECK-NEXT: %{{.*}} = constant 1 : index
// CHECK-NEXT: br ^bb3
// CHECK-NEXT: ^bb2: // pred: ^bb0
// CHECK-NEXT: %{{.*}} = constant 1 : index
// CHECK-NEXT: br ^bb3
// CHECK-NEXT: ^bb3: // 2 preds: ^bb1, ^bb2
// CHECK-NEXT: return
func @simple_std_if_else(%arg0: i1) {
loop.if %arg0 {
%c1 = constant 1 : index
} else {
%c1_0 = constant 1 : index
}
return
}
// CHECK-LABEL: func @simple_std_2_ifs(%{{.*}}: i1) {
// CHECK-NEXT: cond_br %{{.*}}, ^bb1, ^bb5
// CHECK-NEXT: ^bb1: // pred: ^bb0
// CHECK-NEXT: %{{.*}} = constant 1 : index
// CHECK-NEXT: cond_br %{{.*}}, ^bb2, ^bb3
// CHECK-NEXT: ^bb2: // pred: ^bb1
// CHECK-NEXT: %{{.*}} = constant 1 : index
// CHECK-NEXT: br ^bb4
// CHECK-NEXT: ^bb3: // pred: ^bb1
// CHECK-NEXT: %{{.*}} = constant 1 : index
// CHECK-NEXT: br ^bb4
// CHECK-NEXT: ^bb4: // 2 preds: ^bb2, ^bb3
// CHECK-NEXT: br ^bb5
// CHECK-NEXT: ^bb5: // 2 preds: ^bb0, ^bb4
// CHECK-NEXT: return
func @simple_std_2_ifs(%arg0: i1) {
loop.if %arg0 {
%c1 = constant 1 : index
loop.if %arg0 {
%c1_0 = constant 1 : index
} else {
%c1_1 = constant 1 : index
}
}
return
}
// CHECK-LABEL: func @simple_std_for_loop_with_2_ifs(%{{.*}}: index, %{{.*}}: index, %{{.*}}: index, %{{.*}}: i1) {
// CHECK-NEXT: br ^bb1(%{{.*}} : index)
// CHECK-NEXT: ^bb1(%{{.*}}: index): // 2 preds: ^bb0, ^bb7
// CHECK-NEXT: %{{.*}} = cmpi "slt", %{{.*}}, %{{.*}} : index
// CHECK-NEXT: cond_br %{{.*}}, ^bb2, ^bb8
// CHECK-NEXT: ^bb2: // pred: ^bb1
// CHECK-NEXT: %{{.*}} = constant 1 : index
// CHECK-NEXT: cond_br %{{.*}}, ^bb3, ^bb7
// CHECK-NEXT: ^bb3: // pred: ^bb2
// CHECK-NEXT: %{{.*}} = constant 1 : index
// CHECK-NEXT: cond_br %{{.*}}, ^bb4, ^bb5
// CHECK-NEXT: ^bb4: // pred: ^bb3
// CHECK-NEXT: %{{.*}} = constant 1 : index
// CHECK-NEXT: br ^bb6
// CHECK-NEXT: ^bb5: // pred: ^bb3
// CHECK-NEXT: %{{.*}} = constant 1 : index
// CHECK-NEXT: br ^bb6
// CHECK-NEXT: ^bb6: // 2 preds: ^bb4, ^bb5
// CHECK-NEXT: br ^bb7
// CHECK-NEXT: ^bb7: // 2 preds: ^bb2, ^bb6
// CHECK-NEXT: %[[iv0:.*]] = addi %{{.*}}, %{{.*}} : index
// CHECK-NEXT: br ^bb1(%[[iv0]] : index)
// CHECK-NEXT: ^bb8: // pred: ^bb1
// CHECK-NEXT: return
// CHECK-NEXT: }
func @simple_std_for_loop_with_2_ifs(%arg0 : index, %arg1 : index, %arg2 : index, %arg3 : i1) {
loop.for %i0 = %arg0 to %arg1 step %arg2 {
%c1 = constant 1 : index
loop.if %arg3 {
%c1_0 = constant 1 : index
loop.if %arg3 {
%c1_1 = constant 1 : index
} else {
%c1_2 = constant 1 : index
}
}
}
return
}