For PR1319:
[oota-llvm.git] / test / Transforms / SimplifyCFG / 2003-08-17-FoldSwitch.ll
1 ; RUN: llvm-upgrade < %s | llvm-as | opt -simplifycfg | llvm-dis | \
2 ; RUN:   not grep switch
3
4 int %test1() {   ; Test normal folding
5         switch uint 5, label %Default [
6                 uint 0, label %Foo
7                 uint 1, label %Bar
8                 uint 2, label %Baz
9                 uint 5, label %TheDest
10         ]
11 Default:ret int -1
12 Foo:    ret int -2
13 Bar:    ret int -3
14 Baz:    ret int -4
15 TheDest:ret int 1234
16 }
17
18 int %test2() {   ; Test folding to default dest
19         switch uint 3, label %Default [
20                 uint 0, label %Foo
21                 uint 1, label %Bar
22                 uint 2, label %Baz
23                 uint 5, label %TheDest
24         ]
25 Default:ret int 1234
26 Foo:    ret int -2
27 Bar:    ret int -5
28 Baz:    ret int -6
29 TheDest:ret int -8
30 }
31
32 int %test3(bool %C) {   ; Test folding all to same dest
33         br bool %C, label %Start, label %TheDest
34 Start:
35         switch uint 3, label %TheDest [
36                 uint 0, label %TheDest
37                 uint 1, label %TheDest
38                 uint 2, label %TheDest
39                 uint 5, label %TheDest
40         ]
41 TheDest: ret int 1234
42 }
43
44 int %test4(uint %C) {   ; Test folding switch -> branch
45         switch uint %C, label %L1 [
46                 uint 0, label %L2
47         ]
48 L1:     ret int 0
49 L2:     ret int 1
50 }
51
52 int %test5(uint %C) {
53         switch uint %C, label %L1 [   ; Can fold into a cond branch!
54                 uint 0, label %L2
55                 uint 123, label %L1
56         ]
57 L1:     ret int 0
58 L2:     ret int 1
59 }
60
61