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