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