1 ; RUN: opt < %s -loop-unswitch -enable-new-pm=0 -loop-unswitch-threshold=0 -verify-loop-info -verify-memoryssa -S < %s 2>&1 | FileCheck %s
3 ; This test contains two trivial unswitch condition in one loop.
4 ; LoopUnswitch pass should be able to unswitch the second one
5 ; after unswitching the first one.
8 ; CHECK: br i1 %cond1, label %..split_crit_edge, label %.loop_exit.split_crit_edge
10 ; CHECK: ..split_crit_edge: ; preds = %0
11 ; CHECK: br label %.split
13 ; CHECK: .split: ; preds = %..split_crit_edge
14 ; CHECK: br i1 %cond2, label %.split..split.split_crit_edge, label %.split.loop_exit.split1_crit_edge
16 ; CHECK: .split..split.split_crit_edge: ; preds = %.split
17 ; CHECK: br label %.split.split
19 ; CHECK: .split.split: ; preds = %.split..split.split_crit_edge
20 ; CHECK: br label %loop_begin
22 ; CHECK: loop_begin: ; preds = %do_something, %.split.split
23 ; CHECK: br i1 true, label %continue, label %loop_exit
25 ; CHECK: continue: ; preds = %loop_begin
26 ; CHECK: %var_val = load i32, i32* %var
27 ; CHECK: br i1 true, label %do_something, label %loop_exit
29 define i32 @test(i32* %var, i1 %cond1, i1 %cond2) {
33 br i1 %cond1, label %continue, label %loop_exit ; first trivial condition
36 %var_val = load i32, i32* %var
37 br i1 %cond2, label %do_something, label %loop_exit ; second trivial condition
40 call void @some_func() noreturn nounwind
48 ; We will not be able trivially unswitch on the SwitchInst, as its input
49 ; is a constant. However, since its a constant we should be able to figure
50 ; out that the switch can be folded into a unconditional branch to %continue.
51 ; Then we unswitch on the br inst in %continue.
53 ; CHECK: define i32 @test2(
54 ; This is an indication that the loop has been unswitched on %cond1.
55 ; CHECK: br i1 %cond1, label %..split_crit_edge, label %.loop_exit.split_crit_edge
57 ; CHECK: ..split_crit_edge: ; preds = %0
58 ; CHECK: br label %.split
60 ; CHECK: .split: ; preds = %..split_crit_edge
61 ; CHECK: br label %loop_begin
63 ; CHECK: loop_begin: ; preds = %do_something, %.split
66 ; CHECK: continue: ; preds = %loop_begin
67 ; CHECK: %var_val = load i32, i32* %var
68 ; CHECK: br i1 true, label %do_something, label %loop_exit
70 define i32 @test2(i32* %var, i1 %cond1) {
74 switch i32 1, label %continue [
75 i32 0, label %loop_exit
76 i32 1, label %continue
80 %var_val = load i32, i32* %var
81 br i1 %cond1, label %do_something, label %loop_exit
84 call void @some_func() noreturn nounwind
91 declare void @some_func() noreturn