1 ; RUN: llvm-as < %s | \
2 ; RUN: opt -predsimplify -instcombine -simplifycfg | llvm-dis > %t
3 ; RUN: grep -v declare %t | not grep fail
4 ; RUN: grep -v declare %t | grep pass | count 4
7 define void @test1(i32 %x) {
9 %A = icmp eq i32 %x, 0 ; <i1> [#uses=1]
10 br i1 %A, label %then.1, label %else.1
11 then.1: ; preds = %entry
12 %B = icmp eq i32 %x, 1 ; <i1> [#uses=1]
13 br i1 %B, label %then.2, label %else.1
14 then.2: ; preds = %then.1
15 call void (...)* @fail( )
17 else.1: ; preds = %then.1, %entry
21 define void @test2(i32 %x) {
23 %A = icmp eq i32 %x, 0 ; <i1> [#uses=1]
24 %B = icmp eq i32 %x, 1 ; <i1> [#uses=1]
25 br i1 %A, label %then.1, label %else.1
26 then.1: ; preds = %entry
27 br i1 %B, label %then.2, label %else.1
28 then.2: ; preds = %then.1
29 call void (...)* @fail( )
31 else.1: ; preds = %then.1, %entry
35 define void @test3(i32 %x) {
37 %A = icmp eq i32 %x, 0 ; <i1> [#uses=1]
38 %B = icmp eq i32 %x, 1 ; <i1> [#uses=1]
39 br i1 %A, label %then.1, label %else.1
40 then.1: ; preds = %entry
41 br i1 %B, label %then.2, label %else.1
42 then.2: ; preds = %then.1
43 call void (...)* @fail( )
45 else.1: ; preds = %then.1, %entry
49 define void @test4(i32 %x, i32 %y) {
51 %A = icmp eq i32 %x, 0 ; <i1> [#uses=1]
52 %B = icmp eq i32 %y, 0 ; <i1> [#uses=1]
53 %C = and i1 %A, %B ; <i1> [#uses=1]
54 br i1 %C, label %then.1, label %else.1
55 then.1: ; preds = %entry
56 %D = icmp eq i32 %x, 0 ; <i1> [#uses=1]
57 br i1 %D, label %then.2, label %else.2
58 then.2: ; preds = %then.1
59 %E = icmp eq i32 %y, 0 ; <i1> [#uses=1]
60 br i1 %E, label %else.1, label %else.2
61 else.1: ; preds = %then.2, %entry
63 else.2: ; preds = %then.2, %then.1
64 call void (...)* @fail( )
68 define void @test5(i32 %x) {
70 %A = icmp eq i32 %x, 0 ; <i1> [#uses=1]
71 br i1 %A, label %then.1, label %else.1
72 then.1: ; preds = %else.1, %entry
74 then.2: ; preds = %else.1
75 call void (...)* @fail( )
77 else.1: ; preds = %entry
78 %B = icmp eq i32 %x, 0 ; <i1> [#uses=1]
79 br i1 %B, label %then.2, label %then.1
82 define void @test6(i32 %x, i32 %y) {
84 %A = icmp eq i32 %x, 0 ; <i1> [#uses=1]
85 %B = icmp eq i32 %y, 0 ; <i1> [#uses=1]
86 %C = or i1 %A, %B ; <i1> [#uses=1]
87 br i1 %C, label %then.1, label %else.1
88 then.1: ; preds = %else.2, %entry
90 then.2: ; preds = %else.2, %else.1
91 call void (...)* @fail( )
93 else.1: ; preds = %entry
94 %D = icmp eq i32 %x, 0 ; <i1> [#uses=1]
95 br i1 %D, label %then.2, label %else.2
96 else.2: ; preds = %else.1
97 %E = icmp ne i32 %y, 0 ; <i1> [#uses=1]
98 br i1 %E, label %then.1, label %then.2
101 define void @test7(i32 %x) {
103 %A = icmp ne i32 %x, 0 ; <i1> [#uses=1]
104 %B = xor i1 %A, true ; <i1> [#uses=1]
105 br i1 %B, label %then.1, label %else.1
106 then.1: ; preds = %entry
107 %C = icmp eq i32 %x, 1 ; <i1> [#uses=1]
108 br i1 %C, label %then.2, label %else.1
109 then.2: ; preds = %then.1
110 call void (...)* @fail( )
112 else.1: ; preds = %then.1, %entry
116 define void @test8(i32 %x) {
118 %A = add i32 %x, 1 ; <i32> [#uses=1]
119 %B = icmp eq i32 %x, 0 ; <i1> [#uses=1]
120 br i1 %B, label %then.1, label %then.2
121 then.1: ; preds = %entry
122 %C = icmp eq i32 %A, 1 ; <i1> [#uses=1]
123 br i1 %C, label %then.2, label %else.2
124 then.2: ; preds = %then.1, %entry
126 else.2: ; preds = %then.1
127 call void (...)* @fail( )
131 define void @test9(i32 %y, i32 %z) {
133 %x = add i32 %y, %z ; <i32> [#uses=1]
134 %A = icmp eq i32 %y, 3 ; <i1> [#uses=1]
135 %B = icmp eq i32 %z, 5 ; <i1> [#uses=1]
136 %C = and i1 %A, %B ; <i1> [#uses=1]
137 br i1 %C, label %cond_true, label %return
138 cond_true: ; preds = %entry
139 %D = icmp eq i32 %x, 8 ; <i1> [#uses=1]
140 br i1 %D, label %then, label %oops
141 then: ; preds = %cond_true
142 call void (...)* @pass( )
144 oops: ; preds = %cond_true
145 call void (...)* @fail( )
147 return: ; preds = %entry
151 define void @test10() {
153 %A = alloca i32 ; <i32*> [#uses=1]
154 %B = icmp eq i32* %A, null ; <i1> [#uses=1]
155 br i1 %B, label %cond_true, label %cond_false
156 cond_true: ; preds = %entry
157 call void (...)* @fail( )
159 cond_false: ; preds = %entry
160 call void (...)* @pass( )
164 define void @switch1(i32 %x) {
166 %A = icmp eq i32 %x, 10 ; <i1> [#uses=1]
167 br i1 %A, label %return, label %cond_false
168 cond_false: ; preds = %entry
169 switch i32 %x, label %return [
173 then1: ; preds = %cond_false
174 call void (...)* @pass( )
176 then2: ; preds = %cond_false
177 call void (...)* @fail( )
179 return: ; preds = %cond_false, %entry
183 define void @switch2(i32 %x) {
185 %A = icmp eq i32 %x, 10 ; <i1> [#uses=1]
186 br i1 %A, label %return, label %cond_false
187 cond_false: ; preds = %entry
188 switch i32 %x, label %return [
193 then1: ; preds = %cond_false, %cond_false, %cond_false
194 %B = icmp ne i32 %x, 8 ; <i1> [#uses=1]
195 br i1 %B, label %then2, label %return
196 then2: ; preds = %then1
197 call void (...)* @pass( )
199 return: ; preds = %then1, %cond_false, %entry
203 define void @switch3(i32 %x) {
205 %A = icmp eq i32 %x, 10 ; <i1> [#uses=1]
206 br i1 %A, label %return, label %cond_false
207 cond_false: ; preds = %entry
208 switch i32 %x, label %return [
212 then1: ; preds = %cond_false, %cond_false
213 %B = icmp eq i32 %x, 9 ; <i1> [#uses=1]
214 br i1 %B, label %return, label %oops
215 oops: ; preds = %then1
216 call void (...)* @fail( )
218 return: ; preds = %then1, %cond_false, %entry
222 define void @switch4(i32 %x) {
224 %A = icmp eq i32 %x, 10 ; <i1> [#uses=1]
225 br i1 %A, label %then1, label %cond_false
226 cond_false: ; preds = %entry
227 switch i32 %x, label %default [
231 then1: ; preds = %default, %cond_false, %entry
233 then2: ; preds = %cond_false
235 default: ; preds = %cond_false
236 %B = icmp eq i32 %x, 9 ; <i1> [#uses=1]
237 br i1 %B, label %oops, label %then1
238 oops: ; preds = %default
239 call void (...)* @fail( )
243 define void @select1(i32 %x) {
245 %A = icmp eq i32 %x, 10 ; <i1> [#uses=3]
246 %B = select i1 %A, i32 1, i32 2 ; <i32> [#uses=1]
247 %C = icmp eq i32 %B, 1 ; <i1> [#uses=1]
248 br i1 %C, label %then, label %else
249 then: ; preds = %entry
250 br i1 %A, label %return, label %oops
251 else: ; preds = %entry
252 br i1 %A, label %oops, label %return
253 oops: ; preds = %else, %then
254 call void (...)* @fail( )
256 return: ; preds = %else, %then
260 define void @select2(i32 %x) {
262 %A = icmp eq i32 %x, 10 ; <i1> [#uses=2]
263 %B = select i1 %A, i32 1, i32 2 ; <i32> [#uses=1]
264 %C = icmp eq i32 %B, 1 ; <i1> [#uses=2]
265 br i1 %A, label %then, label %else
266 then: ; preds = %entry
267 br i1 %C, label %return, label %oops
268 else: ; preds = %entry
269 br i1 %C, label %oops, label %return
270 oops: ; preds = %else, %then
271 call void (...)* @fail( )
273 return: ; preds = %else, %then
277 declare void @fail(...)
279 declare void @pass(...)