blob: 71269ecfbdc69aa75c9e30e3566a7fac197ed868 [file] [log] [blame]
Chris Lattner09864a12003-08-17 20:19:31 +00001; RUN: as < %s | opt -simplifycfg | dis | not grep switch
2
3int %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 ]
10Default:ret int -1
11Foo: ret int -2
12Bar: ret int -3
13Baz: ret int -4
14TheDest:ret int 1234
15}
16
17int %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 ]
24Default:ret int 1234
25Foo: ret int -2
26Bar: ret int -5
27Baz: ret int -6
28TheDest:ret int -8
29}
30
31int %test3(bool %C) { ; Test folding all to same dest
32 br bool %C, label %Start, label %TheDest
33Start:
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 ]
40TheDest: ret int 1234
41}
42
43int %test4(uint %C) { ; Test folding switch -> branch
44 switch uint %C, label %L1 [
45 uint 0, label %L2
46 ]
47L1: ret int 0
48L2: ret int 1
49}
Chris Lattner2231d582003-08-23 23:17:59 +000050
51int %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 ]
56L1: ret int 0
57L2: ret int 1
58}
59
60