1; RUN: opt < %s -simplifycfg -S | \ 2; RUN: not grep "call void @DEAD" 3 4; Test that we can thread a simple known condition through switch statements. 5 6declare void @foo1() 7 8declare void @foo2() 9 10declare void @DEAD() 11 12define void @test1(i32 %V) { 13 switch i32 %V, label %A [ 14 i32 4, label %T 15 i32 17, label %Done 16 i32 1234, label %A 17 ] 18;; V == 4 if we get here. 19T: ; preds = %0 20 call void @foo1( ) 21 ;; This switch is always statically determined. 22 switch i32 %V, label %A2 [ 23 i32 4, label %B 24 i32 17, label %C 25 i32 42, label %C 26 ] 27A2: ; preds = %T 28 call void @DEAD( ) 29 call void @DEAD( ) 30 ;; always true 31 %cond2 = icmp eq i32 %V, 4 ; <i1> [#uses=1] 32 br i1 %cond2, label %Done, label %C 33A: ; preds = %0, %0 34 call void @foo1( ) 35 ;; always true 36 %cond = icmp ne i32 %V, 4 ; <i1> [#uses=1] 37 br i1 %cond, label %Done, label %C 38Done: ; preds = %B, %A, %A2, %0 39 ret void 40B: ; preds = %T 41 call void @foo2( ) 42 ;; always true 43 %cond3 = icmp eq i32 %V, 4 ; <i1> [#uses=1] 44 br i1 %cond3, label %Done, label %C 45C: ; preds = %B, %A, %A2, %T, %T 46 call void @DEAD( ) 47 ret void 48} 49 50define void @test2(i32 %V) { 51 switch i32 %V, label %A [ 52 i32 4, label %T 53 i32 17, label %D 54 i32 1234, label %E 55 ] 56;; V != 4, 17, 1234 here. 57A: ; preds = %0 58 call void @foo1( ) 59 ;; This switch is always statically determined. 60 switch i32 %V, label %E [ 61 i32 4, label %C 62 i32 17, label %C 63 i32 42, label %D 64 ] 65;; unreacahble. 66C: ; preds = %A, %A 67 call void @DEAD( ) 68 ret void 69T: ; preds = %0 70 call void @foo1( ) 71 call void @foo1( ) 72 ret void 73D: ; preds = %A, %0 74 call void @foo1( ) 75 ret void 76E: ; preds = %A, %0 77 ret void 78} 79 80