1 ; RUN: opt < %s -simplifycfg -S | FileCheck %s 2 3 ; Test that we can thread a simple known condition through switch statements. 4 5 declare void @foo1() 6 7 declare void @foo2() 8 9 declare void @DEAD() 10 11 define void @test1(i32 %V) { 12 switch i32 %V, label %A [ 13 i32 4, label %T 14 i32 17, label %Done 15 i32 1234, label %A 16 ] 17 ;; V == 4 if we get here. 18 T: ; preds = %0 19 call void @foo1( ) 20 ;; This switch is always statically determined. 21 switch i32 %V, label %A2 [ 22 i32 4, label %B 23 i32 17, label %C 24 i32 42, label %C 25 ] 26 A2: ; preds = %T 27 call void @DEAD( ) 28 call void @DEAD( ) 29 ;; always true 30 %cond2 = icmp eq i32 %V, 4 ; <i1> [#uses=1] 31 br i1 %cond2, label %Done, label %C 32 A: ; preds = %0, %0 33 call void @foo1( ) 34 ;; always true 35 %cond = icmp ne i32 %V, 4 ; <i1> [#uses=1] 36 br i1 %cond, label %Done, label %C 37 Done: ; preds = %B, %A, %A2, %0 38 ret void 39 B: ; preds = %T 40 call void @foo2( ) 41 ;; always true 42 %cond3 = icmp eq i32 %V, 4 ; <i1> [#uses=1] 43 br i1 %cond3, label %Done, label %C 44 C: ; preds = %B, %A, %A2, %T, %T 45 call void @DEAD( ) 46 ret void 47 48 ; CHECK-LABEL: @test1( 49 ; CHECK-NEXT: switch i32 %V, label %A [ 50 ; CHECK-NEXT: i32 4, label %T 51 ; CHECK-NEXT: i32 17, label %Done 52 ; CHECK-NEXT: ] 53 ; CHECK: T: 54 ; CHECK-NEXT: call void @foo1() 55 ; CHECK-NEXT: call void @foo2() 56 ; CHECK-NEXT: br label %Done 57 ; CHECK: A: 58 ; CHECK-NEXT: call void @foo1() 59 ; CHECK-NEXT: br label %Done 60 ; CHECK: Done: 61 ; CHECK-NEXT: ret void 62 } 63 64 define void @test2(i32 %V) { 65 switch i32 %V, label %A [ 66 i32 4, label %T 67 i32 17, label %D 68 i32 1234, label %E 69 ] 70 ;; V != 4, 17, 1234 here. 71 A: ; preds = %0 72 call void @foo1( ) 73 ;; This switch is always statically determined. 74 switch i32 %V, label %E [ 75 i32 4, label %C 76 i32 17, label %C 77 i32 42, label %D 78 ] 79 ;; unreacahble. 80 C: ; preds = %A, %A 81 call void @DEAD( ) 82 ret void 83 T: ; preds = %0 84 call void @foo1( ) 85 call void @foo1( ) 86 ret void 87 D: ; preds = %A, %0 88 call void @foo1( ) 89 ret void 90 E: ; preds = %A, %0 91 ret void 92 93 ; CHECK-LABEL: @test2( 94 ; CHECK-NEXT: switch i32 %V, label %A [ 95 ; CHECK-NEXT: i32 4, label %T 96 ; CHECK-NEXT: i32 17, label %D 97 ; CHECK-NEXT: i32 1234, label %E 98 ; CHECK-NEXT: ] 99 ; CHECK: A: 100 ; CHECK-NEXT: call void @foo1() 101 ; CHECK-NEXT: [[COND:%.*]] = icmp eq i32 %V, 42 102 ; CHECK-NEXT: br i1 [[COND]], label %D, label %E 103 ; CHECK: T: 104 ; CHECK-NEXT: call void @foo1() 105 ; CHECK-NEXT: call void @foo1() 106 ; CHECK-NEXT: ret void 107 ; CHECK: D: 108 ; CHECK-NEXT: call void @foo1() 109 ; CHECK-NEXT: ret void 110 ; CHECK: E: 111 ; CHECK-NEXT: ret void 112 } 113 114