blob: a6848df69e3de15468c079a64952da4e9b9718b3 [file] [log] [blame]
Tanya Lattnerce7d5db2008-03-19 05:39:35 +00001; RUN: llvm-as < %s | \
Reid Spencereb1d74e2007-04-16 17:36:08 +00002; RUN: opt -predsimplify -instcombine -simplifycfg | llvm-dis > %t
Tanya Lattnerce7d5db2008-03-19 05:39:35 +00003; RUN: grep -v declare %t | not grep fail
Dan Gohman43c3db32007-08-15 13:49:33 +00004; RUN: grep -v declare %t | grep pass | count 4
Nick Lewycky05450ae2006-08-28 22:44:55 +00005
Tanya Lattnerce7d5db2008-03-19 05:39:35 +00006
7define void @test1(i32 %x) {
Nick Lewycky05450ae2006-08-28 22:44:55 +00008entry:
Tanya Lattnerce7d5db2008-03-19 05:39:35 +00009 %A = icmp eq i32 %x, 0 ; <i1> [#uses=1]
10 br i1 %A, label %then.1, label %else.1
11then.1: ; preds = %entry
12 %B = icmp eq i32 %x, 1 ; <i1> [#uses=1]
13 br i1 %B, label %then.2, label %else.1
14then.2: ; preds = %then.1
15 call void (...)* @fail( )
16 ret void
17else.1: ; preds = %then.1, %entry
18 ret void
Nick Lewycky05450ae2006-08-28 22:44:55 +000019}
20
Tanya Lattnerce7d5db2008-03-19 05:39:35 +000021define void @test2(i32 %x) {
Nick Lewycky05450ae2006-08-28 22:44:55 +000022entry:
Tanya Lattnerce7d5db2008-03-19 05:39:35 +000023 %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
26then.1: ; preds = %entry
27 br i1 %B, label %then.2, label %else.1
28then.2: ; preds = %then.1
29 call void (...)* @fail( )
30 ret void
31else.1: ; preds = %then.1, %entry
32 ret void
Nick Lewycky05450ae2006-08-28 22:44:55 +000033}
34
Tanya Lattnerce7d5db2008-03-19 05:39:35 +000035define void @test3(i32 %x) {
Nick Lewycky05450ae2006-08-28 22:44:55 +000036entry:
Tanya Lattnerce7d5db2008-03-19 05:39:35 +000037 %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
40then.1: ; preds = %entry
41 br i1 %B, label %then.2, label %else.1
42then.2: ; preds = %then.1
43 call void (...)* @fail( )
44 ret void
45else.1: ; preds = %then.1, %entry
46 ret void
Nick Lewycky05450ae2006-08-28 22:44:55 +000047}
48
Tanya Lattnerce7d5db2008-03-19 05:39:35 +000049define void @test4(i32 %x, i32 %y) {
Nick Lewycky05450ae2006-08-28 22:44:55 +000050entry:
Tanya Lattnerce7d5db2008-03-19 05:39:35 +000051 %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
55then.1: ; preds = %entry
56 %D = icmp eq i32 %x, 0 ; <i1> [#uses=1]
57 br i1 %D, label %then.2, label %else.2
58then.2: ; preds = %then.1
59 %E = icmp eq i32 %y, 0 ; <i1> [#uses=1]
60 br i1 %E, label %else.1, label %else.2
61else.1: ; preds = %then.2, %entry
62 ret void
63else.2: ; preds = %then.2, %then.1
64 call void (...)* @fail( )
65 ret void
Nick Lewycky05450ae2006-08-28 22:44:55 +000066}
67
Tanya Lattnerce7d5db2008-03-19 05:39:35 +000068define void @test5(i32 %x) {
Nick Lewycky05450ae2006-08-28 22:44:55 +000069entry:
Tanya Lattnerce7d5db2008-03-19 05:39:35 +000070 %A = icmp eq i32 %x, 0 ; <i1> [#uses=1]
71 br i1 %A, label %then.1, label %else.1
72then.1: ; preds = %else.1, %entry
73 ret void
74then.2: ; preds = %else.1
75 call void (...)* @fail( )
76 ret void
77else.1: ; preds = %entry
78 %B = icmp eq i32 %x, 0 ; <i1> [#uses=1]
79 br i1 %B, label %then.2, label %then.1
Nick Lewycky05450ae2006-08-28 22:44:55 +000080}
81
Tanya Lattnerce7d5db2008-03-19 05:39:35 +000082define void @test6(i32 %x, i32 %y) {
Nick Lewycky05450ae2006-08-28 22:44:55 +000083entry:
Tanya Lattnerce7d5db2008-03-19 05:39:35 +000084 %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
88then.1: ; preds = %else.2, %entry
89 ret void
90then.2: ; preds = %else.2, %else.1
91 call void (...)* @fail( )
92 ret void
93else.1: ; preds = %entry
94 %D = icmp eq i32 %x, 0 ; <i1> [#uses=1]
95 br i1 %D, label %then.2, label %else.2
96else.2: ; preds = %else.1
97 %E = icmp ne i32 %y, 0 ; <i1> [#uses=1]
98 br i1 %E, label %then.1, label %then.2
Nick Lewycky05450ae2006-08-28 22:44:55 +000099}
100
Tanya Lattnerce7d5db2008-03-19 05:39:35 +0000101define void @test7(i32 %x) {
Nick Lewycky05450ae2006-08-28 22:44:55 +0000102entry:
Tanya Lattnerce7d5db2008-03-19 05:39:35 +0000103 %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
106then.1: ; preds = %entry
107 %C = icmp eq i32 %x, 1 ; <i1> [#uses=1]
108 br i1 %C, label %then.2, label %else.1
109then.2: ; preds = %then.1
110 call void (...)* @fail( )
111 ret void
112else.1: ; preds = %then.1, %entry
113 ret void
Nick Lewycky05450ae2006-08-28 22:44:55 +0000114}
115
Tanya Lattnerce7d5db2008-03-19 05:39:35 +0000116define void @test8(i32 %x) {
Nick Lewycky05450ae2006-08-28 22:44:55 +0000117entry:
Tanya Lattnerce7d5db2008-03-19 05:39:35 +0000118 %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
121then.1: ; preds = %entry
122 %C = icmp eq i32 %A, 1 ; <i1> [#uses=1]
123 br i1 %C, label %then.2, label %else.2
124then.2: ; preds = %then.1, %entry
125 ret void
126else.2: ; preds = %then.1
127 call void (...)* @fail( )
128 ret void
Nick Lewycky05450ae2006-08-28 22:44:55 +0000129}
130
Tanya Lattnerce7d5db2008-03-19 05:39:35 +0000131define void @test9(i32 %y, i32 %z) {
Nick Lewyckya3a68bd2006-09-02 19:40:38 +0000132entry:
Tanya Lattnerce7d5db2008-03-19 05:39:35 +0000133 %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
138cond_true: ; preds = %entry
139 %D = icmp eq i32 %x, 8 ; <i1> [#uses=1]
140 br i1 %D, label %then, label %oops
141then: ; preds = %cond_true
142 call void (...)* @pass( )
143 ret void
144oops: ; preds = %cond_true
145 call void (...)* @fail( )
146 ret void
147return: ; preds = %entry
148 ret void
Nick Lewyckya3a68bd2006-09-02 19:40:38 +0000149}
150
Tanya Lattnerce7d5db2008-03-19 05:39:35 +0000151define void @test10() {
Nick Lewycky802fe272006-10-22 19:53:27 +0000152entry:
Tanya Lattnerce7d5db2008-03-19 05:39:35 +0000153 %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
156cond_true: ; preds = %entry
157 call void (...)* @fail( )
158 ret void
159cond_false: ; preds = %entry
160 call void (...)* @pass( )
161 ret void
Nick Lewycky802fe272006-10-22 19:53:27 +0000162}
163
Tanya Lattnerce7d5db2008-03-19 05:39:35 +0000164define void @switch1(i32 %x) {
Nick Lewyckya3a68bd2006-09-02 19:40:38 +0000165entry:
Tanya Lattnerce7d5db2008-03-19 05:39:35 +0000166 %A = icmp eq i32 %x, 10 ; <i1> [#uses=1]
167 br i1 %A, label %return, label %cond_false
168cond_false: ; preds = %entry
169 switch i32 %x, label %return [
170 i32 9, label %then1
171 i32 10, label %then2
172 ]
173then1: ; preds = %cond_false
174 call void (...)* @pass( )
175 ret void
176then2: ; preds = %cond_false
177 call void (...)* @fail( )
178 ret void
179return: ; preds = %cond_false, %entry
180 ret void
Nick Lewyckya3a68bd2006-09-02 19:40:38 +0000181}
182
Tanya Lattnerce7d5db2008-03-19 05:39:35 +0000183define void @switch2(i32 %x) {
Nick Lewyckya3a68bd2006-09-02 19:40:38 +0000184entry:
Tanya Lattnerce7d5db2008-03-19 05:39:35 +0000185 %A = icmp eq i32 %x, 10 ; <i1> [#uses=1]
186 br i1 %A, label %return, label %cond_false
187cond_false: ; preds = %entry
188 switch i32 %x, label %return [
189 i32 8, label %then1
190 i32 9, label %then1
191 i32 10, label %then1
192 ]
193then1: ; 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
196then2: ; preds = %then1
197 call void (...)* @pass( )
198 ret void
199return: ; preds = %then1, %cond_false, %entry
200 ret void
Nick Lewyckya3a68bd2006-09-02 19:40:38 +0000201}
202
Tanya Lattnerce7d5db2008-03-19 05:39:35 +0000203define void @switch3(i32 %x) {
Nick Lewyckya3a68bd2006-09-02 19:40:38 +0000204entry:
Tanya Lattnerce7d5db2008-03-19 05:39:35 +0000205 %A = icmp eq i32 %x, 10 ; <i1> [#uses=1]
206 br i1 %A, label %return, label %cond_false
207cond_false: ; preds = %entry
208 switch i32 %x, label %return [
209 i32 9, label %then1
210 i32 10, label %then1
211 ]
212then1: ; preds = %cond_false, %cond_false
213 %B = icmp eq i32 %x, 9 ; <i1> [#uses=1]
214 br i1 %B, label %return, label %oops
215oops: ; preds = %then1
216 call void (...)* @fail( )
217 ret void
218return: ; preds = %then1, %cond_false, %entry
219 ret void
Nick Lewyckya3a68bd2006-09-02 19:40:38 +0000220}
221
Tanya Lattnerce7d5db2008-03-19 05:39:35 +0000222define void @switch4(i32 %x) {
Nick Lewyckya3a68bd2006-09-02 19:40:38 +0000223entry:
Tanya Lattnerce7d5db2008-03-19 05:39:35 +0000224 %A = icmp eq i32 %x, 10 ; <i1> [#uses=1]
225 br i1 %A, label %then1, label %cond_false
226cond_false: ; preds = %entry
227 switch i32 %x, label %default [
228 i32 9, label %then1
229 i32 10, label %then2
230 ]
231then1: ; preds = %default, %cond_false, %entry
232 ret void
233then2: ; preds = %cond_false
234 ret void
235default: ; preds = %cond_false
236 %B = icmp eq i32 %x, 9 ; <i1> [#uses=1]
237 br i1 %B, label %oops, label %then1
238oops: ; preds = %default
239 call void (...)* @fail( )
240 ret void
Nick Lewyckya3a68bd2006-09-02 19:40:38 +0000241}
242
Tanya Lattnerce7d5db2008-03-19 05:39:35 +0000243define void @select1(i32 %x) {
Nick Lewyckya3a68bd2006-09-02 19:40:38 +0000244entry:
Tanya Lattnerce7d5db2008-03-19 05:39:35 +0000245 %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
249then: ; preds = %entry
250 br i1 %A, label %return, label %oops
251else: ; preds = %entry
252 br i1 %A, label %oops, label %return
253oops: ; preds = %else, %then
254 call void (...)* @fail( )
255 ret void
256return: ; preds = %else, %then
257 ret void
Nick Lewyckya3a68bd2006-09-02 19:40:38 +0000258}
259
Tanya Lattnerce7d5db2008-03-19 05:39:35 +0000260define void @select2(i32 %x) {
Nick Lewyckya3a68bd2006-09-02 19:40:38 +0000261entry:
Tanya Lattnerce7d5db2008-03-19 05:39:35 +0000262 %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
266then: ; preds = %entry
267 br i1 %C, label %return, label %oops
268else: ; preds = %entry
269 br i1 %C, label %oops, label %return
270oops: ; preds = %else, %then
271 call void (...)* @fail( )
272 ret void
273return: ; preds = %else, %then
274 ret void
Nick Lewyckya3a68bd2006-09-02 19:40:38 +0000275}
Nick Lewycky05450ae2006-08-28 22:44:55 +0000276
Tanya Lattnerce7d5db2008-03-19 05:39:35 +0000277declare void @fail(...)
Nick Lewycky05450ae2006-08-28 22:44:55 +0000278
Tanya Lattnerce7d5db2008-03-19 05:39:35 +0000279declare void @pass(...)