1; RUN: opt < %s -simplifycfg -S | FileCheck %s 2 3; CHECK-NOT: switch 4 5; Test normal folding 6define i32 @test1() { 7 switch i32 5, label %Default [ 8 i32 0, label %Foo 9 i32 1, label %Bar 10 i32 2, label %Baz 11 i32 5, label %TheDest 12 ] 13Default: ; preds = %0 14 ret i32 -1 15Foo: ; preds = %0 16 ret i32 -2 17Bar: ; preds = %0 18 ret i32 -3 19Baz: ; preds = %0 20 ret i32 -4 21TheDest: ; preds = %0 22 ret i32 1234 23} 24 25; Test folding to default dest 26define i32 @test2() { 27 switch i32 3, label %Default [ 28 i32 0, label %Foo 29 i32 1, label %Bar 30 i32 2, label %Baz 31 i32 5, label %TheDest 32 ] 33Default: ; preds = %0 34 ret i32 1234 35Foo: ; preds = %0 36 ret i32 -2 37Bar: ; preds = %0 38 ret i32 -5 39Baz: ; preds = %0 40 ret i32 -6 41TheDest: ; preds = %0 42 ret i32 -8 43} 44 45; Test folding all to same dest 46define i32 @test3(i1 %C) { 47 br i1 %C, label %Start, label %TheDest 48Start: ; preds = %0 49 switch i32 3, label %TheDest [ 50 i32 0, label %TheDest 51 i32 1, label %TheDest 52 i32 2, label %TheDest 53 i32 5, label %TheDest 54 ] 55TheDest: ; preds = %Start, %Start, %Start, %Start, %Start, %0 56 ret i32 1234 57} 58 59; Test folding switch -> branch 60define i32 @test4(i32 %C) { 61 switch i32 %C, label %L1 [ 62 i32 0, label %L2 63 ] 64L1: ; preds = %0 65 ret i32 0 66L2: ; preds = %0 67 ret i32 1 68} 69 70; Can fold into a cond branch! 71define i32 @test5(i32 %C) { 72 switch i32 %C, label %L1 [ 73 i32 0, label %L2 74 i32 123, label %L1 75 ] 76L1: ; preds = %0, %0 77 ret i32 0 78L2: ; preds = %0 79 ret i32 1 80} 81 82