File: 2003-08-17-FoldSwitch.ll

package info (click to toggle)
llvm 2.2-12
  • links: PTS, VCS
  • area: main
  • in suites: lenny
  • size: 38,648 kB
  • ctags: 28,258
  • sloc: cpp: 215,479; sh: 12,132; ansic: 10,002; yacc: 5,525; perl: 2,352; ml: 1,580; makefile: 956; pascal: 718; lex: 602; exp: 320; ada: 193; lisp: 160; csh: 116; objc: 59; python: 59; tcl: 20
file content (61 lines) | stat: -rw-r--r-- 1,180 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
; RUN: llvm-upgrade < %s | llvm-as | opt -simplifycfg | llvm-dis | \
; RUN:   not grep switch

int %test1() {   ; Test normal folding
	switch uint 5, label %Default [
		uint 0, label %Foo
		uint 1, label %Bar
		uint 2, label %Baz
		uint 5, label %TheDest
	]
Default:ret int -1
Foo:	ret int -2
Bar:	ret int -3
Baz: 	ret int -4
TheDest:ret int 1234
}

int %test2() {   ; Test folding to default dest
	switch uint 3, label %Default [
		uint 0, label %Foo
		uint 1, label %Bar
		uint 2, label %Baz
		uint 5, label %TheDest
	]
Default:ret int 1234
Foo:	ret int -2
Bar:	ret int -5
Baz: 	ret int -6
TheDest:ret int -8
}

int %test3(bool %C) {   ; Test folding all to same dest
	br bool %C, label %Start, label %TheDest
Start:
	switch uint 3, label %TheDest [
		uint 0, label %TheDest
		uint 1, label %TheDest
		uint 2, label %TheDest
		uint 5, label %TheDest
	]
TheDest: ret int 1234
}

int %test4(uint %C) {   ; Test folding switch -> branch
	switch uint %C, label %L1 [
		uint 0, label %L2
	]
L1:	ret int 0
L2:	ret int 1
}

int %test5(uint %C) {
	switch uint %C, label %L1 [   ; Can fold into a cond branch!
		uint 0, label %L2
		uint 123, label %L1
	]
L1:	ret int 0
L2:	ret int 1
}