1 ; RUN: opt -passes='loop(simple-loop-unswitch),verify<loops>' -S < %s | FileCheck %s
2 ; RUN: opt -verify-memoryssa -passes='loop-mssa(simple-loop-unswitch),verify<loops>' -S < %s | FileCheck %s
4 declare void @some_func() noreturn
5 declare void @sink(i32)
8 declare i32 @cond.i32()
10 ; This test contains two trivial unswitch condition in one loop.
11 ; LoopUnswitch pass should be able to unswitch the second one
12 ; after unswitching the first one.
13 define i32 @test1(i32* %var, i1 %cond1, i1 %cond2) {
14 ; CHECK-LABEL: @test1(
18 ; CHECK-NEXT: br i1 %{{.*}}, label %entry.split, label %loop_exit.split
21 ; CHECK-NEXT: br i1 %{{.*}}, label %entry.split.split, label %loop_exit
23 ; CHECK: entry.split.split:
24 ; CHECK-NEXT: br label %loop_begin
27 br i1 %cond1, label %continue, label %loop_exit ; first trivial condition
29 ; CHECK-NEXT: br label %continue
32 %var_val = load i32, i32* %var
33 br i1 %cond2, label %do_something, label %loop_exit ; second trivial condition
36 ; CHECK-NEXT: br label %do_something
39 call void @some_func() noreturn nounwind
41 ; CHECK: do_something:
43 ; CHECK-NEXT: br label %loop_begin
48 ; CHECK-NEXT: br label %loop_exit.split
50 ; CHECK: loop_exit.split:
54 ; Test for two trivially unswitchable switches.
55 define i32 @test3(i32* %var, i32 %cond1, i32 %cond2) {
56 ; CHECK-LABEL: @test3(
60 ; CHECK-NEXT: switch i32 %cond1, label %entry.split [
61 ; CHECK-NEXT: i32 0, label %loop_exit1
65 ; CHECK-NEXT: switch i32 %cond2, label %loop_exit2 [
66 ; CHECK-NEXT: i32 42, label %loop_exit2
67 ; CHECK-NEXT: i32 0, label %entry.split.split
70 ; CHECK: entry.split.split:
71 ; CHECK-NEXT: br label %loop_begin
74 switch i32 %cond1, label %continue [
75 i32 0, label %loop_exit1
78 ; CHECK-NEXT: br label %continue
81 %var_val = load i32, i32* %var
82 switch i32 %cond2, label %loop_exit2 [
83 i32 0, label %do_something
84 i32 42, label %loop_exit2
88 ; CHECK-NEXT: br label %do_something
91 call void @some_func() noreturn nounwind
93 ; CHECK: do_something:
95 ; CHECK-NEXT: br label %loop_begin
107 ; We shouldn't have any unreachable blocks here because the unswitched switches
108 ; turn into branches instead.
109 ; CHECK-NOT: unreachable
112 ; Test for a trivially unswitchable switch with multiple exiting cases and
113 ; multiple looping cases.
114 define i32 @test4(i32* %var, i32 %cond1, i32 %cond2) {
115 ; CHECK-LABEL: @test4(
119 ; CHECK-NEXT: switch i32 %cond2, label %loop_exit2 [
120 ; CHECK-NEXT: i32 13, label %loop_exit1
121 ; CHECK-NEXT: i32 42, label %loop_exit3
122 ; CHECK-NEXT: i32 0, label %entry.split
123 ; CHECK-NEXT: i32 1, label %entry.split
124 ; CHECK-NEXT: i32 2, label %entry.split
127 ; CHECK: entry.split:
128 ; CHECK-NEXT: br label %loop_begin
131 %var_val = load i32, i32* %var
132 switch i32 %cond2, label %loop_exit2 [
135 i32 13, label %loop_exit1
137 i32 42, label %loop_exit3
141 ; CHECK-NEXT: switch i32 %cond2, label %loop2 [
142 ; CHECK-NEXT: i32 0, label %loop0
143 ; CHECK-NEXT: i32 1, label %loop1
147 call void @some_func() noreturn nounwind
151 ; CHECK-NEXT: br label %loop_latch
154 call void @some_func() noreturn nounwind
158 ; CHECK-NEXT: br label %loop_latch
161 call void @some_func() noreturn nounwind
165 ; CHECK-NEXT: br label %loop_latch
170 ; CHECK-NEXT: br label %loop_begin
188 ; This test contains a trivially unswitchable branch with an LCSSA phi node in
190 define i32 @test5(i1 %cond1, i32 %x, i32 %y) {
191 ; CHECK-LABEL: @test5(
195 ; CHECK-NEXT: br i1 %{{.*}}, label %entry.split, label %loop_exit
197 ; CHECK: entry.split:
198 ; CHECK-NEXT: br label %loop_begin
201 br i1 %cond1, label %latch, label %loop_exit
203 ; CHECK-NEXT: br label %latch
206 call void @some_func() noreturn nounwind
210 ; CHECK-NEXT: br label %loop_begin
213 %result1 = phi i32 [ %x, %loop_begin ]
214 %result2 = phi i32 [ %y, %loop_begin ]
215 %result = add i32 %result1, %result2
218 ; CHECK-NEXT: %[[R1:.*]] = phi i32 [ %x, %entry ]
219 ; CHECK-NEXT: %[[R2:.*]] = phi i32 [ %y, %entry ]
220 ; CHECK-NEXT: %[[R:.*]] = add i32 %[[R1]], %[[R2]]
221 ; CHECK-NEXT: ret i32 %[[R]]
224 ; This test contains a trivially unswitchable branch with a real phi node in LCSSA
225 ; position in a shared exit block where a different path through the loop
226 ; produces a non-invariant input to the PHI node.
227 define i32 @test6(i32* %var, i1 %cond1, i1 %cond2, i32 %x, i32 %y) {
228 ; CHECK-LABEL: @test6(
232 ; CHECK-NEXT: br i1 %{{.*}}, label %entry.split, label %loop_exit.split
234 ; CHECK: entry.split:
235 ; CHECK-NEXT: br label %loop_begin
238 br i1 %cond1, label %continue, label %loop_exit
240 ; CHECK-NEXT: br label %continue
243 %var_val = load i32, i32* %var
244 br i1 %cond2, label %latch, label %loop_exit
247 ; CHECK-NEXT: br i1 %cond2, label %latch, label %loop_exit
250 call void @some_func() noreturn nounwind
254 ; CHECK-NEXT: br label %loop_begin
257 %result1 = phi i32 [ %x, %loop_begin ], [ %var_val, %continue ]
258 %result2 = phi i32 [ %var_val, %continue ], [ %y, %loop_begin ]
259 %result = add i32 %result1, %result2
262 ; CHECK-NEXT: %[[R1:.*]] = phi i32 [ %var_val, %continue ]
263 ; CHECK-NEXT: %[[R2:.*]] = phi i32 [ %var_val, %continue ]
264 ; CHECK-NEXT: br label %loop_exit.split
266 ; CHECK: loop_exit.split:
267 ; CHECK-NEXT: %[[R1S:.*]] = phi i32 [ %x, %entry ], [ %[[R1]], %loop_exit ]
268 ; CHECK-NEXT: %[[R2S:.*]] = phi i32 [ %y, %entry ], [ %[[R2]], %loop_exit ]
269 ; CHECK-NEXT: %[[R:.*]] = add i32 %[[R1S]], %[[R2S]]
270 ; CHECK-NEXT: ret i32 %[[R]]
273 ; This test contains a trivially unswitchable switch with an LCSSA phi node in
275 define i32 @test7(i32 %cond1, i32 %x, i32 %y) {
276 ; CHECK-LABEL: @test7(
280 ; CHECK-NEXT: switch i32 %cond1, label %entry.split [
281 ; CHECK-NEXT: i32 0, label %loop_exit
282 ; CHECK-NEXT: i32 1, label %loop_exit
285 ; CHECK: entry.split:
286 ; CHECK-NEXT: br label %loop_begin
289 switch i32 %cond1, label %latch [
290 i32 0, label %loop_exit
291 i32 1, label %loop_exit
294 ; CHECK-NEXT: br label %latch
297 call void @some_func() noreturn nounwind
301 ; CHECK-NEXT: br label %loop_begin
304 %result1 = phi i32 [ %x, %loop_begin ], [ %x, %loop_begin ]
305 %result2 = phi i32 [ %y, %loop_begin ], [ %y, %loop_begin ]
306 %result = add i32 %result1, %result2
309 ; CHECK-NEXT: %[[R1:.*]] = phi i32 [ %x, %entry ], [ %x, %entry ]
310 ; CHECK-NEXT: %[[R2:.*]] = phi i32 [ %y, %entry ], [ %y, %entry ]
311 ; CHECK-NEXT: %[[R:.*]] = add i32 %[[R1]], %[[R2]]
312 ; CHECK-NEXT: ret i32 %[[R]]
315 ; This test contains a trivially unswitchable switch with a real phi node in
316 ; LCSSA position in a shared exit block where a different path through the loop
317 ; produces a non-invariant input to the PHI node.
318 define i32 @test8(i32* %var, i32 %cond1, i32 %cond2, i32 %x, i32 %y) {
319 ; CHECK-LABEL: @test8(
323 ; CHECK-NEXT: switch i32 %cond1, label %entry.split [
324 ; CHECK-NEXT: i32 0, label %loop_exit.split
325 ; CHECK-NEXT: i32 1, label %loop_exit2
326 ; CHECK-NEXT: i32 2, label %loop_exit.split
329 ; CHECK: entry.split:
330 ; CHECK-NEXT: br label %loop_begin
333 switch i32 %cond1, label %continue [
334 i32 0, label %loop_exit
335 i32 1, label %loop_exit2
336 i32 2, label %loop_exit
339 ; CHECK-NEXT: br label %continue
342 %var_val = load i32, i32* %var
343 switch i32 %cond2, label %latch [
344 i32 0, label %loop_exit
348 ; CHECK-NEXT: switch i32 %cond2, label %latch [
349 ; CHECK-NEXT: i32 0, label %loop_exit
353 call void @some_func() noreturn nounwind
357 ; CHECK-NEXT: br label %loop_begin
360 %result1.1 = phi i32 [ %x, %loop_begin ], [ %x, %loop_begin ], [ %var_val, %continue ]
361 %result1.2 = phi i32 [ %var_val, %continue ], [ %y, %loop_begin ], [ %y, %loop_begin ]
362 %result1 = add i32 %result1.1, %result1.2
365 ; CHECK-NEXT: %[[R1:.*]] = phi i32 [ %var_val, %continue ]
366 ; CHECK-NEXT: %[[R2:.*]] = phi i32 [ %var_val, %continue ]
367 ; CHECK-NEXT: br label %loop_exit.split
369 ; CHECK: loop_exit.split:
370 ; CHECK-NEXT: %[[R1S:.*]] = phi i32 [ %x, %entry ], [ %x, %entry ], [ %[[R1]], %loop_exit ]
371 ; CHECK-NEXT: %[[R2S:.*]] = phi i32 [ %y, %entry ], [ %y, %entry ], [ %[[R2]], %loop_exit ]
372 ; CHECK-NEXT: %[[R:.*]] = add i32 %[[R1S]], %[[R2S]]
373 ; CHECK-NEXT: ret i32 %[[R]]
376 %result2.1 = phi i32 [ %x, %loop_begin ]
377 %result2.2 = phi i32 [ %y, %loop_begin ]
378 %result2 = add i32 %result2.1, %result2.2
381 ; CHECK-NEXT: %[[R1:.*]] = phi i32 [ %x, %entry ]
382 ; CHECK-NEXT: %[[R2:.*]] = phi i32 [ %y, %entry ]
383 ; CHECK-NEXT: %[[R:.*]] = add i32 %[[R1]], %[[R2]]
384 ; CHECK-NEXT: ret i32 %[[R]]
387 ; This test, extracted from the LLVM test suite, has an interesting dominator
388 ; tree to update as there are edges to sibling domtree nodes within child
389 ; domtree nodes of the unswitched node.
390 define void @xgets(i1 %cond1, i1* %cond2.ptr) {
391 ; CHECK-LABEL: @xgets(
393 br label %for.cond.preheader
395 ; CHECK-NEXT: br label %for.cond.preheader
399 ; CHECK: for.cond.preheader:
400 ; CHECK-NEXT: br i1 %cond1, label %for.cond.preheader.split, label %if.end17.thread.loopexit
402 ; CHECK: for.cond.preheader.split:
403 ; CHECK-NEXT: br label %for.cond
406 br i1 %cond1, label %land.lhs.true, label %if.end17.thread.loopexit
408 ; CHECK-NEXT: br label %land.lhs.true
412 ; CHECK: land.lhs.true:
413 ; CHECK-NEXT: br label %if.then20
416 %cond2 = load volatile i1, i1* %cond2.ptr
417 br i1 %cond2, label %if.then23, label %if.else
419 ; CHECK-NEXT: %[[COND2:.*]] = load volatile i1, i1* %cond2.ptr
420 ; CHECK-NEXT: br i1 %[[COND2]], label %if.then23, label %if.else
425 ; CHECK-NEXT: br label %for.cond
427 if.end17.thread.loopexit:
428 br label %if.end17.thread
429 ; CHECK: if.end17.thread.loopexit:
430 ; CHECK-NEXT: br label %if.end17.thread
434 ; CHECK: if.end17.thread:
435 ; CHECK-NEXT: br label %cleanup
440 ; CHECK-NEXT: br label %cleanup
445 ; CHECK-NEXT: ret void
448 define i32 @test_partial_condition_unswitch_and(i32* %var, i1 %cond1, i1 %cond2) {
449 ; CHECK-LABEL: @test_partial_condition_unswitch_and(
453 ; CHECK-NEXT: br i1 %cond1, label %entry.split, label %loop_exit.split
455 ; CHECK: entry.split:
456 ; CHECK-NEXT: br i1 %cond2, label %entry.split.split, label %loop_exit
458 ; CHECK: entry.split.split:
459 ; CHECK-NEXT: br label %loop_begin
462 br i1 %cond1, label %continue, label %loop_exit
464 ; CHECK-NEXT: br label %continue
467 %var_val = load i32, i32* %var
468 %var_cond = trunc i32 %var_val to i1
469 %cond_and = and i1 %var_cond, %cond2
470 br i1 %cond_and, label %do_something, label %loop_exit
472 ; CHECK-NEXT: %[[VAR:.*]] = load i32
473 ; CHECK-NEXT: %[[VAR_COND:.*]] = trunc i32 %[[VAR]] to i1
474 ; CHECK-NEXT: %[[COND_AND:.*]] = and i1 %[[VAR_COND]], true
475 ; CHECK-NEXT: br i1 %[[COND_AND]], label %do_something, label %loop_exit
478 call void @some_func() noreturn nounwind
480 ; CHECK: do_something:
482 ; CHECK-NEXT: br label %loop_begin
487 ; CHECK-NEXT: br label %loop_exit.split
489 ; CHECK: loop_exit.split:
493 define i32 @test_partial_condition_unswitch_and_select(i32* %var, i1 %cond1, i1 %cond2) {
494 ; CHECK-LABEL: @test_partial_condition_unswitch_and_select(
498 ; CHECK-NEXT: br i1 %cond1, label %entry.split, label %loop_exit.split
500 ; CHECK: entry.split:
501 ; CHECK-NEXT: br i1 %cond2, label %entry.split.split, label %loop_exit
503 ; CHECK: entry.split.split:
504 ; CHECK-NEXT: br label %loop_begin
507 br i1 %cond1, label %continue, label %loop_exit
509 ; CHECK-NEXT: br label %continue
512 %var_val = load i32, i32* %var
513 %var_cond = trunc i32 %var_val to i1
514 %cond_and = select i1 %var_cond, i1 %cond2, i1 false
515 br i1 %cond_and, label %do_something, label %loop_exit
517 ; CHECK-NEXT: %[[VAR:.*]] = load i32
518 ; CHECK-NEXT: %[[VAR_COND:.*]] = trunc i32 %[[VAR]] to i1
519 ; CHECK-NEXT: %[[COND_AND:.*]] = select i1 %[[VAR_COND]], i1 true, i1 false
520 ; CHECK-NEXT: br i1 %[[COND_AND]], label %do_something, label %loop_exit
523 call void @some_func() noreturn nounwind
525 ; CHECK: do_something:
527 ; CHECK-NEXT: br label %loop_begin
532 ; CHECK-NEXT: br label %loop_exit.split
534 ; CHECK: loop_exit.split:
538 define i32 @test_partial_condition_unswitch_or_simple_select(i32* %var, i1 %cond1, i1 %cond2) {
539 ; CHECK-LABEL: @test_partial_condition_unswitch_or_simple_select(
543 ; CHECK-NEXT: br i1 %cond1, label %entry.split, label %loop_exit.split
545 ; CHECK: entry.split:
546 ; CHECK-NEXT: br i1 %cond2, label %loop_exit.split1, label %entry.split.split
548 ; CHECK: entry.split.split:
549 ; CHECK-NEXT: br label %loop_begin
552 br i1 %cond1, label %continue, label %loop_exit
554 ; CHECK-NEXT: br label %continue
557 %var_val = load i32, i32* %var
558 %var_cond = trunc i32 %var_val to i1
559 %cond_or = select i1 %var_cond, i1 true, i1 %cond2
560 br i1 %cond_or, label %loop_exit, label %do_something
562 ; CHECK-NEXT: %[[VAR:.*]] = load i32
563 ; CHECK-NEXT: %[[VAR_COND:.*]] = trunc i32 %[[VAR]] to i1
564 ; CHECK-NEXT: %[[COND_OR:.*]] = select i1 %[[VAR_COND]], i1 true, i1 false
565 ; CHECK-NEXT: br i1 %[[COND_OR]], label %loop_exit, label %do_something
568 call void @some_func() noreturn nounwind
570 ; CHECK: do_something:
572 ; CHECK-NEXT: br label %loop_begin
577 ; CHECK-NEXT: br label %loop_exit.split1
579 ; CHECK: loop_exit.split1:
580 ; CHECK-NEXT: br label %loop_exit.split
582 ; CHECK: loop_exit.split:
586 define i32 @test_partial_condition_unswitch_or(i32* %var, i1 %cond1, i1 %cond2, i1 %cond3, i1 %cond4, i1 %cond5, i1 %cond6) {
587 ; CHECK-LABEL: @test_partial_condition_unswitch_or(
591 ; CHECK-NEXT: %[[INV_OR1:.*]] = or i1 %cond4, %cond2
592 ; CHECK-NEXT: %[[INV_OR2:.*]] = or i1 %[[INV_OR1]], %cond3
593 ; CHECK-NEXT: %[[INV_OR3:.*]] = or i1 %[[INV_OR2]], %cond1
594 ; CHECK-NEXT: br i1 %[[INV_OR3]], label %loop_exit.split, label %entry.split
596 ; CHECK: entry.split:
597 ; CHECK-NEXT: br label %loop_begin
600 %var_val = load i32, i32* %var
601 %var_cond = trunc i32 %var_val to i1
602 %cond_or1 = or i1 %var_cond, %cond1
603 %cond_or2 = or i1 %cond2, %cond3
604 %cond_or3 = or i1 %cond_or1, %cond_or2
605 %cond_xor1 = xor i1 %cond5, %var_cond
606 %cond_and1 = and i1 %cond6, %var_cond
607 %cond_or4 = or i1 %cond_xor1, %cond_and1
608 %cond_or5 = or i1 %cond_or3, %cond_or4
609 %cond_or6 = or i1 %cond_or5, %cond4
610 br i1 %cond_or6, label %loop_exit, label %do_something
612 ; CHECK-NEXT: %[[VAR:.*]] = load i32
613 ; CHECK-NEXT: %[[VAR_COND:.*]] = trunc i32 %[[VAR]] to i1
614 ; CHECK-NEXT: %[[COND_OR1:.*]] = or i1 %[[VAR_COND]], false
615 ; CHECK-NEXT: %[[COND_OR2:.*]] = or i1 false, false
616 ; CHECK-NEXT: %[[COND_OR3:.*]] = or i1 %[[COND_OR1]], %[[COND_OR2]]
617 ; CHECK-NEXT: %[[COND_XOR:.*]] = xor i1 %cond5, %[[VAR_COND]]
618 ; CHECK-NEXT: %[[COND_AND:.*]] = and i1 %cond6, %[[VAR_COND]]
619 ; CHECK-NEXT: %[[COND_OR4:.*]] = or i1 %[[COND_XOR]], %[[COND_AND]]
620 ; CHECK-NEXT: %[[COND_OR5:.*]] = or i1 %[[COND_OR3]], %[[COND_OR4]]
621 ; CHECK-NEXT: %[[COND_OR6:.*]] = or i1 %[[COND_OR5]], false
622 ; CHECK-NEXT: br i1 %[[COND_OR6]], label %loop_exit, label %do_something
625 call void @some_func() noreturn nounwind
627 ; CHECK: do_something:
629 ; CHECK-NEXT: br label %loop_begin
633 ; CHECK: loop_exit.split:
637 ; Check that loop unswitch looks through a combination of or and select instructions.
638 ; Note that cond6 can be unswitched because `select i1 %cond_or5, i1 true, i1 false` is
639 ; both logical-or and logical-and.
640 define i32 @test_partial_condition_unswitch_or_select(i32* %var, i1 %cond1, i1 %cond2, i1 %cond3, i1 %cond4, i1 %cond5, i1 %cond6) {
641 ; CHECK-LABEL: @test_partial_condition_unswitch_or_select(
645 ; CHECK-NEXT: %[[INV_OR1:.*]] = or i1 %cond4, %cond2
646 ; CHECK-NEXT: %[[INV_OR2:.*]] = or i1 %[[INV_OR1]], %cond3
647 ; CHECK-NEXT: %[[INV_OR3:.*]] = or i1 %[[INV_OR2]], %cond1
648 ; CHECK-NEXT: br i1 %[[INV_OR3]], label %loop_exit.split, label %entry.split
650 ; CHECK: entry.split:
651 ; CHECK-NEXT: br i1 %cond6, label %loop_exit.split1, label %entry.split.split
653 ; CHECK: entry.split.split:
654 ; CHECK-NEXT: br label %loop_begin
657 %var_val = load i32, i32* %var
658 %var_cond = trunc i32 %var_val to i1
659 %cond_or1 = or i1 %var_cond, %cond1
660 %cond_or2 = or i1 %cond2, %cond3
661 %cond_or3 = or i1 %cond_or1, %cond_or2
662 %cond_xor1 = xor i1 %cond5, %var_cond
663 %cond_and1 = and i1 %cond6, %var_cond
664 %cond_or4 = or i1 %cond_xor1, %cond_and1
665 %cond_or5 = select i1 %cond_or3, i1 true, i1 %cond_or4
666 %cond_or6 = select i1 %cond_or5, i1 true, i1 %cond4
667 br i1 %cond_or6, label %loop_exit, label %do_something
669 ; CHECK-NEXT: %[[VAR:.*]] = load i32
670 ; CHECK-NEXT: %[[VAR_COND:.*]] = trunc i32 %[[VAR]] to i1
671 ; CHECK-NEXT: %[[COND_OR1:.*]] = or i1 %[[VAR_COND]], false
672 ; CHECK-NEXT: %[[COND_OR2:.*]] = or i1 false, false
673 ; CHECK-NEXT: %[[COND_OR3:.*]] = or i1 %[[COND_OR1]], %[[COND_OR2]]
674 ; CHECK-NEXT: %[[COND_XOR:.*]] = xor i1 %cond5, %[[VAR_COND]]
675 ; CHECK-NEXT: %[[COND_AND:.*]] = and i1 false, %[[VAR_COND]]
676 ; CHECK-NEXT: %[[COND_OR4:.*]] = or i1 %[[COND_XOR]], %[[COND_AND]]
677 ; CHECK-NEXT: %[[COND_OR5:.*]] = select i1 %[[COND_OR3]], i1 true, i1 %[[COND_OR4]]
678 ; CHECK-NEXT: %[[COND_OR6:.*]] = select i1 %[[COND_OR5]], i1 true, i1 false
679 ; CHECK-NEXT: br i1 %[[COND_OR6]], label %loop_exit, label %do_something
682 call void @some_func() noreturn nounwind
684 ; CHECK: do_something:
686 ; CHECK-NEXT: br label %loop_begin
690 ; CHECK: loop_exit.split:
694 define i32 @test_partial_condition_unswitch_with_lcssa_phi1(i32* %var, i1 %cond, i32 %x) {
695 ; CHECK-LABEL: @test_partial_condition_unswitch_with_lcssa_phi1(
699 ; CHECK-NEXT: br i1 %cond, label %entry.split, label %loop_exit.split
701 ; CHECK: entry.split:
702 ; CHECK-NEXT: br label %loop_begin
705 %var_val = load i32, i32* %var
706 %var_cond = trunc i32 %var_val to i1
707 %cond_and = and i1 %var_cond, %cond
708 br i1 %cond_and, label %do_something, label %loop_exit
710 ; CHECK-NEXT: %[[VAR:.*]] = load i32
711 ; CHECK-NEXT: %[[VAR_COND:.*]] = trunc i32 %[[VAR]] to i1
712 ; CHECK-NEXT: %[[COND_AND:.*]] = and i1 %[[VAR_COND]], true
713 ; CHECK-NEXT: br i1 %[[COND_AND]], label %do_something, label %loop_exit
716 call void @some_func() noreturn nounwind
718 ; CHECK: do_something:
720 ; CHECK-NEXT: br label %loop_begin
723 %x.lcssa = phi i32 [ %x, %loop_begin ]
726 ; CHECK-NEXT: %[[LCSSA:.*]] = phi i32 [ %x, %loop_begin ]
727 ; CHECK-NEXT: br label %loop_exit.split
729 ; CHECK: loop_exit.split:
730 ; CHECK-NEXT: %[[LCSSA_SPLIT:.*]] = phi i32 [ %x, %entry ], [ %[[LCSSA]], %loop_exit ]
731 ; CHECK-NEXT: ret i32 %[[LCSSA_SPLIT]]
734 define i32 @test_partial_condition_unswitch_with_lcssa_phi2(i32* %var, i1 %cond, i32 %x, i32 %y) {
735 ; CHECK-LABEL: @test_partial_condition_unswitch_with_lcssa_phi2(
739 ; CHECK-NEXT: br i1 %cond, label %entry.split, label %loop_exit.split
741 ; CHECK: entry.split:
742 ; CHECK-NEXT: br label %loop_begin
745 %var_val = load i32, i32* %var
746 %var_cond = trunc i32 %var_val to i1
747 %cond_and = and i1 %var_cond, %cond
748 br i1 %cond_and, label %do_something, label %loop_exit
750 ; CHECK-NEXT: %[[VAR:.*]] = load i32
751 ; CHECK-NEXT: %[[VAR_COND:.*]] = trunc i32 %[[VAR]] to i1
752 ; CHECK-NEXT: %[[COND_AND:.*]] = and i1 %[[VAR_COND]], true
753 ; CHECK-NEXT: br i1 %[[COND_AND]], label %do_something, label %loop_exit
756 call void @some_func() noreturn nounwind
757 br i1 %var_cond, label %loop_begin, label %loop_exit
758 ; CHECK: do_something:
760 ; CHECK-NEXT: br i1 %[[VAR_COND]], label %loop_begin, label %loop_exit
763 %xy.lcssa = phi i32 [ %x, %loop_begin ], [ %y, %do_something ]
766 ; CHECK-NEXT: %[[LCSSA:.*]] = phi i32 [ %x, %loop_begin ], [ %y, %do_something ]
767 ; CHECK-NEXT: br label %loop_exit.split
769 ; CHECK: loop_exit.split:
770 ; CHECK-NEXT: %[[LCSSA_SPLIT:.*]] = phi i32 [ %x, %entry ], [ %[[LCSSA]], %loop_exit ]
771 ; CHECK-NEXT: ret i32 %[[LCSSA_SPLIT]]
774 ; Unswitch will not actually change the loop nest from:
776 define void @hoist_inner_loop0() {
777 ; CHECK-LABEL: define void @hoist_inner_loop0(
781 ; CHECK-NEXT: br label %a.header
786 ; CHECK-NEXT: br label %b.header
789 %v1 = call i1 @cond()
792 ; CHECK-NEXT: %v1 = call i1 @cond()
793 ; CHECK-NEXT: br i1 %v1, label %[[B_LATCH_SPLIT:.*]], label %[[B_HEADER_SPLIT:.*]]
795 ; CHECK: [[B_HEADER_SPLIT]]:
796 ; CHECK-NEXT: br label %c.header
799 br i1 %v1, label %b.latch, label %c.latch
801 ; CHECK-NEXT: br label %c.latch
804 %v2 = call i1 @cond()
805 br i1 %v2, label %c.header, label %b.latch
807 ; CHECK-NEXT: %v2 = call i1 @cond()
808 ; CHECK-NEXT: br i1 %v2, label %c.header, label %b.latch
811 %v3 = call i1 @cond()
812 br i1 %v3, label %b.header, label %a.latch
814 ; CHECK-NEXT: br label %[[B_LATCH_SPLIT]]
816 ; CHECK: [[B_LATCH_SPLIT]]:
817 ; CHECK-NEXT: %v3 = call i1 @cond()
818 ; CHECK-NEXT: br i1 %v3, label %b.header, label %a.latch
823 ; CHECK-NEXT: br label %a.header
828 ; CHECK-NEXT: ret void
831 ; Unswitch will transform the loop nest from:
835 define void @hoist_inner_loop1(i32* %ptr) {
836 ; CHECK-LABEL: define void @hoist_inner_loop1(
840 ; CHECK-NEXT: br label %a.header
843 %x.a = load i32, i32* %ptr
846 ; CHECK-NEXT: %x.a = load i32, i32* %ptr
847 ; CHECK-NEXT: br label %b.header
850 %x.b = load i32, i32* %ptr
851 %v1 = call i1 @cond()
854 ; CHECK-NEXT: %x.b = load i32, i32* %ptr
855 ; CHECK-NEXT: %v1 = call i1 @cond()
856 ; CHECK-NEXT: br i1 %v1, label %b.latch, label %[[B_HEADER_SPLIT:.*]]
858 ; CHECK: [[B_HEADER_SPLIT]]:
859 ; CHECK-NEXT: %[[X_B_LCSSA:.*]] = phi i32 [ %x.b, %b.header ]
860 ; CHECK-NEXT: br label %c.header
863 br i1 %v1, label %b.latch, label %c.latch
865 ; CHECK-NEXT: br label %c.latch
868 ; Use values from other loops to check LCSSA form.
869 store i32 %x.a, i32* %ptr
870 store i32 %x.b, i32* %ptr
871 %v2 = call i1 @cond()
872 br i1 %v2, label %c.header, label %a.exit.c
874 ; CHECK-NEXT: store i32 %x.a, i32* %ptr
875 ; CHECK-NEXT: store i32 %[[X_B_LCSSA]], i32* %ptr
876 ; CHECK-NEXT: %v2 = call i1 @cond()
877 ; CHECK-NEXT: br i1 %v2, label %c.header, label %a.exit.c
880 %v3 = call i1 @cond()
881 br i1 %v3, label %b.header, label %a.exit.b
883 ; CHECK-NEXT: %v3 = call i1 @cond()
884 ; CHECK-NEXT: br i1 %v3, label %b.header, label %a.exit.b
889 ; CHECK-NEXT: br label %a.latch
894 ; CHECK-NEXT: br label %a.latch
899 ; CHECK-NEXT: br label %a.header
904 ; CHECK-NEXT: ret void
907 ; Unswitch will transform the loop nest from:
911 define void @hoist_inner_loop2(i32* %ptr) {
912 ; CHECK-LABEL: define void @hoist_inner_loop2(
916 ; CHECK-NEXT: br label %a.header
919 %x.a = load i32, i32* %ptr
922 ; CHECK-NEXT: %x.a = load i32, i32* %ptr
923 ; CHECK-NEXT: br label %b.header
926 %x.b = load i32, i32* %ptr
927 %v1 = call i1 @cond()
930 ; CHECK-NEXT: %x.b = load i32, i32* %ptr
931 ; CHECK-NEXT: %v1 = call i1 @cond()
932 ; CHECK-NEXT: br i1 %v1, label %b.latch, label %[[B_HEADER_SPLIT:.*]]
934 ; CHECK: [[B_HEADER_SPLIT]]:
935 ; CHECK-NEXT: %[[X_A_LCSSA:.*]] = phi i32 [ %x.a, %b.header ]
936 ; CHECK-NEXT: %[[X_B_LCSSA:.*]] = phi i32 [ %x.b, %b.header ]
937 ; CHECK-NEXT: br label %c.header
940 br i1 %v1, label %b.latch, label %c.latch
942 ; CHECK-NEXT: br label %c.latch
945 ; Use values from other loops to check LCSSA form.
946 store i32 %x.a, i32* %ptr
947 store i32 %x.b, i32* %ptr
948 %v2 = call i1 @cond()
949 br i1 %v2, label %c.header, label %exit
951 ; CHECK-NEXT: store i32 %[[X_A_LCSSA]], i32* %ptr
952 ; CHECK-NEXT: store i32 %[[X_B_LCSSA]], i32* %ptr
953 ; CHECK-NEXT: %v2 = call i1 @cond()
954 ; CHECK-NEXT: br i1 %v2, label %c.header, label %exit
957 %v3 = call i1 @cond()
958 br i1 %v3, label %b.header, label %a.latch
960 ; CHECK-NEXT: %v3 = call i1 @cond()
961 ; CHECK-NEXT: br i1 %v3, label %b.header, label %a.latch
966 ; CHECK-NEXT: br label %a.header
971 ; CHECK-NEXT: ret void
974 ; Same as @hoist_inner_loop2 but with a nested loop inside the hoisted loop.
975 ; Unswitch will transform the loop nest from:
979 define void @hoist_inner_loop3(i32* %ptr) {
980 ; CHECK-LABEL: define void @hoist_inner_loop3(
984 ; CHECK-NEXT: br label %a.header
987 %x.a = load i32, i32* %ptr
990 ; CHECK-NEXT: %x.a = load i32, i32* %ptr
991 ; CHECK-NEXT: br label %b.header
994 %x.b = load i32, i32* %ptr
995 %v1 = call i1 @cond()
998 ; CHECK-NEXT: %x.b = load i32, i32* %ptr
999 ; CHECK-NEXT: %v1 = call i1 @cond()
1000 ; CHECK-NEXT: br i1 %v1, label %b.latch, label %[[B_HEADER_SPLIT:.*]]
1002 ; CHECK: [[B_HEADER_SPLIT]]:
1003 ; CHECK-NEXT: %[[X_A_LCSSA:.*]] = phi i32 [ %x.a, %b.header ]
1004 ; CHECK-NEXT: %[[X_B_LCSSA:.*]] = phi i32 [ %x.b, %b.header ]
1005 ; CHECK-NEXT: br label %c.header
1008 br i1 %v1, label %b.latch, label %c.body
1010 ; CHECK-NEXT: br label %c.body
1013 %x.c = load i32, i32* %ptr
1016 ; CHECK-NEXT: %x.c = load i32, i32* %ptr
1017 ; CHECK-NEXT: br label %d.header
1020 ; Use values from other loops to check LCSSA form.
1021 store i32 %x.a, i32* %ptr
1022 store i32 %x.b, i32* %ptr
1023 store i32 %x.c, i32* %ptr
1024 %v2 = call i1 @cond()
1025 br i1 %v2, label %d.header, label %c.latch
1027 ; CHECK-NEXT: store i32 %[[X_A_LCSSA]], i32* %ptr
1028 ; CHECK-NEXT: store i32 %[[X_B_LCSSA]], i32* %ptr
1029 ; CHECK-NEXT: store i32 %x.c, i32* %ptr
1030 ; CHECK-NEXT: %v2 = call i1 @cond()
1031 ; CHECK-NEXT: br i1 %v2, label %d.header, label %c.latch
1034 %v3 = call i1 @cond()
1035 br i1 %v3, label %c.header, label %exit
1037 ; CHECK-NEXT: %v3 = call i1 @cond()
1038 ; CHECK-NEXT: br i1 %v3, label %c.header, label %exit
1041 %v4 = call i1 @cond()
1042 br i1 %v4, label %b.header, label %a.latch
1044 ; CHECK-NEXT: %v4 = call i1 @cond()
1045 ; CHECK-NEXT: br i1 %v4, label %b.header, label %a.latch
1050 ; CHECK-NEXT: br label %a.header
1055 ; CHECK-NEXT: ret void
1058 ; This test is designed to exercise checking multiple remaining exits from the
1059 ; loop being unswitched.
1060 ; Unswitch will transform the loop nest from:
1064 define void @hoist_inner_loop4() {
1065 ; CHECK-LABEL: define void @hoist_inner_loop4(
1069 ; CHECK-NEXT: br label %a.header
1074 ; CHECK-NEXT: br label %b.header
1079 ; CHECK-NEXT: br label %c.header
1082 %v1 = call i1 @cond()
1085 ; CHECK-NEXT: %v1 = call i1 @cond()
1086 ; CHECK-NEXT: br i1 %v1, label %[[C_HEADER_SPLIT:.*]], label %c.latch
1088 ; CHECK: [[C_HEADER_SPLIT]]:
1089 ; CHECK-NEXT: br label %d.header
1092 br i1 %v1, label %d.exiting1, label %c.latch
1094 ; CHECK-NEXT: br label %d.exiting1
1097 %v2 = call i1 @cond()
1098 br i1 %v2, label %d.exiting2, label %a.latch
1099 ; CHECK: d.exiting1:
1100 ; CHECK-NEXT: %v2 = call i1 @cond()
1101 ; CHECK-NEXT: br i1 %v2, label %d.exiting2, label %a.latch
1104 %v3 = call i1 @cond()
1105 br i1 %v3, label %d.exiting3, label %loopexit.d
1106 ; CHECK: d.exiting2:
1107 ; CHECK-NEXT: %v3 = call i1 @cond()
1108 ; CHECK-NEXT: br i1 %v3, label %d.exiting3, label %loopexit.d
1111 %v4 = call i1 @cond()
1112 br i1 %v4, label %d.latch, label %b.latch
1113 ; CHECK: d.exiting3:
1114 ; CHECK-NEXT: %v4 = call i1 @cond()
1115 ; CHECK-NEXT: br i1 %v4, label %d.latch, label %b.latch
1120 ; CHECK-NEXT: br label %d.header
1123 %v5 = call i1 @cond()
1124 br i1 %v5, label %c.header, label %loopexit.c
1126 ; CHECK-NEXT: %v5 = call i1 @cond()
1127 ; CHECK-NEXT: br i1 %v5, label %c.header, label %loopexit.c
1132 ; CHECK-NEXT: br label %b.header
1137 ; CHECK-NEXT: br label %a.header
1141 ; CHECK: loopexit.d:
1142 ; CHECK-NEXT: br label %exit
1146 ; CHECK: loopexit.c:
1147 ; CHECK-NEXT: br label %exit
1152 ; CHECK-NEXT: ret void
1155 ; Unswitch will transform the loop nest from:
1159 define void @hoist_inner_loop5(i32* %ptr) {
1160 ; CHECK-LABEL: define void @hoist_inner_loop5(
1164 ; CHECK-NEXT: br label %a.header
1167 %x.a = load i32, i32* %ptr
1170 ; CHECK-NEXT: %x.a = load i32, i32* %ptr
1171 ; CHECK-NEXT: br label %b.header
1174 %x.b = load i32, i32* %ptr
1177 ; CHECK-NEXT: %x.b = load i32, i32* %ptr
1178 ; CHECK-NEXT: br label %c.header
1181 %x.c = load i32, i32* %ptr
1182 %v1 = call i1 @cond()
1185 ; CHECK-NEXT: %x.c = load i32, i32* %ptr
1186 ; CHECK-NEXT: %v1 = call i1 @cond()
1187 ; CHECK-NEXT: br i1 %v1, label %c.latch, label %[[C_HEADER_SPLIT:.*]]
1189 ; CHECK: [[C_HEADER_SPLIT]]:
1190 ; CHECK-NEXT: %[[X_B_LCSSA:.*]] = phi i32 [ %x.b, %c.header ]
1191 ; CHECK-NEXT: %[[X_C_LCSSA:.*]] = phi i32 [ %x.c, %c.header ]
1192 ; CHECK-NEXT: br label %d.header
1195 br i1 %v1, label %c.latch, label %d.latch
1197 ; CHECK-NEXT: br label %d.latch
1200 ; Use values from other loops to check LCSSA form.
1201 store i32 %x.a, i32* %ptr
1202 store i32 %x.b, i32* %ptr
1203 store i32 %x.c, i32* %ptr
1204 %v2 = call i1 @cond()
1205 br i1 %v2, label %d.header, label %a.latch
1207 ; CHECK-NEXT: store i32 %x.a, i32* %ptr
1208 ; CHECK-NEXT: store i32 %[[X_B_LCSSA]], i32* %ptr
1209 ; CHECK-NEXT: store i32 %[[X_C_LCSSA]], i32* %ptr
1210 ; CHECK-NEXT: %v2 = call i1 @cond()
1211 ; CHECK-NEXT: br i1 %v2, label %d.header, label %a.latch
1214 %v3 = call i1 @cond()
1215 br i1 %v3, label %c.header, label %b.latch
1217 ; CHECK-NEXT: %v3 = call i1 @cond()
1218 ; CHECK-NEXT: br i1 %v3, label %c.header, label %b.latch
1223 ; CHECK-NEXT: br label %b.header
1228 ; CHECK-NEXT: br label %a.header
1233 ; CHECK-NEXT: ret void
1236 ; Same as `@hoist_inner_loop2` but using a switch.
1237 ; Unswitch will transform the loop nest from:
1241 define void @hoist_inner_loop_switch(i32* %ptr) {
1242 ; CHECK-LABEL: define void @hoist_inner_loop_switch(
1246 ; CHECK-NEXT: br label %a.header
1249 %x.a = load i32, i32* %ptr
1252 ; CHECK-NEXT: %x.a = load i32, i32* %ptr
1253 ; CHECK-NEXT: br label %b.header
1256 %x.b = load i32, i32* %ptr
1257 %v1 = call i32 @cond.i32()
1260 ; CHECK-NEXT: %x.b = load i32, i32* %ptr
1261 ; CHECK-NEXT: %v1 = call i32 @cond.i32()
1262 ; CHECK-NEXT: switch i32 %v1, label %[[B_HEADER_SPLIT:.*]] [
1263 ; CHECK-NEXT: i32 1, label %b.latch
1264 ; CHECK-NEXT: i32 2, label %b.latch
1265 ; CHECK-NEXT: i32 3, label %b.latch
1268 ; CHECK: [[B_HEADER_SPLIT]]:
1269 ; CHECK-NEXT: %[[X_A_LCSSA:.*]] = phi i32 [ %x.a, %b.header ]
1270 ; CHECK-NEXT: %[[X_B_LCSSA:.*]] = phi i32 [ %x.b, %b.header ]
1271 ; CHECK-NEXT: br label %c.header
1274 switch i32 %v1, label %c.latch [
1275 i32 1, label %b.latch
1276 i32 2, label %b.latch
1277 i32 3, label %b.latch
1280 ; CHECK-NEXT: br label %c.latch
1283 ; Use values from other loops to check LCSSA form.
1284 store i32 %x.a, i32* %ptr
1285 store i32 %x.b, i32* %ptr
1286 %v2 = call i1 @cond()
1287 br i1 %v2, label %c.header, label %exit
1289 ; CHECK-NEXT: store i32 %[[X_A_LCSSA]], i32* %ptr
1290 ; CHECK-NEXT: store i32 %[[X_B_LCSSA]], i32* %ptr
1291 ; CHECK-NEXT: %v2 = call i1 @cond()
1292 ; CHECK-NEXT: br i1 %v2, label %c.header, label %exit
1295 %v3 = call i1 @cond()
1296 br i1 %v3, label %b.header, label %a.latch
1298 ; CHECK-NEXT: %v3 = call i1 @cond()
1299 ; CHECK-NEXT: br i1 %v3, label %b.header, label %a.latch
1304 ; CHECK-NEXT: br label %a.header
1309 ; CHECK-NEXT: ret void
1312 define void @test_unswitch_to_common_succ_with_phis(i32* %var, i32 %cond) {
1313 ; CHECK-LABEL: @test_unswitch_to_common_succ_with_phis(
1316 ; CHECK-NEXT: entry:
1317 ; CHECK-NEXT: switch i32 %cond, label %loopexit1 [
1318 ; CHECK-NEXT: i32 13, label %loopexit2
1319 ; CHECK-NEXT: i32 0, label %entry.split
1320 ; CHECK-NEXT: i32 1, label %entry.split
1323 ; CHECK: entry.split:
1324 ; CHECK-NEXT: br label %header
1327 %var_val = load i32, i32* %var
1328 switch i32 %cond, label %loopexit1 [
1331 i32 13, label %loopexit2
1335 ; CHECK-NEXT: br label %latch
1338 ; No-op PHI node to exercise weird PHI update scenarios.
1339 %phi = phi i32 [ %var_val, %header ], [ %var_val, %header ]
1340 call void @sink(i32 %phi)
1343 ; CHECK-NEXT: %[[PHI:.*]] = phi i32 [ %var_val, %header ]
1344 ; CHECK-NEXT: call void @sink(i32 %[[PHI]])
1345 ; CHECK-NEXT: br label %header
1358 define void @test_unswitch_to_default_common_succ_with_phis(i32* %var, i32 %cond) {
1359 ; CHECK-LABEL: @test_unswitch_to_default_common_succ_with_phis(
1362 ; CHECK-NEXT: entry:
1363 ; CHECK-NEXT: switch i32 %cond, label %entry.split [
1364 ; CHECK-NEXT: i32 13, label %loopexit
1367 ; CHECK: entry.split:
1368 ; CHECK-NEXT: br label %header
1371 %var_val = load i32, i32* %var
1372 switch i32 %cond, label %latch [
1375 i32 13, label %loopexit
1379 ; CHECK-NEXT: br label %latch
1382 ; No-op PHI node to exercise weird PHI update scenarios.
1383 %phi = phi i32 [ %var_val, %header ], [ %var_val, %header ], [ %var_val, %header ]
1384 call void @sink(i32 %phi)
1387 ; CHECK-NEXT: %[[PHI:.*]] = phi i32 [ %var_val, %header ]
1388 ; CHECK-NEXT: call void @sink(i32 %[[PHI]])
1389 ; CHECK-NEXT: br label %header
1399 define void @test_unswitch_switch_with_nonempty_unreachable() {
1400 ; CHECK-LABEL: @test_unswitch_switch_with_nonempty_unreachable()
1405 %cleanup.dest.slot.0 = select i1 undef, i32 5, i32 undef
1409 switch i32 %cleanup.dest.slot.0, label %NonEmptyUnreachableBlock [
1410 i32 0, label %for.cond
1411 i32 1, label %NonEmptyUnreachableBlock
1412 i32 2, label %loop.loopexit
1418 NonEmptyUnreachableBlock:
1424 ; CHECK-NEXT: %cleanup.dest.slot.0 = select i1 undef, i32 5, i32 undef
1425 ; CHECK-NEXT: switch i32 %cleanup.dest.slot.0, label %NonEmptyUnreachableBlock [
1426 ; CHECK-NEXT: i32 1, label %NonEmptyUnreachableBlock
1427 ; CHECK-NEXT: i32 0, label %loop.split
1428 ; CHECK-NEXT: i32 2, label %loop.split
1432 ; CHECK-NEXT: br label %for.cond
1435 ; CHECK-NEXT: switch i32 %cleanup.dest.slot.0, label %loop.loopexit [
1436 ; CHECK-NEXT: i32 0, label %for.cond
1439 ; CHECK:loop.loopexit:
1440 ; CHECK-NEXT: unreachable
1442 ; CHECK:NonEmptyUnreachableBlock:
1443 ; CHECK-NEXT: call void @f()
1444 ; CHECK-NEXT: call void @g()
1445 ; CHECK-NEXT: unreachable
1448 define void @test_unswitch_switch_with_nonempty_unreachable2() {
1449 ; CHECK-LABEL: @test_unswitch_switch_with_nonempty_unreachable2()
1454 %cleanup.dest.slot.0 = select i1 undef, i32 5, i32 undef
1458 switch i32 %cleanup.dest.slot.0, label %for.cond [
1459 i32 0, label %for.cond
1460 i32 1, label %NonEmptyUnreachableBlock
1461 i32 2, label %loop.loopexit
1467 NonEmptyUnreachableBlock:
1473 ; CHECK-NEXT: %cleanup.dest.slot.0 = select i1 undef, i32 5, i32 undef
1474 ; CHECK-NEXT: switch i32 %cleanup.dest.slot.0, label %loop.split [
1475 ; CHECK-NEXT: i32 1, label %NonEmptyUnreachableBlock
1479 ; CHECK-NEXT: br label %for.cond
1482 ; CHECK-NEXT: switch i32 %cleanup.dest.slot.0, label %for.cond.backedge [
1483 ; CHECK-NEXT: i32 0, label %for.cond.backedge
1484 ; CHECK-NEXT: i32 2, label %loop.loopexit
1487 ; CHECK:for.cond.backedge:
1488 ; CHECK-NEXT: br label %for.cond
1490 ; CHECK:loop.loopexit:
1491 ; CHECK-NEXT: unreachable
1493 ; CHECK:NonEmptyUnreachableBlock:
1494 ; CHECK-NEXT: call void @f()
1495 ; CHECK-NEXT: call void @g()
1496 ; CHECK-NEXT: unreachable
1500 define void @test_unswitch_switch_with_duplicate_edge() {
1501 ; CHECK-LABEL: @test_unswitch_switch_with_duplicate_edge()
1505 lbl1: ; preds = %entry
1506 %cleanup.dest.slot.0 = select i1 undef, i32 5, i32 undef
1509 for.cond1: ; preds = %for.cond1, %lbl1
1510 switch i32 %cleanup.dest.slot.0, label %UnifiedUnreachableBlock [
1511 i32 0, label %for.cond1
1512 i32 5, label %UnifiedUnreachableBlock
1513 i32 2, label %lbl1.loopexit
1516 UnifiedUnreachableBlock: ; preds = %for.cond1, %for.cond1
1519 lbl1.loopexit: ; preds = %for.cond1
1523 ; CHECK-NEXT: switch i32 %cleanup.dest.slot.0, label %UnifiedUnreachableBlock [
1524 ; CHECK-NEXT: i32 0, label %for.cond1
1525 ; CHECK-NEXT: i32 5, label %UnifiedUnreachableBlock
1526 ; CHECK-NEXT: i32 2, label %lbl1.loopexit