1; RUN: opt < %s -simplifycfg -S | FileCheck %s 2 3; Test that we can thread a simple known condition through switch statements. 4 5declare void @foo1() 6 7declare void @foo2() 8 9declare void @DEAD() 10 11define 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. 18T: ; 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 ] 26A2: ; 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 32A: ; 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 37Done: ; preds = %B, %A, %A2, %0 38 ret void 39B: ; 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 44C: ; 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 64define 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. 71A: ; 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. 80C: ; preds = %A, %A 81 call void @DEAD( ) 82 ret void 83T: ; preds = %0 84 call void @foo1( ) 85 call void @foo1( ) 86 ret void 87D: ; preds = %A, %0 88 call void @foo1( ) 89 ret void 90E: ; 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