1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2 ; RUN: opt -S -passes=dfa-jump-threading -dfa-early-exit-heuristic=false %s | FileCheck %s
4 ; These tests check if selects are unfolded properly for jump threading
5 ; opportunities. There are three different patterns to consider:
6 ; 1) Both operands are constant and the false branch is unfolded by default
7 ; 2) One operand is constant and the other is another select to be unfolded. In
8 ; this case a single select is sunk to a new block to unfold.
9 ; 3) Both operands are a select, and both should be sunk to new blocks.
10 define i32 @test1(i32 %num) {
11 ; CHECK-LABEL: @test1(
13 ; CHECK-NEXT: br label [[FOR_BODY:%.*]]
15 ; CHECK-NEXT: [[COUNT:%.*]] = phi i32 [ 0, [[ENTRY:%.*]] ], [ [[INC:%.*]], [[FOR_INC:%.*]] ]
16 ; CHECK-NEXT: [[STATE:%.*]] = phi i32 [ 1, [[ENTRY]] ], [ [[STATE_NEXT:%.*]], [[FOR_INC]] ]
17 ; CHECK-NEXT: switch i32 [[STATE]], label [[FOR_INC_JT1:%.*]] [
18 ; CHECK-NEXT: i32 1, label [[CASE1:%.*]]
19 ; CHECK-NEXT: i32 2, label [[CASE2:%.*]]
21 ; CHECK: for.body.jt2:
22 ; CHECK-NEXT: [[COUNT_JT2:%.*]] = phi i32 [ [[INC_JT2:%.*]], [[FOR_INC_JT2:%.*]] ]
23 ; CHECK-NEXT: [[STATE_JT2:%.*]] = phi i32 [ [[STATE_NEXT_JT2:%.*]], [[FOR_INC_JT2]] ]
24 ; CHECK-NEXT: br label [[CASE2]]
25 ; CHECK: for.body.jt1:
26 ; CHECK-NEXT: [[COUNT_JT1:%.*]] = phi i32 [ [[INC_JT1:%.*]], [[FOR_INC_JT1]] ]
27 ; CHECK-NEXT: [[STATE_JT1:%.*]] = phi i32 [ [[STATE_NEXT_JT1:%.*]], [[FOR_INC_JT1]] ]
28 ; CHECK-NEXT: br label [[CASE1]]
30 ; CHECK-NEXT: [[COUNT2:%.*]] = phi i32 [ [[COUNT_JT1]], [[FOR_BODY_JT1:%.*]] ], [ [[COUNT]], [[FOR_BODY]] ]
31 ; CHECK-NEXT: br label [[FOR_INC_JT2]]
33 ; CHECK-NEXT: [[COUNT1:%.*]] = phi i32 [ [[COUNT_JT2]], [[FOR_BODY_JT2:%.*]] ], [ [[COUNT]], [[FOR_BODY]] ]
34 ; CHECK-NEXT: [[CMP:%.*]] = icmp slt i32 [[COUNT1]], 50
35 ; CHECK-NEXT: br i1 [[CMP]], label [[FOR_INC_JT1]], label [[SEL_SI_UNFOLD_FALSE_JT2:%.*]]
36 ; CHECK: sel.si.unfold.false:
37 ; CHECK-NEXT: br label [[FOR_INC]]
38 ; CHECK: sel.si.unfold.false.jt2:
39 ; CHECK-NEXT: [[DOTSI_UNFOLD_PHI_JT2:%.*]] = phi i32 [ 2, [[CASE2]] ]
40 ; CHECK-NEXT: br label [[FOR_INC_JT2]]
42 ; CHECK-NEXT: [[STATE_NEXT]] = phi i32 [ poison, [[SEL_SI_UNFOLD_FALSE:%.*]] ]
43 ; CHECK-NEXT: [[INC]] = add nsw i32 undef, 1
44 ; CHECK-NEXT: [[CMP_EXIT:%.*]] = icmp slt i32 [[INC]], [[NUM:%.*]]
45 ; CHECK-NEXT: br i1 [[CMP_EXIT]], label [[FOR_BODY]], label [[FOR_END:%.*]]
47 ; CHECK-NEXT: [[COUNT4:%.*]] = phi i32 [ [[COUNT1]], [[SEL_SI_UNFOLD_FALSE_JT2]] ], [ [[COUNT2]], [[CASE1]] ]
48 ; CHECK-NEXT: [[STATE_NEXT_JT2]] = phi i32 [ 2, [[CASE1]] ], [ [[DOTSI_UNFOLD_PHI_JT2]], [[SEL_SI_UNFOLD_FALSE_JT2]] ]
49 ; CHECK-NEXT: [[INC_JT2]] = add nsw i32 [[COUNT4]], 1
50 ; CHECK-NEXT: [[CMP_EXIT_JT2:%.*]] = icmp slt i32 [[INC_JT2]], [[NUM]]
51 ; CHECK-NEXT: br i1 [[CMP_EXIT_JT2]], label [[FOR_BODY_JT2]], label [[FOR_END]]
53 ; CHECK-NEXT: [[COUNT3:%.*]] = phi i32 [ [[COUNT]], [[FOR_BODY]] ], [ [[COUNT1]], [[CASE2]] ]
54 ; CHECK-NEXT: [[STATE_NEXT_JT1]] = phi i32 [ 1, [[CASE2]] ], [ 1, [[FOR_BODY]] ]
55 ; CHECK-NEXT: [[INC_JT1]] = add nsw i32 [[COUNT3]], 1
56 ; CHECK-NEXT: [[CMP_EXIT_JT1:%.*]] = icmp slt i32 [[INC_JT1]], [[NUM]]
57 ; CHECK-NEXT: br i1 [[CMP_EXIT_JT1]], label [[FOR_BODY_JT1]], label [[FOR_END]]
59 ; CHECK-NEXT: ret i32 0
65 %count = phi i32 [ 0, %entry ], [ %inc, %for.inc ]
66 %state = phi i32 [ 1, %entry ], [ %state.next, %for.inc ]
67 switch i32 %state, label %for.inc [
76 %cmp = icmp slt i32 %count, 50
77 %sel = select i1 %cmp, i32 1, i32 2
81 %state.next = phi i32 [ %sel, %case2 ], [ 1, %for.body ], [ 2, %case1 ]
82 %inc = add nsw i32 %count, 1
83 %cmp.exit = icmp slt i32 %inc, %num
84 br i1 %cmp.exit, label %for.body, label %for.end
90 define i32 @test2(i32 %num) {
91 ; CHECK-LABEL: @test2(
93 ; CHECK-NEXT: br label [[FOR_BODY:%.*]]
95 ; CHECK-NEXT: [[COUNT:%.*]] = phi i32 [ 0, [[ENTRY:%.*]] ], [ [[INC:%.*]], [[FOR_INC:%.*]] ]
96 ; CHECK-NEXT: [[STATE:%.*]] = phi i32 [ 1, [[ENTRY]] ], [ [[STATE_NEXT:%.*]], [[FOR_INC]] ]
97 ; CHECK-NEXT: switch i32 [[STATE]], label [[FOR_INC_JT1:%.*]] [
98 ; CHECK-NEXT: i32 1, label [[CASE1:%.*]]
99 ; CHECK-NEXT: i32 2, label [[CASE2:%.*]]
101 ; CHECK: for.body.jt2:
102 ; CHECK-NEXT: [[COUNT_JT2:%.*]] = phi i32 [ [[INC_JT2:%.*]], [[FOR_INC_JT2:%.*]] ]
103 ; CHECK-NEXT: [[STATE_JT2:%.*]] = phi i32 [ [[STATE_NEXT_JT2:%.*]], [[FOR_INC_JT2]] ]
104 ; CHECK-NEXT: br label [[CASE2]]
105 ; CHECK: for.body.jt1:
106 ; CHECK-NEXT: [[COUNT_JT1:%.*]] = phi i32 [ [[INC_JT1:%.*]], [[FOR_INC_JT1]] ]
107 ; CHECK-NEXT: [[STATE_JT1:%.*]] = phi i32 [ [[STATE_NEXT_JT1:%.*]], [[FOR_INC_JT1]] ]
108 ; CHECK-NEXT: br label [[CASE1]]
109 ; CHECK: for.body.jt3:
110 ; CHECK-NEXT: [[COUNT_JT3:%.*]] = phi i32 [ [[INC_JT3:%.*]], [[FOR_INC_JT3:%.*]] ]
111 ; CHECK-NEXT: [[STATE_JT3:%.*]] = phi i32 [ [[STATE_NEXT_JT3:%.*]], [[FOR_INC_JT3]] ]
112 ; CHECK-NEXT: br label [[FOR_INC]]
114 ; CHECK-NEXT: [[COUNT6:%.*]] = phi i32 [ [[COUNT_JT1]], [[FOR_BODY_JT1:%.*]] ], [ [[COUNT]], [[FOR_BODY]] ]
115 ; CHECK-NEXT: [[CMP_C1:%.*]] = icmp slt i32 [[COUNT6]], 50
116 ; CHECK-NEXT: [[CMP2_C1:%.*]] = icmp slt i32 [[COUNT6]], 100
117 ; CHECK-NEXT: br i1 [[CMP2_C1]], label [[STATE1_1_SI_UNFOLD_TRUE_JT1:%.*]], label [[STATE1_2_SI_UNFOLD_FALSE_JT3:%.*]]
119 ; CHECK-NEXT: [[CMP_C2:%.*]] = icmp slt i32 [[COUNT]], 50
120 ; CHECK-NEXT: [[CMP2_C2:%.*]] = icmp sgt i32 [[COUNT]], 100
121 ; CHECK-NEXT: br i1 [[CMP2_C2]], label [[FOR_INC_JT3]], label [[STATE2_1_SI_UNFOLD_TRUE_JT1:%.*]]
122 ; CHECK: state2.1.si.unfold.true:
123 ; CHECK-NEXT: br i1 [[CMP_C2]], label [[STATE2_2_SI_UNFOLD_FALSE:%.*]], label [[STATE2_1_SI_UNFOLD_FALSE_JT2:%.*]]
124 ; CHECK: state2.1.si.unfold.true.jt1:
125 ; CHECK-NEXT: [[DOTSI_UNFOLD_PHI_JT1:%.*]] = phi i32 [ 1, [[CASE2]] ]
126 ; CHECK-NEXT: br i1 [[CMP_C2]], label [[STATE2_2_SI_UNFOLD_FALSE_JT1:%.*]], label [[STATE2_1_SI_UNFOLD_FALSE:%.*]]
127 ; CHECK: state2.1.si.unfold.false:
128 ; CHECK-NEXT: [[DOTSI_UNFOLD_PHI1:%.*]] = phi i32 [ 2, [[STATE2_1_SI_UNFOLD_TRUE_JT1]] ]
129 ; CHECK-NEXT: br label [[STATE2_2_SI_UNFOLD_FALSE]]
130 ; CHECK: state2.1.si.unfold.false.jt2:
131 ; CHECK-NEXT: [[DOTSI_UNFOLD_PHI1_JT2:%.*]] = phi i32 [ 2, [[STATE2_1_SI_UNFOLD_TRUE:%.*]] ]
132 ; CHECK-NEXT: br label [[STATE2_2_SI_UNFOLD_FALSE_JT2:%.*]]
133 ; CHECK: state2.2.si.unfold.false:
134 ; CHECK-NEXT: [[STATE2_1_SI_UNFOLD_PHI:%.*]] = phi i32 [ poison, [[STATE2_1_SI_UNFOLD_TRUE]] ], [ [[DOTSI_UNFOLD_PHI1]], [[STATE2_1_SI_UNFOLD_FALSE]] ]
135 ; CHECK-NEXT: br label [[FOR_INC]]
136 ; CHECK: state2.2.si.unfold.false.jt2:
137 ; CHECK-NEXT: [[STATE2_1_SI_UNFOLD_PHI_JT2:%.*]] = phi i32 [ [[DOTSI_UNFOLD_PHI1_JT2]], [[STATE2_1_SI_UNFOLD_FALSE_JT2]] ]
138 ; CHECK-NEXT: br label [[FOR_INC_JT2]]
139 ; CHECK: state2.2.si.unfold.false.jt1:
140 ; CHECK-NEXT: [[STATE2_1_SI_UNFOLD_PHI_JT1:%.*]] = phi i32 [ [[DOTSI_UNFOLD_PHI_JT1]], [[STATE2_1_SI_UNFOLD_TRUE_JT1]] ]
141 ; CHECK-NEXT: br label [[FOR_INC_JT1]]
142 ; CHECK: state1.2.si.unfold.false:
143 ; CHECK-NEXT: br label [[FOR_INC]]
144 ; CHECK: state1.2.si.unfold.false.jt3:
145 ; CHECK-NEXT: [[DOTSI_UNFOLD_PHI2_JT3:%.*]] = phi i32 [ 3, [[CASE1]] ]
146 ; CHECK-NEXT: br label [[FOR_INC_JT3]]
147 ; CHECK: state1.1.si.unfold.true:
148 ; CHECK-NEXT: br i1 [[CMP_C1]], label [[FOR_INC]], label [[STATE1_1_SI_UNFOLD_FALSE_JT2:%.*]]
149 ; CHECK: state1.1.si.unfold.true.jt1:
150 ; CHECK-NEXT: [[DOTSI_UNFOLD_PHI3_JT1:%.*]] = phi i32 [ 1, [[CASE1]] ]
151 ; CHECK-NEXT: br i1 [[CMP_C1]], label [[FOR_INC_JT1]], label [[STATE1_1_SI_UNFOLD_FALSE:%.*]]
152 ; CHECK: state1.1.si.unfold.false:
153 ; CHECK-NEXT: [[DOTSI_UNFOLD_PHI4:%.*]] = phi i32 [ 2, [[STATE1_1_SI_UNFOLD_TRUE_JT1]] ]
154 ; CHECK-NEXT: br label [[FOR_INC]]
155 ; CHECK: state1.1.si.unfold.false.jt2:
156 ; CHECK-NEXT: [[DOTSI_UNFOLD_PHI4_JT2:%.*]] = phi i32 [ 2, [[STATE1_1_SI_UNFOLD_TRUE:%.*]] ]
157 ; CHECK-NEXT: br label [[FOR_INC_JT2]]
159 ; CHECK-NEXT: [[COUNT5:%.*]] = phi i32 [ [[COUNT_JT3]], [[FOR_BODY_JT3:%.*]] ], [ undef, [[STATE1_1_SI_UNFOLD_TRUE]] ], [ [[COUNT6]], [[STATE1_1_SI_UNFOLD_FALSE]] ], [ undef, [[STATE1_2_SI_UNFOLD_FALSE:%.*]] ], [ [[COUNT]], [[STATE2_2_SI_UNFOLD_FALSE]] ]
160 ; CHECK-NEXT: [[STATE_NEXT]] = phi i32 [ [[STATE2_1_SI_UNFOLD_PHI]], [[STATE2_2_SI_UNFOLD_FALSE]] ], [ poison, [[STATE1_2_SI_UNFOLD_FALSE]] ], [ poison, [[STATE1_1_SI_UNFOLD_TRUE]] ], [ [[DOTSI_UNFOLD_PHI4]], [[STATE1_1_SI_UNFOLD_FALSE]] ], [ 1, [[FOR_BODY_JT3]] ]
161 ; CHECK-NEXT: [[INC]] = add nsw i32 [[COUNT5]], 1
162 ; CHECK-NEXT: [[CMP_EXIT:%.*]] = icmp slt i32 [[INC]], [[NUM:%.*]]
163 ; CHECK-NEXT: br i1 [[CMP_EXIT]], label [[FOR_BODY]], label [[FOR_END:%.*]]
164 ; CHECK: for.inc.jt2:
165 ; CHECK-NEXT: [[STATE_NEXT_JT2]] = phi i32 [ [[STATE2_1_SI_UNFOLD_PHI_JT2]], [[STATE2_2_SI_UNFOLD_FALSE_JT2]] ], [ [[DOTSI_UNFOLD_PHI4_JT2]], [[STATE1_1_SI_UNFOLD_FALSE_JT2]] ]
166 ; CHECK-NEXT: [[INC_JT2]] = add nsw i32 undef, 1
167 ; CHECK-NEXT: [[CMP_EXIT_JT2:%.*]] = icmp slt i32 [[INC_JT2]], [[NUM]]
168 ; CHECK-NEXT: br i1 [[CMP_EXIT_JT2]], label [[FOR_BODY_JT2:%.*]], label [[FOR_END]]
169 ; CHECK: for.inc.jt1:
170 ; CHECK-NEXT: [[COUNT7:%.*]] = phi i32 [ [[COUNT6]], [[STATE1_1_SI_UNFOLD_TRUE_JT1]] ], [ [[COUNT]], [[STATE2_2_SI_UNFOLD_FALSE_JT1]] ], [ [[COUNT]], [[FOR_BODY]] ]
171 ; CHECK-NEXT: [[STATE_NEXT_JT1]] = phi i32 [ 1, [[FOR_BODY]] ], [ [[STATE2_1_SI_UNFOLD_PHI_JT1]], [[STATE2_2_SI_UNFOLD_FALSE_JT1]] ], [ [[DOTSI_UNFOLD_PHI3_JT1]], [[STATE1_1_SI_UNFOLD_TRUE_JT1]] ]
172 ; CHECK-NEXT: [[INC_JT1]] = add nsw i32 [[COUNT7]], 1
173 ; CHECK-NEXT: [[CMP_EXIT_JT1:%.*]] = icmp slt i32 [[INC_JT1]], [[NUM]]
174 ; CHECK-NEXT: br i1 [[CMP_EXIT_JT1]], label [[FOR_BODY_JT1]], label [[FOR_END]]
175 ; CHECK: for.inc.jt3:
176 ; CHECK-NEXT: [[COUNT8:%.*]] = phi i32 [ [[COUNT6]], [[STATE1_2_SI_UNFOLD_FALSE_JT3]] ], [ [[COUNT]], [[CASE2]] ]
177 ; CHECK-NEXT: [[STATE_NEXT_JT3]] = phi i32 [ 3, [[CASE2]] ], [ [[DOTSI_UNFOLD_PHI2_JT3]], [[STATE1_2_SI_UNFOLD_FALSE_JT3]] ]
178 ; CHECK-NEXT: [[INC_JT3]] = add nsw i32 [[COUNT8]], 1
179 ; CHECK-NEXT: [[CMP_EXIT_JT3:%.*]] = icmp slt i32 [[INC_JT3]], [[NUM]]
180 ; CHECK-NEXT: br i1 [[CMP_EXIT_JT3]], label [[FOR_BODY_JT3]], label [[FOR_END]]
182 ; CHECK-NEXT: ret i32 0
188 %count = phi i32 [ 0, %entry ], [ %inc, %for.inc ]
189 %state = phi i32 [ 1, %entry ], [ %state.next, %for.inc ]
190 switch i32 %state, label %for.inc [
196 %cmp.c1 = icmp slt i32 %count, 50
197 %cmp2.c1 = icmp slt i32 %count, 100
198 %state1.1 = select i1 %cmp.c1, i32 1, i32 2
199 %state1.2 = select i1 %cmp2.c1, i32 %state1.1, i32 3
203 %cmp.c2 = icmp slt i32 %count, 50
204 %cmp2.c2 = icmp sgt i32 %count, 100
205 %state2.1 = select i1 %cmp.c2, i32 1, i32 2
206 %state2.2 = select i1 %cmp2.c2, i32 3, i32 %state2.1
210 %state.next = phi i32 [ %state1.2, %case1 ], [ %state2.2, %case2 ], [ 1, %for.body ]
211 %inc = add nsw i32 %count, 1
212 %cmp.exit = icmp slt i32 %inc, %num
213 br i1 %cmp.exit, label %for.body, label %for.end
219 define i32 @test3(i32 %num) {
220 ; CHECK-LABEL: @test3(
222 ; CHECK-NEXT: br label [[FOR_BODY:%.*]]
224 ; CHECK-NEXT: [[COUNT:%.*]] = phi i32 [ 0, [[ENTRY:%.*]] ], [ [[INC:%.*]], [[FOR_INC:%.*]] ]
225 ; CHECK-NEXT: [[STATE:%.*]] = phi i32 [ 1, [[ENTRY]] ], [ [[STATE_NEXT:%.*]], [[FOR_INC]] ]
226 ; CHECK-NEXT: switch i32 [[STATE]], label [[FOR_INC_JT1:%.*]] [
227 ; CHECK-NEXT: i32 1, label [[CASE1:%.*]]
228 ; CHECK-NEXT: i32 2, label [[CASE2:%.*]]
230 ; CHECK: for.body.jt4:
231 ; CHECK-NEXT: [[COUNT_JT4:%.*]] = phi i32 [ [[INC_JT4:%.*]], [[FOR_INC_JT4:%.*]] ]
232 ; CHECK-NEXT: [[STATE_JT4:%.*]] = phi i32 [ [[STATE_NEXT_JT4:%.*]], [[FOR_INC_JT4]] ]
233 ; CHECK-NEXT: br label [[FOR_INC_JT1]]
234 ; CHECK: for.body.jt3:
235 ; CHECK-NEXT: [[COUNT_JT3:%.*]] = phi i32 [ [[INC_JT3:%.*]], [[FOR_INC_JT3:%.*]] ]
236 ; CHECK-NEXT: [[STATE_JT3:%.*]] = phi i32 [ [[STATE_NEXT_JT3:%.*]], [[FOR_INC_JT3]] ]
237 ; CHECK-NEXT: br label [[FOR_INC_JT1]]
238 ; CHECK: for.body.jt2:
239 ; CHECK-NEXT: [[COUNT_JT2:%.*]] = phi i32 [ [[INC_JT2:%.*]], [[FOR_INC_JT2:%.*]] ]
240 ; CHECK-NEXT: [[STATE_JT2:%.*]] = phi i32 [ [[STATE_NEXT_JT2:%.*]], [[FOR_INC_JT2]] ]
241 ; CHECK-NEXT: br label [[CASE2]]
242 ; CHECK: for.body.jt1:
243 ; CHECK-NEXT: [[COUNT_JT1:%.*]] = phi i32 [ [[INC_JT1:%.*]], [[FOR_INC_JT1]] ]
244 ; CHECK-NEXT: [[STATE_JT1:%.*]] = phi i32 [ [[STATE_NEXT_JT1:%.*]], [[FOR_INC_JT1]] ]
245 ; CHECK-NEXT: br label [[CASE1]]
247 ; CHECK-NEXT: [[COUNT6:%.*]] = phi i32 [ [[COUNT_JT1]], [[FOR_BODY_JT1:%.*]] ], [ [[COUNT]], [[FOR_BODY]] ]
248 ; CHECK-NEXT: br label [[FOR_INC_JT2]]
250 ; CHECK-NEXT: [[COUNT5:%.*]] = phi i32 [ [[COUNT_JT2]], [[FOR_BODY_JT2:%.*]] ], [ [[COUNT]], [[FOR_BODY]] ]
251 ; CHECK-NEXT: [[CMP_1:%.*]] = icmp slt i32 [[COUNT5]], 50
252 ; CHECK-NEXT: [[CMP_2:%.*]] = icmp slt i32 [[COUNT5]], 100
253 ; CHECK-NEXT: [[TMP0:%.*]] = and i32 [[COUNT5]], 1
254 ; CHECK-NEXT: [[CMP_3:%.*]] = icmp eq i32 [[TMP0]], 0
255 ; CHECK-NEXT: br i1 [[CMP_3]], label [[SEL_1_SI_UNFOLD_TRUE_JT1:%.*]], label [[SEL_2_SI_UNFOLD_TRUE_JT3:%.*]]
256 ; CHECK: sel.2.si.unfold.true:
257 ; CHECK-NEXT: br i1 [[CMP_2]], label [[SEL_3_SI_UNFOLD_FALSE:%.*]], label [[SEL_2_SI_UNFOLD_FALSE_JT4:%.*]]
258 ; CHECK: sel.2.si.unfold.true.jt3:
259 ; CHECK-NEXT: [[DOTSI_UNFOLD_PHI_JT3:%.*]] = phi i32 [ 3, [[CASE2]] ]
260 ; CHECK-NEXT: br i1 [[CMP_2]], label [[SEL_3_SI_UNFOLD_FALSE_JT3:%.*]], label [[SEL_2_SI_UNFOLD_FALSE:%.*]]
261 ; CHECK: sel.2.si.unfold.false:
262 ; CHECK-NEXT: [[DOTSI_UNFOLD_PHI1:%.*]] = phi i32 [ 4, [[SEL_2_SI_UNFOLD_TRUE_JT3]] ]
263 ; CHECK-NEXT: br label [[SEL_3_SI_UNFOLD_FALSE]]
264 ; CHECK: sel.2.si.unfold.false.jt4:
265 ; CHECK-NEXT: [[DOTSI_UNFOLD_PHI1_JT4:%.*]] = phi i32 [ 4, [[SEL_2_SI_UNFOLD_TRUE:%.*]] ]
266 ; CHECK-NEXT: br label [[SEL_3_SI_UNFOLD_FALSE_JT4:%.*]]
267 ; CHECK: sel.3.si.unfold.false:
268 ; CHECK-NEXT: [[SEL_2_SI_UNFOLD_PHI:%.*]] = phi i32 [ poison, [[SEL_2_SI_UNFOLD_TRUE]] ], [ [[DOTSI_UNFOLD_PHI1]], [[SEL_2_SI_UNFOLD_FALSE]] ]
269 ; CHECK-NEXT: br label [[FOR_INC]]
270 ; CHECK: sel.3.si.unfold.false.jt4:
271 ; CHECK-NEXT: [[SEL_2_SI_UNFOLD_PHI_JT4:%.*]] = phi i32 [ [[DOTSI_UNFOLD_PHI1_JT4]], [[SEL_2_SI_UNFOLD_FALSE_JT4]] ]
272 ; CHECK-NEXT: br label [[FOR_INC_JT4]]
273 ; CHECK: sel.3.si.unfold.false.jt3:
274 ; CHECK-NEXT: [[SEL_2_SI_UNFOLD_PHI_JT3:%.*]] = phi i32 [ [[DOTSI_UNFOLD_PHI_JT3]], [[SEL_2_SI_UNFOLD_TRUE_JT3]] ]
275 ; CHECK-NEXT: br label [[FOR_INC_JT3]]
276 ; CHECK: sel.1.si.unfold.true:
277 ; CHECK-NEXT: br i1 [[CMP_1]], label [[FOR_INC]], label [[SEL_1_SI_UNFOLD_FALSE_JT2:%.*]]
278 ; CHECK: sel.1.si.unfold.true.jt1:
279 ; CHECK-NEXT: [[DOTSI_UNFOLD_PHI2_JT1:%.*]] = phi i32 [ 1, [[CASE2]] ]
280 ; CHECK-NEXT: br i1 [[CMP_1]], label [[FOR_INC_JT1]], label [[SEL_1_SI_UNFOLD_FALSE:%.*]]
281 ; CHECK: sel.1.si.unfold.false:
282 ; CHECK-NEXT: [[DOTSI_UNFOLD_PHI3:%.*]] = phi i32 [ 2, [[SEL_1_SI_UNFOLD_TRUE_JT1]] ]
283 ; CHECK-NEXT: br label [[FOR_INC]]
284 ; CHECK: sel.1.si.unfold.false.jt2:
285 ; CHECK-NEXT: [[DOTSI_UNFOLD_PHI3_JT2:%.*]] = phi i32 [ 2, [[SEL_1_SI_UNFOLD_TRUE:%.*]] ]
286 ; CHECK-NEXT: br label [[FOR_INC_JT2]]
288 ; CHECK-NEXT: [[STATE_NEXT]] = phi i32 [ [[SEL_2_SI_UNFOLD_PHI]], [[SEL_3_SI_UNFOLD_FALSE]] ], [ poison, [[SEL_1_SI_UNFOLD_TRUE]] ], [ [[DOTSI_UNFOLD_PHI3]], [[SEL_1_SI_UNFOLD_FALSE]] ]
289 ; CHECK-NEXT: [[INC]] = add nsw i32 [[COUNT5]], 1
290 ; CHECK-NEXT: [[CMP_EXIT:%.*]] = icmp slt i32 [[INC]], [[NUM:%.*]]
291 ; CHECK-NEXT: br i1 [[CMP_EXIT]], label [[FOR_BODY]], label [[FOR_END:%.*]]
292 ; CHECK: for.inc.jt4:
293 ; CHECK-NEXT: [[STATE_NEXT_JT4]] = phi i32 [ [[SEL_2_SI_UNFOLD_PHI_JT4]], [[SEL_3_SI_UNFOLD_FALSE_JT4]] ]
294 ; CHECK-NEXT: [[INC_JT4]] = add nsw i32 undef, 1
295 ; CHECK-NEXT: [[CMP_EXIT_JT4:%.*]] = icmp slt i32 [[INC_JT4]], [[NUM]]
296 ; CHECK-NEXT: br i1 [[CMP_EXIT_JT4]], label [[FOR_BODY_JT4:%.*]], label [[FOR_END]]
297 ; CHECK: for.inc.jt3:
298 ; CHECK-NEXT: [[STATE_NEXT_JT3]] = phi i32 [ [[SEL_2_SI_UNFOLD_PHI_JT3]], [[SEL_3_SI_UNFOLD_FALSE_JT3]] ]
299 ; CHECK-NEXT: [[INC_JT3]] = add nsw i32 [[COUNT5]], 1
300 ; CHECK-NEXT: [[CMP_EXIT_JT3:%.*]] = icmp slt i32 [[INC_JT3]], [[NUM]]
301 ; CHECK-NEXT: br i1 [[CMP_EXIT_JT3]], label [[FOR_BODY_JT3:%.*]], label [[FOR_END]]
302 ; CHECK: for.inc.jt2:
303 ; CHECK-NEXT: [[STATE_NEXT_JT2]] = phi i32 [ 2, [[CASE1]] ], [ [[DOTSI_UNFOLD_PHI3_JT2]], [[SEL_1_SI_UNFOLD_FALSE_JT2]] ]
304 ; CHECK-NEXT: [[INC_JT2]] = add nsw i32 [[COUNT6]], 1
305 ; CHECK-NEXT: [[CMP_EXIT_JT2:%.*]] = icmp slt i32 [[INC_JT2]], [[NUM]]
306 ; CHECK-NEXT: br i1 [[CMP_EXIT_JT2]], label [[FOR_BODY_JT2]], label [[FOR_END]]
307 ; CHECK: for.inc.jt1:
308 ; CHECK-NEXT: [[COUNT4:%.*]] = phi i32 [ [[COUNT_JT4]], [[FOR_BODY_JT4]] ], [ [[COUNT_JT3]], [[FOR_BODY_JT3]] ], [ [[COUNT5]], [[SEL_1_SI_UNFOLD_TRUE_JT1]] ], [ [[COUNT]], [[FOR_BODY]] ]
309 ; CHECK-NEXT: [[STATE_NEXT_JT1]] = phi i32 [ 1, [[FOR_BODY]] ], [ 1, [[FOR_BODY_JT3]] ], [ 1, [[FOR_BODY_JT4]] ], [ [[DOTSI_UNFOLD_PHI2_JT1]], [[SEL_1_SI_UNFOLD_TRUE_JT1]] ]
310 ; CHECK-NEXT: [[INC_JT1]] = add nsw i32 [[COUNT4]], 1
311 ; CHECK-NEXT: [[CMP_EXIT_JT1:%.*]] = icmp slt i32 [[INC_JT1]], [[NUM]]
312 ; CHECK-NEXT: br i1 [[CMP_EXIT_JT1]], label [[FOR_BODY_JT1]], label [[FOR_END]]
314 ; CHECK-NEXT: ret i32 0
320 %count = phi i32 [ 0, %entry ], [ %inc, %for.inc ]
321 %state = phi i32 [ 1, %entry ], [ %state.next, %for.inc ]
322 switch i32 %state, label %for.inc [
331 %cmp.1 = icmp slt i32 %count, 50
332 %cmp.2 = icmp slt i32 %count, 100
333 %0 = and i32 %count, 1
334 %cmp.3 = icmp eq i32 %0, 0
335 %sel.1 = select i1 %cmp.1, i32 1, i32 2
336 %sel.2 = select i1 %cmp.2, i32 3, i32 4
337 %sel.3 = select i1 %cmp.3, i32 %sel.1, i32 %sel.2
341 %state.next = phi i32 [ %sel.3, %case2 ], [ 1, %for.body ], [ 2, %case1 ]
342 %inc = add nsw i32 %count, 1
343 %cmp.exit = icmp slt i32 %inc, %num
344 br i1 %cmp.exit, label %for.body, label %for.end
350 define void @select_coming_elsewhere(i1 %cond, i16 %a, i16 %b) {
351 ; CHECK-LABEL: @select_coming_elsewhere(
353 ; CHECK-NEXT: [[DIV:%.*]] = select i1 [[COND:%.*]], i16 [[A:%.*]], i16 [[B:%.*]]
354 ; CHECK-NEXT: br label [[FOR_COND:%.*]]
356 ; CHECK-NEXT: [[E_ADDR_0:%.*]] = phi i16 [ 0, [[ENTRY:%.*]] ], [ [[DIV]], [[LOR_END:%.*]] ]
357 ; CHECK-NEXT: switch i16 [[E_ADDR_0]], label [[LOR_END]] [
360 ; CHECK-NEXT: br label [[FOR_COND]]
363 %div = select i1 %cond, i16 %a, i16 %b
366 for.cond: ; preds = %lor.end, %entry
367 %e.addr.0 = phi i16 [ 0, %entry ], [ %div, %lor.end ]
368 switch i16 %e.addr.0, label %lor.end [
371 lor.end: ; preds = %for.cond
375 define void @pr65222(i32 %flags, i1 %cmp, i1 %tobool.not) {
376 ; CHECK-LABEL: @pr65222(
378 ; CHECK-NEXT: br label [[WHILE_COND:%.*]]
380 ; CHECK-NEXT: br i1 [[CMP:%.*]], label [[THEN:%.*]], label [[IF_END:%.*]]
382 ; CHECK-NEXT: br i1 [[TOBOOL_NOT:%.*]], label [[COND1_SI_UNFOLD_TRUE:%.*]], label [[COND_SI_UNFOLD_TRUE:%.*]]
383 ; CHECK: cond.si.unfold.true:
384 ; CHECK-NEXT: [[DOTSI_UNFOLD_PHI:%.*]] = phi i32 [ 2, [[THEN]] ]
385 ; CHECK-NEXT: br i1 [[CMP]], label [[TOUNFOLD_SI_UNFOLD_FALSE:%.*]], label [[COND_SI_UNFOLD_FALSE:%.*]]
386 ; CHECK: cond.si.unfold.false:
387 ; CHECK-NEXT: [[DOTSI_UNFOLD_PHI1:%.*]] = phi i32 [ 0, [[COND_SI_UNFOLD_TRUE]] ]
388 ; CHECK-NEXT: br label [[TOUNFOLD_SI_UNFOLD_FALSE]]
389 ; CHECK: tounfold.si.unfold.false:
390 ; CHECK-NEXT: [[COND_SI_UNFOLD_PHI:%.*]] = phi i32 [ [[DOTSI_UNFOLD_PHI]], [[COND_SI_UNFOLD_TRUE]] ], [ [[DOTSI_UNFOLD_PHI1]], [[COND_SI_UNFOLD_FALSE]] ]
391 ; CHECK-NEXT: br label [[IF_END]]
392 ; CHECK: cond1.si.unfold.true:
393 ; CHECK-NEXT: [[DOTSI_UNFOLD_PHI2:%.*]] = phi i32 [ 3, [[THEN]] ]
394 ; CHECK-NEXT: br i1 [[CMP]], label [[IF_END]], label [[COND1_SI_UNFOLD_FALSE:%.*]]
395 ; CHECK: cond1.si.unfold.false:
396 ; CHECK-NEXT: [[DOTSI_UNFOLD_PHI3:%.*]] = phi i32 [ 1, [[COND1_SI_UNFOLD_TRUE]] ]
397 ; CHECK-NEXT: br label [[IF_END]]
399 ; CHECK-NEXT: [[UNFOLDED:%.*]] = phi i32 [ [[FLAGS:%.*]], [[WHILE_COND]] ], [ [[COND_SI_UNFOLD_PHI]], [[TOUNFOLD_SI_UNFOLD_FALSE]] ], [ [[DOTSI_UNFOLD_PHI2]], [[COND1_SI_UNFOLD_TRUE]] ], [ [[DOTSI_UNFOLD_PHI3]], [[COND1_SI_UNFOLD_FALSE]] ]
400 ; CHECK-NEXT: [[OTHER:%.*]] = phi i32 [ [[FLAGS]], [[WHILE_COND]] ], [ 0, [[TOUNFOLD_SI_UNFOLD_FALSE]] ], [ 0, [[COND1_SI_UNFOLD_TRUE]] ], [ 0, [[COND1_SI_UNFOLD_FALSE]] ]
401 ; CHECK-NEXT: switch i32 [[UNFOLDED]], label [[UNREACHABLE:%.*]] [
402 ; CHECK-NEXT: i32 0, label [[SW_BB:%.*]]
404 ; CHECK: unreachable:
405 ; CHECK-NEXT: unreachable
407 ; CHECK-NEXT: br label [[WHILE_COND]]
412 while.cond: ; preds = %sw.bb147, %if.end, %entry
413 br i1 %cmp, label %then, label %if.end
415 then: ; preds = %while.cond
416 %cond = select i1 %cmp, i32 2, i32 0
417 %cond1 = select i1 %cmp, i32 3, i32 1
418 %tounfold = select i1 %tobool.not, i32 %cond1, i32 %cond
421 if.end: ; preds = %then, %while.cond
422 %unfolded = phi i32 [ %tounfold, %then ], [ %flags, %while.cond ]
423 %other = phi i32 [ 0, %then ], [ %flags, %while.cond ]
424 switch i32 %unfolded, label %unreachable [
431 sw.bb: ; preds = %if.end