1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2 ; RUN: opt < %s -fix-irreducible -S | FileCheck %s -check-prefix=CHECK
4 define void @nested_irr_top_level(i1 %Pred0, i1 %Pred1, i1 %Pred2, i1 %Pred3, i1 %Pred4, i1 %Pred5) {
5 ; CHECK-LABEL: @nested_irr_top_level(
7 ; CHECK-NEXT: br label [[IRR_GUARD:%.*]]
9 ; CHECK-NEXT: br label [[IRR_GUARD1:%.*]]
11 ; CHECK-NEXT: br i1 [[PRED2:%.*]], label [[IRR_GUARD1]], label [[A3:%.*]]
13 ; CHECK-NEXT: br i1 [[PRED3:%.*]], label [[IRR_GUARD1]], label [[A3]]
15 ; CHECK-NEXT: br i1 [[PRED4:%.*]], label [[IRR_GUARD]], label [[EXIT:%.*]]
17 ; CHECK-NEXT: br i1 [[PRED5:%.*]], label [[IRR_GUARD]], label [[EXIT]]
19 ; CHECK-NEXT: ret void
21 ; CHECK-NEXT: [[GUARD_A1:%.*]] = phi i1 [ true, [[A2:%.*]] ], [ [[PRED0:%.*]], [[ENTRY:%.*]] ], [ false, [[A3]] ]
22 ; CHECK-NEXT: br i1 [[GUARD_A1]], label [[A1:%.*]], label [[A2]]
24 ; CHECK-NEXT: [[GUARD_B1:%.*]] = phi i1 [ true, [[B2:%.*]] ], [ [[PRED1:%.*]], [[A1]] ], [ false, [[B1:%.*]] ]
25 ; CHECK-NEXT: br i1 [[GUARD_B1]], label [[B1]], label [[B2]]
28 br i1 %Pred0, label %A1, label %A2
31 br i1 %Pred1, label %B1, label %B2
34 br i1 %Pred2, label %B2, label %A3
37 br i1 %Pred3, label %B1, label %A3
40 br i1 %Pred4, label %A2, label %exit
43 br i1 %Pred5, label %A1, label %exit
49 define void @nested_irr_in_loop(i1 %Pred0, i1 %Pred1, i1 %Pred2, i1 %Pred3, i1 %Pred4, i1 %Pred5, i1 %Pred6) {
50 ; CHECK-LABEL: @nested_irr_in_loop(
52 ; CHECK-NEXT: br label [[H1:%.*]]
54 ; CHECK-NEXT: br label [[IRR_GUARD:%.*]]
56 ; CHECK-NEXT: br label [[IRR_GUARD1:%.*]]
58 ; CHECK-NEXT: br i1 [[PRED2:%.*]], label [[IRR_GUARD1]], label [[A3:%.*]]
60 ; CHECK-NEXT: br i1 [[PRED3:%.*]], label [[IRR_GUARD1]], label [[A3]]
62 ; CHECK-NEXT: br i1 [[PRED4:%.*]], label [[IRR_GUARD]], label [[L1:%.*]]
64 ; CHECK-NEXT: br i1 [[PRED5:%.*]], label [[IRR_GUARD]], label [[L1]]
66 ; CHECK-NEXT: br i1 [[PRED6:%.*]], label [[EXIT:%.*]], label [[H1]]
68 ; CHECK-NEXT: ret void
70 ; CHECK-NEXT: [[GUARD_A1:%.*]] = phi i1 [ true, [[A2:%.*]] ], [ [[PRED0:%.*]], [[H1]] ], [ false, [[A3]] ]
71 ; CHECK-NEXT: br i1 [[GUARD_A1]], label [[A1:%.*]], label [[A2]]
73 ; CHECK-NEXT: [[GUARD_B1:%.*]] = phi i1 [ true, [[B2:%.*]] ], [ [[PRED1:%.*]], [[A1]] ], [ false, [[B1:%.*]] ]
74 ; CHECK-NEXT: br i1 [[GUARD_B1]], label [[B1]], label [[B2]]
80 br i1 %Pred0, label %A1, label %A2
83 br i1 %Pred1, label %B1, label %B2
86 br i1 %Pred2, label %B2, label %A3
89 br i1 %Pred3, label %B1, label %A3
92 br i1 %Pred4, label %A2, label %L1
95 br i1 %Pred5, label %A1, label %L1
98 br i1 %Pred6, label %exit, label %H1
104 define void @loop_in_irr(i1 %Pred0, i1 %Pred1, i1 %Pred2) {
105 ; CHECK-LABEL: @loop_in_irr(
107 ; CHECK-NEXT: br label [[IRR_GUARD:%.*]]
109 ; CHECK-NEXT: br label [[H1:%.*]]
111 ; CHECK-NEXT: br label [[L1:%.*]]
113 ; CHECK-NEXT: br i1 [[PRED1:%.*]], label [[H1]], label [[A3:%.*]]
115 ; CHECK-NEXT: br i1 [[PRED2:%.*]], label [[IRR_GUARD]], label [[EXIT:%.*]]
117 ; CHECK-NEXT: br label [[IRR_GUARD]]
119 ; CHECK-NEXT: ret void
121 ; CHECK-NEXT: [[GUARD_A1:%.*]] = phi i1 [ true, [[A2:%.*]] ], [ [[PRED0:%.*]], [[ENTRY:%.*]] ], [ false, [[A3]] ]
122 ; CHECK-NEXT: br i1 [[GUARD_A1]], label [[A1:%.*]], label [[A2]]
125 br i1 %Pred0, label %A1, label %A2
134 br i1 %Pred1, label %H1, label %A3
137 br i1 %Pred2, label %A2, label %exit
146 define void @loop_in_irr_shared_header(i1 %Pred0, i1 %Pred1, i1 %Pred2) {
147 ; CHECK-LABEL: @loop_in_irr_shared_header(
149 ; CHECK-NEXT: br label [[IRR_GUARD:%.*]]
151 ; CHECK-NEXT: br label [[L1:%.*]]
153 ; CHECK-NEXT: br i1 [[PRED1:%.*]], label [[IRR_GUARD]], label [[A3:%.*]]
155 ; CHECK-NEXT: br i1 [[PRED2:%.*]], label [[IRR_GUARD]], label [[EXIT:%.*]]
157 ; CHECK-NEXT: br label [[IRR_GUARD]]
159 ; CHECK-NEXT: ret void
161 ; CHECK-NEXT: [[GUARD_H1:%.*]] = phi i1 [ true, [[A2:%.*]] ], [ true, [[L1]] ], [ [[PRED0:%.*]], [[ENTRY:%.*]] ], [ false, [[A3]] ]
162 ; CHECK-NEXT: br i1 [[GUARD_H1]], label [[H1:%.*]], label [[A2]]
165 br i1 %Pred0, label %H1, label %A2
171 br i1 %Pred1, label %H1, label %A3
174 br i1 %Pred2, label %A2, label %exit
183 define void @siblings_top_level(i1 %Pred0, i1 %Pred1, i1 %Pred2, i1 %Pred3, i1 %Pred4, i1 %Pred5, i1 %Pred6) {
184 ; CHECK-LABEL: @siblings_top_level(
186 ; CHECK-NEXT: br i1 [[PRED0:%.*]], label [[H1:%.*]], label [[FORK1:%.*]]
188 ; CHECK-NEXT: br label [[IRR_GUARD1:%.*]]
190 ; CHECK-NEXT: br label [[IRR_GUARD1]]
192 ; CHECK-NEXT: br i1 [[PRED2:%.*]], label [[IRR_GUARD1]], label [[L1:%.*]]
194 ; CHECK-NEXT: br i1 [[PRED3:%.*]], label [[H1]], label [[EXIT:%.*]]
196 ; CHECK-NEXT: br label [[IRR_GUARD:%.*]]
198 ; CHECK-NEXT: br label [[H2:%.*]]
200 ; CHECK-NEXT: br label [[L2:%.*]]
202 ; CHECK-NEXT: br i1 [[PRED5:%.*]], label [[H2]], label [[IRR_GUARD]]
204 ; CHECK-NEXT: br i1 [[PRED6:%.*]], label [[IRR_GUARD]], label [[EXIT]]
206 ; CHECK-NEXT: ret void
208 ; CHECK-NEXT: [[GUARD_B1:%.*]] = phi i1 [ true, [[B2:%.*]] ], [ [[PRED4:%.*]], [[FORK1]] ], [ false, [[L2]] ]
209 ; CHECK-NEXT: br i1 [[GUARD_B1]], label [[B1:%.*]], label [[B2]]
211 ; CHECK-NEXT: [[GUARD_A1:%.*]] = phi i1 [ true, [[A2:%.*]] ], [ [[PRED1:%.*]], [[H1]] ], [ false, [[A1:%.*]] ]
212 ; CHECK-NEXT: br i1 [[GUARD_A1]], label [[A1]], label [[A2]]
215 br i1 %Pred0, label %H1, label %fork1
218 br i1 %Pred1, label %A1, label %A2
224 br i1 %Pred2, label %A1, label %L1
227 br i1 %Pred3, label %H1, label %exit
230 br i1 %Pred4, label %B1, label %B2
239 br i1 %Pred5, label %H2, label %B2
242 br i1 %Pred6, label %B1, label %exit
248 define void @siblings_in_loop(i1 %Pred0, i1 %Pred1, i1 %Pred2, i1 %Pred3, i1 %Pred4, i1 %Pred5, i1 %Pred6, i1 %Pred7) {
249 ; CHECK-LABEL: @siblings_in_loop(
251 ; CHECK-NEXT: br label [[H0:%.*]]
253 ; CHECK-NEXT: br i1 [[PRED0:%.*]], label [[H1:%.*]], label [[FORK1:%.*]]
255 ; CHECK-NEXT: br label [[IRR_GUARD1:%.*]]
257 ; CHECK-NEXT: br label [[IRR_GUARD1]]
259 ; CHECK-NEXT: br i1 [[PRED2:%.*]], label [[IRR_GUARD1]], label [[L1:%.*]]
261 ; CHECK-NEXT: br i1 [[PRED3:%.*]], label [[H1]], label [[L0:%.*]]
263 ; CHECK-NEXT: br label [[IRR_GUARD:%.*]]
265 ; CHECK-NEXT: br label [[H2:%.*]]
267 ; CHECK-NEXT: br label [[L2:%.*]]
269 ; CHECK-NEXT: br i1 [[PRED5:%.*]], label [[H2]], label [[IRR_GUARD]]
271 ; CHECK-NEXT: br i1 [[PRED6:%.*]], label [[IRR_GUARD]], label [[L0]]
273 ; CHECK-NEXT: br i1 [[PRED7:%.*]], label [[EXIT:%.*]], label [[H0]]
275 ; CHECK-NEXT: ret void
277 ; CHECK-NEXT: [[GUARD_B1:%.*]] = phi i1 [ true, [[B2:%.*]] ], [ [[PRED4:%.*]], [[FORK1]] ], [ false, [[L2]] ]
278 ; CHECK-NEXT: br i1 [[GUARD_B1]], label [[B1:%.*]], label [[B2]]
280 ; CHECK-NEXT: [[GUARD_A1:%.*]] = phi i1 [ true, [[A2:%.*]] ], [ [[PRED1:%.*]], [[H1]] ], [ false, [[A1:%.*]] ]
281 ; CHECK-NEXT: br i1 [[GUARD_A1]], label [[A1]], label [[A2]]
287 br i1 %Pred0, label %H1, label %fork1
290 br i1 %Pred1, label %A1, label %A2
296 br i1 %Pred2, label %A1, label %L1
299 br i1 %Pred3, label %H1, label %L0
302 br i1 %Pred4, label %B1, label %B2
311 br i1 %Pred5, label %H2, label %B2
314 br i1 %Pred6, label %B1, label %L0
317 br i1 %Pred7, label %exit, label %H0
323 define void @irreducible_mountain_bug(i1 %Pred0, i1 %Pred1, i1 %Pred2, i1 %Pred3, i1 %Pred4, i1 %Pred5, i1 %Pred6, i1 %Pred7, i1 %Pred8, i1 %Pred9, i1 %Pred10, i1 %Pred11, i1 %Pred12, i1 %Pred13) {
324 ; CHECK-LABEL: @irreducible_mountain_bug(
326 ; CHECK-NEXT: br i1 [[PRED0:%.*]], label [[IF_END:%.*]], label [[IF_THEN:%.*]]
328 ; CHECK-NEXT: br i1 [[PRED1:%.*]], label [[IF_THEN7:%.*]], label [[IF_ELSE:%.*]]
330 ; CHECK-NEXT: br label [[IF_END16:%.*]]
332 ; CHECK-NEXT: br label [[IF_END16]]
334 ; CHECK-NEXT: br i1 [[PRED2:%.*]], label [[WHILE_COND_PREHEADER:%.*]], label [[IF_THEN39:%.*]]
335 ; CHECK: while.cond.preheader:
336 ; CHECK-NEXT: br label [[WHILE_COND:%.*]]
338 ; CHECK-NEXT: br i1 [[PRED3:%.*]], label [[IRR_GUARD:%.*]], label [[LOR_RHS:%.*]]
339 ; CHECK: cond.true49:
340 ; CHECK-NEXT: br i1 [[PRED4:%.*]], label [[IF_THEN69:%.*]], label [[WHILE_BODY63:%.*]]
341 ; CHECK: while.body63:
342 ; CHECK-NEXT: br i1 [[PRED5:%.*]], label [[EXIT:%.*]], label [[WHILE_COND47:%.*]]
343 ; CHECK: while.cond47:
344 ; CHECK-NEXT: br label [[IRR_GUARD]]
346 ; CHECK-NEXT: br i1 [[PRED7:%.*]], label [[WHILE_BODY63]], label [[WHILE_COND]]
348 ; CHECK-NEXT: br i1 [[PRED8:%.*]], label [[EXIT]], label [[WHILE_COND]]
350 ; CHECK-NEXT: br i1 [[PRED9:%.*]], label [[IRR_GUARD]], label [[WHILE_END76:%.*]]
351 ; CHECK: while.end76:
352 ; CHECK-NEXT: br label [[EXIT]]
354 ; CHECK-NEXT: br i1 [[PRED10:%.*]], label [[EXIT]], label [[IF_END_I145:%.*]]
355 ; CHECK: if.end.i145:
356 ; CHECK-NEXT: br i1 [[PRED11:%.*]], label [[EXIT]], label [[IF_END8_I149:%.*]]
357 ; CHECK: if.end8.i149:
358 ; CHECK-NEXT: br label [[EXIT]]
360 ; CHECK-NEXT: br i1 [[PRED12:%.*]], label [[EXIT]], label [[IF_END_I:%.*]]
362 ; CHECK-NEXT: br i1 [[PRED13:%.*]], label [[EXIT]], label [[IF_END8_I:%.*]]
364 ; CHECK-NEXT: br label [[EXIT]]
366 ; CHECK-NEXT: ret void
368 ; CHECK-NEXT: [[GUARD_COND_TRUE49:%.*]] = phi i1 [ [[PRED6:%.*]], [[WHILE_COND47]] ], [ true, [[WHILE_COND]] ], [ false, [[LOR_RHS]] ]
369 ; CHECK-NEXT: br i1 [[GUARD_COND_TRUE49]], label [[COND_TRUE49:%.*]], label [[COND_END61:%.*]]
372 br i1 %Pred0, label %if.end, label %if.then
375 br i1 %Pred1, label %if.then7, label %if.else
384 br i1 %Pred2, label %while.cond.preheader, label %if.then39
386 while.cond.preheader:
390 br i1 %Pred3, label %cond.true49, label %lor.rhs
393 br i1 %Pred4, label %if.then69, label %while.body63
396 br i1 %Pred5, label %exit, label %while.cond47
399 br i1 %Pred6, label %cond.true49, label %cond.end61
402 br i1 %Pred7, label %while.body63, label %while.cond
405 br i1 %Pred8, label %exit, label %while.cond
408 br i1 %Pred9, label %cond.end61, label %while.end76
414 br i1 %Pred10, label %exit, label %if.end.i145
417 br i1 %Pred11, label %exit, label %if.end8.i149
423 br i1 %Pred12, label %exit, label %if.end.i
426 br i1 %Pred13, label %exit, label %if.end8.i