1; RUN: opt < %s -loop-unswitch -enable-new-pm=0 -loop-unswitch-threshold=0 -verify-loop-info -S < %s 2>&1 | FileCheck %s 2; RUN: opt < %s -loop-unswitch -enable-new-pm=0 -loop-unswitch-threshold=0 -verify-loop-info -enable-mssa-loop-dependency=true -verify-memoryssa -S < %s 2>&1 | FileCheck %s 3 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. 7 8 9; CHECK: br i1 %cond1, label %..split_crit_edge, label %.loop_exit.split_crit_edge 10 11; CHECK: ..split_crit_edge: ; preds = %0 12; CHECK: br label %.split 13 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 16 17; CHECK: .split..split.split_crit_edge: ; preds = %.split 18; CHECK: br label %.split.split 19 20; CHECK: .split.split: ; preds = %.split..split.split_crit_edge 21; CHECK: br label %loop_begin 22 23; CHECK: loop_begin: ; preds = %do_something, %.split.split 24; CHECK: br i1 true, label %continue, label %loop_exit 25 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 29 30define i32 @test(i32* %var, i1 %cond1, i1 %cond2) { 31 br label %loop_begin 32 33loop_begin: 34 br i1 %cond1, label %continue, label %loop_exit ; first trivial condition 35 36continue: 37 %var_val = load i32, i32* %var 38 br i1 %cond2, label %do_something, label %loop_exit ; second trivial condition 39 40do_something: 41 call void @some_func() noreturn nounwind 42 br label %loop_begin 43 44loop_exit: 45 ret i32 0 46} 47 48 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. 53; 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 57 58; CHECK: ..split_crit_edge: ; preds = %0 59; CHECK: br label %.split 60 61; CHECK: .split: ; preds = %..split_crit_edge 62; CHECK: br label %loop_begin 63 64; CHECK: loop_begin: ; preds = %do_something, %.split 65; CHECK: switch i32 66 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 70 71define i32 @test2(i32* %var, i1 %cond1) { 72 br label %loop_begin 73 74loop_begin: 75 switch i32 1, label %continue [ 76 i32 0, label %loop_exit 77 i32 1, label %continue 78 ] 79 80continue: 81 %var_val = load i32, i32* %var 82 br i1 %cond1, label %do_something, label %loop_exit 83 84do_something: 85 call void @some_func() noreturn nounwind 86 br label %loop_begin 87 88loop_exit: 89 ret i32 0 90} 91 92declare void @some_func() noreturn 93