1 ; RUN: opt < %s -loop-unswitch -loop-unswitch-threshold=0 -verify-loop-info -S < %s 2>&1 | FileCheck %s
2 ; RUN: opt < %s -loop-unswitch -loop-unswitch-threshold=0 -verify-loop-info -enable-mssa-loop-dependency=true -verify-memoryssa -S < %s 2>&1 | FileCheck %s
4 ; This test contains two trivial unswitch condition in one loop.
5 ; LoopUnswitch pass should be able to unswitch the second one
6 ; after unswitching the first one.
9 ; CHECK: br i1 %cond1, label %..split_crit_edge, label %.loop_exit.split_crit_edge
11 ; CHECK: ..split_crit_edge: ; preds = %0
12 ; CHECK: br label %.split
14 ; CHECK: .split: ; preds = %..split_crit_edge
15 ; CHECK: br i1 %cond2, label %.split..split.split_crit_edge, label %.split.loop_exit.split1_crit_edge
17 ; CHECK: .split..split.split_crit_edge: ; preds = %.split
18 ; CHECK: br label %.split.split
20 ; CHECK: .split.split: ; preds = %.split..split.split_crit_edge
21 ; CHECK: br label %loop_begin
23 ; CHECK: loop_begin: ; preds = %do_something, %.split.split
24 ; CHECK: br i1 true, label %continue, label %loop_exit
26 ; CHECK: continue: ; preds = %loop_begin
27 ; CHECK: %var_val = load i32, i32* %var
28 ; CHECK: br i1 true, label %do_something, label %loop_exit
30 define i32 @test(i32* %var, i1 %cond1, i1 %cond2) {
34 br i1 %cond1, label %continue, label %loop_exit ; first trivial condition
37 %var_val = load i32, i32* %var
38 br i1 %cond2, label %do_something, label %loop_exit ; second trivial condition
41 call void @some_func() noreturn nounwind
49 ; We will not be able trivially unswitch on the SwitchInst, as its input
50 ; is a constant. However, since its a constant we should be able to figure
51 ; out that the switch can be folded into a unconditional branch to %continue.
52 ; Then we unswitch on the br inst in %continue.
54 ; CHECK: define i32 @test2(
55 ; This is an indication that the loop has been unswitched on %cond1.
56 ; CHECK: br i1 %cond1, label %..split_crit_edge, label %.loop_exit.split_crit_edge
58 ; CHECK: ..split_crit_edge: ; preds = %0
59 ; CHECK: br label %.split
61 ; CHECK: .split: ; preds = %..split_crit_edge
62 ; CHECK: br label %loop_begin
64 ; CHECK: loop_begin: ; preds = %do_something, %.split
67 ; CHECK: continue: ; preds = %loop_begin
68 ; CHECK: %var_val = load i32, i32* %var
69 ; CHECK: br i1 true, label %do_something, label %loop_exit
71 define i32 @test2(i32* %var, i1 %cond1) {
75 switch i32 1, label %continue [
76 i32 0, label %loop_exit
77 i32 1, label %continue
81 %var_val = load i32, i32* %var
82 br i1 %cond1, label %do_something, label %loop_exit
85 call void @some_func() noreturn nounwind
92 declare void @some_func() noreturn