@@ -35,10 +35,12 @@ func @single_iteration(%A: memref<?x?x?xi32>) {
35
35
36
36
// -----
37
37
38
+ func private @side_effect ()
38
39
func @one_unused (%cond: i1 ) -> (index ) {
39
40
%c0 = constant 0 : index
40
41
%c1 = constant 1 : index
41
42
%0 , %1 = scf.if %cond -> (index , index ) {
43
+ call @side_effect () : () -> ()
42
44
scf.yield %c0 , %c1 : index , index
43
45
} else {
44
46
scf.yield %c0 , %c1 : index , index
@@ -49,6 +51,7 @@ func @one_unused(%cond: i1) -> (index) {
49
51
// CHECK-LABEL: func @one_unused
50
52
// CHECK: [[C0:%.*]] = constant 1 : index
51
53
// CHECK: [[V0:%.*]] = scf.if %{{.*}} -> (index) {
54
+ // CHECK: call @side_effect() : () -> ()
52
55
// CHECK: scf.yield [[C0]] : index
53
56
// CHECK: } else
54
57
// CHECK: scf.yield [[C0]] : index
@@ -57,11 +60,13 @@ func @one_unused(%cond: i1) -> (index) {
57
60
58
61
// -----
59
62
63
+ func private @side_effect ()
60
64
func @nested_unused (%cond1: i1 , %cond2: i1 ) -> (index ) {
61
65
%c0 = constant 0 : index
62
66
%c1 = constant 1 : index
63
67
%0 , %1 = scf.if %cond1 -> (index , index ) {
64
68
%2 , %3 = scf.if %cond2 -> (index , index ) {
69
+ call @side_effect () : () -> ()
65
70
scf.yield %c0 , %c1 : index , index
66
71
} else {
67
72
scf.yield %c0 , %c1 : index , index
@@ -77,6 +82,7 @@ func @nested_unused(%cond1: i1, %cond2: i1) -> (index) {
77
82
// CHECK: [[C0:%.*]] = constant 1 : index
78
83
// CHECK: [[V0:%.*]] = scf.if {{.*}} -> (index) {
79
84
// CHECK: [[V1:%.*]] = scf.if {{.*}} -> (index) {
85
+ // CHECK: call @side_effect() : () -> ()
80
86
// CHECK: scf.yield [[C0]] : index
81
87
// CHECK: } else
82
88
// CHECK: scf.yield [[C0]] : index
@@ -113,6 +119,96 @@ func @all_unused(%cond: i1) {
113
119
114
120
// -----
115
121
122
+ func @empty_if1 (%cond: i1 ) {
123
+ scf.if %cond {
124
+ scf.yield
125
+ }
126
+ return
127
+ }
128
+
129
+ // CHECK-LABEL: func @empty_if1
130
+ // CHECK-NOT: scf.if
131
+ // CHECK: return
132
+
133
+ // -----
134
+
135
+ func @empty_if2 (%cond: i1 ) {
136
+ scf.if %cond {
137
+ scf.yield
138
+ } else {
139
+ scf.yield
140
+ }
141
+ return
142
+ }
143
+
144
+ // CHECK-LABEL: func @empty_if2
145
+ // CHECK-NOT: scf.if
146
+ // CHECK: return
147
+
148
+ // -----
149
+
150
+ func @to_select1 (%cond: i1 ) -> index {
151
+ %c0 = constant 0 : index
152
+ %c1 = constant 1 : index
153
+ %0 = scf.if %cond -> index {
154
+ scf.yield %c0 : index
155
+ } else {
156
+ scf.yield %c1 : index
157
+ }
158
+ return %0 : index
159
+ }
160
+
161
+ // CHECK-LABEL: func @to_select1
162
+ // CHECK: [[C0:%.*]] = constant 0 : index
163
+ // CHECK: [[C1:%.*]] = constant 1 : index
164
+ // CHECK: [[V0:%.*]] = select {{.*}}, [[C0]], [[C1]]
165
+ // CHECK: return [[V0]] : index
166
+
167
+ // -----
168
+
169
+ func @to_select_same_val (%cond: i1 ) -> (index , index ) {
170
+ %c0 = constant 0 : index
171
+ %c1 = constant 1 : index
172
+ %0 , %1 = scf.if %cond -> (index , index ) {
173
+ scf.yield %c0 , %c1 : index , index
174
+ } else {
175
+ scf.yield %c1 , %c1 : index , index
176
+ }
177
+ return %0 , %1 : index , index
178
+ }
179
+
180
+ // CHECK-LABEL: func @to_select_same_val
181
+ // CHECK: [[C0:%.*]] = constant 0 : index
182
+ // CHECK: [[C1:%.*]] = constant 1 : index
183
+ // CHECK: [[V0:%.*]] = select {{.*}}, [[C0]], [[C1]]
184
+ // CHECK: return [[V0]], [[C1]] : index, index
185
+
186
+ // -----
187
+
188
+ func @to_select2 (%cond: i1 ) -> (index , index ) {
189
+ %c0 = constant 0 : index
190
+ %c1 = constant 1 : index
191
+ %c2 = constant 2 : index
192
+ %c3 = constant 3 : index
193
+ %0 , %1 = scf.if %cond -> (index , index ) {
194
+ scf.yield %c0 , %c1 : index , index
195
+ } else {
196
+ scf.yield %c2 , %c3 : index , index
197
+ }
198
+ return %0 , %1 : index , index
199
+ }
200
+
201
+ // CHECK-LABEL: func @to_select2
202
+ // CHECK: [[C0:%.*]] = constant 0 : index
203
+ // CHECK: [[C1:%.*]] = constant 1 : index
204
+ // CHECK: [[C2:%.*]] = constant 2 : index
205
+ // CHECK: [[C3:%.*]] = constant 3 : index
206
+ // CHECK: [[V0:%.*]] = select {{.*}}, [[C0]], [[C2]]
207
+ // CHECK: [[V1:%.*]] = select {{.*}}, [[C1]], [[C3]]
208
+ // CHECK: return [[V0]], [[V1]] : index
209
+
210
+ // -----
211
+
116
212
func private @make_i32 () -> i32
117
213
118
214
func @for_yields_2 (%lb : index , %ub : index , %step : index ) -> i32 {
0 commit comments