This pass has never worked correctly. Remove.
[oota-llvm.git] / test / Transforms / PRE / basictest.ll
1 ; Basic testcases - these are only tested by inspection, but illustrate the 
2 ; basic cases PRE can handle.
3 ;
4 ; RUN: llvm-as < %s | opt -pre -disable-output
5
6 declare void %use(int)
7 declare int %get()
8
9 void %test0(int %A, int %B) {   ;; Fully redundant
10         %X = add int %A, %B
11         %Y = add int %A, %B
12         call void %use(int %X)
13         call void %use(int %Y)
14         ret void
15 }
16
17 void %test1(int %cond, int %A, int %B) {
18         switch int %cond, label %Out [ 
19                 int 1, label %B1
20                 int 2, label %B2
21                 int 3, label %Cont ]
22 B1:
23         %X1 = add int %A, %B
24         call void %use(int %X1)
25         br label %Cont
26 B2:
27         %X2 = add int %A, %B
28         call void %use(int %X2)
29         br label %Cont
30
31 Cont:
32         br label %Next
33
34 Next:
35         %X3 = add int %A, %B
36         call void %use(int %X3)
37         br label %Out
38
39 Out:
40         ret void
41 }
42
43
44 void %testloop(bool %cond, int %A, int %B) {
45         br label %Loop
46
47 Loop:
48         %C = add int %A, %B     ; loop invariant
49         call void %use(int %C)
50
51         %D = add int %C, %B
52         call void %use(int %D)
53
54         br bool %cond, label %Loop, label %Exit
55 Exit:
56         ret void
57 }
58
59
60
61 void %test3(bool %cond, int %A, int %B) {
62         br bool %cond, label %A, label %B
63
64 A:
65         %C = add int %A, %B
66         call void %use(int %C)
67         br label %Merge
68 B:
69         %D = add int %A, %B
70         call void %use(int %D)
71         br label %Merge
72
73 Merge:
74         %E = add int %A, %B
75         call void %use(int %E)
76         ret void
77 }
78
79 void %test4(bool %cond, int %A, int %B) {
80         br bool %cond, label %A, label %B
81
82 A:
83         br label %Merge
84 B:
85         %D = add int %A, %B
86         call void %use(int %D)
87         br label %Merge
88
89 Merge:
90         %E = add int %A, %B
91         call void %use(int %E)
92         ret void
93 }
94
95
96 int %test5(bool %cond, int %A, int %B) {
97         br label %Loop
98
99 Loop:
100         br bool %cond, label %A, label %B
101
102 A:
103         br label %Merge
104 B:
105         %D = add int %A, %B
106         call void %use(int %D)
107         br label %Merge
108
109 Merge:
110         br bool %cond, label %Loop, label %Out
111
112 Out:
113         %E = add int %A, %B
114         ret int %E
115 }
116
117
118 void %test6(bool %cond, int %A, int %B) {
119         br bool %cond, label %A1, label %Def
120 A1:     br label %Around
121 Def:
122         %C = add int %A, %B
123         call void %use(int %C)
124         br bool %cond, label %F1, label %F2
125 F1:     br label %Around
126 F2:     br label %Y
127
128 Around:
129         br label %Y
130 Y:
131         %D = add int %A, %B
132         call void %use(int %D)
133         ret void
134 }
135
136 void %testloop-load(bool %cond, int* %P, int* %Q) {
137         br label %Loop
138
139 Loop:
140         store int 5, int* %Q          ;; Q may alias P
141         %D = load int* %P             ;; Should not hoist load out of loop
142         call void %use(int %D)
143
144         br bool %cond, label %Loop, label %Exit
145 Exit:
146         ret void
147 }
148
149 void %test7(bool %cond) {      ;; Test anticipatibility
150         br label %Loop
151
152 Loop:
153         %A = call int %get()
154         %B = add int %A, %A          ; Cannot hoist from loop
155         call void %use(int %B)
156
157         br bool %cond, label %Loop, label %Exit
158 Exit:
159         ret void
160 }
161
162
163 void %test8(bool %cond, int %A, int %B) {   ;; Test irreducible loop
164         br bool %cond, label %LoopHead, label %LoopMiddle
165
166 LoopHead:
167         %C = add int %A, %B          ; Should hoist from loop
168         call void %use(int %C)
169         br label %LoopMiddle
170
171 LoopMiddle:
172
173         br bool %cond, label %LoopHead, label %Exit
174 Exit:
175         %D = add int %A, %B
176         call void %use(int %D)
177         ret void
178 }
179
180
181 void %test9(bool %cond, int %A, int %B) {   ;; Test irreducible loop
182         br bool %cond, label %LoopHead, label %LoopMiddle
183
184 LoopHead:
185         call int %get()              ; random function call
186         br label %LoopMiddle
187
188 LoopMiddle:
189         %C = add int %A, %B          ; Should hoist from loop
190         call void %use(int %C)
191         br bool %cond, label %LoopHead, label %Exit
192 Exit:
193         ret void
194 }