Fix bug in updating dominance frontier after loop
[oota-llvm.git] / test / Transforms / SimplifyCFG / switch_thread.ll
1 ; RUN: llvm-upgrade < %s | llvm-as | opt -simplifycfg | llvm-dis | \
2 ; RUN:   not grep {call void %DEAD}
3
4 ; Test that we can thread a simple known condition through switch statements.
5
6 declare void %foo1()
7 declare void %foo2()
8 declare void %DEAD()
9
10 void %test1(uint %V) {
11         switch uint %V, label %A [
12                  uint 4, label %T
13                  uint 17, label %Done
14                  uint 1234, label %A
15         ]
16
17 T:  ;; V == 4 if we get here.
18         call void %foo1()
19         ;; This switch is always statically determined.
20         switch uint %V, label %A2 [
21                  uint 4, label %B
22                  uint 17, label %C
23                  uint 42, label %C
24         ]
25 A2:
26         call void %DEAD()
27         call void %DEAD()
28         %cond2 = seteq uint %V, 4    ;; always false
29         br bool %cond2, label %Done, label %C
30
31 A:
32         call void %foo1()
33         %cond = setne uint %V, 4    ;; always true
34         br bool %cond, label %Done, label %C
35
36
37 Done:
38         ret void
39
40 B:
41         call void %foo2()
42         %cond3 = seteq uint %V, 4    ;; always true
43         br bool %cond3, label %Done, label %C
44 C:
45         call void %DEAD()
46         ret void
47 }
48
49 void %test2(uint %V) {
50         switch uint %V, label %A [
51                  uint 4, label %T
52                  uint 17, label %D
53                  uint 1234, label %E
54         ]
55
56 A:  ;; V != 4, 17, 1234 here.
57         call void %foo1()
58         ;; This switch is always statically determined.
59         switch uint %V, label %E [
60                  uint 4, label %C
61                  uint 17, label %C
62                  uint 42, label %D
63         ]
64 C:
65         call void %DEAD()  ;; unreacahble.
66         ret void
67 T:
68         call void %foo1()
69         call void %foo1()
70         ret void
71
72 D:
73         call void %foo1()
74         ret void
75
76 E:
77         ret void
78 }
79