blob: 095794923b921b276f8f467f8cb26a8ade807fe2 [file] [log] [blame]
Duncan Sands8fb2c382011-01-20 13:21:55 +00001; RUN: opt < %s -instsimplify -S | FileCheck %s
2target datalayout = "p:32:32"
3
4define i1 @ptrtoint() {
Stephen Linc1c7a132013-07-14 01:42:54 +00005; CHECK-LABEL: @ptrtoint(
Duncan Sands8fb2c382011-01-20 13:21:55 +00006 %a = alloca i8
7 %tmp = ptrtoint i8* %a to i32
8 %r = icmp eq i32 %tmp, 0
9 ret i1 %r
10; CHECK: ret i1 false
11}
12
Benjamin Kramerea51f622012-02-16 13:49:39 +000013define i1 @bitcast() {
Stephen Linc1c7a132013-07-14 01:42:54 +000014; CHECK-LABEL: @bitcast(
Benjamin Kramerea51f622012-02-16 13:49:39 +000015 %a = alloca i32
16 %b = alloca i64
17 %x = bitcast i32* %a to i8*
18 %y = bitcast i64* %b to i8*
19 %cmp = icmp eq i8* %x, %y
20 ret i1 %cmp
21; CHECK-NEXT: ret i1 false
22}
23
24define i1 @gep() {
Stephen Linc1c7a132013-07-14 01:42:54 +000025; CHECK-LABEL: @gep(
Benjamin Kramerea51f622012-02-16 13:49:39 +000026 %a = alloca [3 x i8], align 8
27 %x = getelementptr inbounds [3 x i8]* %a, i32 0, i32 0
28 %cmp = icmp eq i8* %x, null
29 ret i1 %cmp
30; CHECK-NEXT: ret i1 false
31}
32
Eli Friedman952d1f92012-02-18 03:29:25 +000033define i1 @gep2() {
Stephen Linc1c7a132013-07-14 01:42:54 +000034; CHECK-LABEL: @gep2(
Eli Friedman952d1f92012-02-18 03:29:25 +000035 %a = alloca [3 x i8], align 8
36 %x = getelementptr inbounds [3 x i8]* %a, i32 0, i32 0
37 %y = getelementptr inbounds [3 x i8]* %a, i32 0, i32 0
38 %cmp = icmp eq i8* %x, %y
39 ret i1 %cmp
40; CHECK-NEXT: ret i1 true
41}
42
Nick Lewycky3db143e2012-02-26 02:09:49 +000043; PR11238
44%gept = type { i32, i32 }
45@gepy = global %gept zeroinitializer, align 8
46@gepz = extern_weak global %gept
47
48define i1 @gep3() {
Stephen Linc1c7a132013-07-14 01:42:54 +000049; CHECK-LABEL: @gep3(
Nick Lewycky3db143e2012-02-26 02:09:49 +000050 %x = alloca %gept, align 8
51 %a = getelementptr %gept* %x, i64 0, i32 0
52 %b = getelementptr %gept* %x, i64 0, i32 1
53 %equal = icmp eq i32* %a, %b
54 ret i1 %equal
55; CHECK-NEXT: ret i1 false
56}
57
58define i1 @gep4() {
Stephen Linc1c7a132013-07-14 01:42:54 +000059; CHECK-LABEL: @gep4(
Nick Lewycky3db143e2012-02-26 02:09:49 +000060 %x = alloca %gept, align 8
61 %a = getelementptr %gept* @gepy, i64 0, i32 0
62 %b = getelementptr %gept* @gepy, i64 0, i32 1
63 %equal = icmp eq i32* %a, %b
64 ret i1 %equal
65; CHECK-NEXT: ret i1 false
66}
67
68define i1 @gep5() {
Stephen Linc1c7a132013-07-14 01:42:54 +000069; CHECK-LABEL: @gep5(
Nick Lewycky3db143e2012-02-26 02:09:49 +000070 %x = alloca %gept, align 8
71 %a = getelementptr inbounds %gept* %x, i64 0, i32 1
72 %b = getelementptr %gept* @gepy, i64 0, i32 0
73 %equal = icmp eq i32* %a, %b
74 ret i1 %equal
75; CHECK-NEXT: ret i1 false
76}
77
78define i1 @gep6(%gept* %x) {
79; Same as @gep3 but potentially null.
Stephen Linc1c7a132013-07-14 01:42:54 +000080; CHECK-LABEL: @gep6(
Nick Lewycky3db143e2012-02-26 02:09:49 +000081 %a = getelementptr %gept* %x, i64 0, i32 0
82 %b = getelementptr %gept* %x, i64 0, i32 1
83 %equal = icmp eq i32* %a, %b
84 ret i1 %equal
85; CHECK-NEXT: ret i1 false
86}
87
88define i1 @gep7(%gept* %x) {
Stephen Linc1c7a132013-07-14 01:42:54 +000089; CHECK-LABEL: @gep7(
Nick Lewycky3db143e2012-02-26 02:09:49 +000090 %a = getelementptr %gept* %x, i64 0, i32 0
91 %b = getelementptr %gept* @gepz, i64 0, i32 0
92 %equal = icmp eq i32* %a, %b
93 ret i1 %equal
94; CHECK: ret i1 %equal
95}
96
97define i1 @gep8(%gept* %x) {
Stephen Linc1c7a132013-07-14 01:42:54 +000098; CHECK-LABEL: @gep8(
Nick Lewycky3db143e2012-02-26 02:09:49 +000099 %a = getelementptr %gept* %x, i32 1
100 %b = getelementptr %gept* %x, i32 -1
101 %equal = icmp ugt %gept* %a, %b
102 ret i1 %equal
103; CHECK: ret i1 %equal
104}
105
Chandler Carruth8059c842012-03-25 21:28:14 +0000106define i1 @gep9(i8* %ptr) {
Stephen Linc1c7a132013-07-14 01:42:54 +0000107; CHECK-LABEL: @gep9(
Chandler Carruth8059c842012-03-25 21:28:14 +0000108; CHECK-NOT: ret
109; CHECK: ret i1 true
110
111entry:
112 %first1 = getelementptr inbounds i8* %ptr, i32 0
113 %first2 = getelementptr inbounds i8* %first1, i32 1
114 %first3 = getelementptr inbounds i8* %first2, i32 2
115 %first4 = getelementptr inbounds i8* %first3, i32 4
116 %last1 = getelementptr inbounds i8* %first2, i32 48
117 %last2 = getelementptr inbounds i8* %last1, i32 8
118 %last3 = getelementptr inbounds i8* %last2, i32 -4
119 %last4 = getelementptr inbounds i8* %last3, i32 -4
120 %first.int = ptrtoint i8* %first4 to i32
121 %last.int = ptrtoint i8* %last4 to i32
122 %cmp = icmp ne i32 %last.int, %first.int
123 ret i1 %cmp
124}
125
126define i1 @gep10(i8* %ptr) {
Stephen Linc1c7a132013-07-14 01:42:54 +0000127; CHECK-LABEL: @gep10(
Chandler Carruth8059c842012-03-25 21:28:14 +0000128; CHECK-NOT: ret
129; CHECK: ret i1 true
130
131entry:
132 %first1 = getelementptr inbounds i8* %ptr, i32 -2
133 %first2 = getelementptr inbounds i8* %first1, i32 44
134 %last1 = getelementptr inbounds i8* %ptr, i32 48
135 %last2 = getelementptr inbounds i8* %last1, i32 -6
136 %first.int = ptrtoint i8* %first2 to i32
137 %last.int = ptrtoint i8* %last2 to i32
138 %cmp = icmp eq i32 %last.int, %first.int
139 ret i1 %cmp
140}
141
142define i1 @gep11(i8* %ptr) {
Stephen Linc1c7a132013-07-14 01:42:54 +0000143; CHECK-LABEL: @gep11(
Chandler Carruth8059c842012-03-25 21:28:14 +0000144; CHECK-NOT: ret
145; CHECK: ret i1 true
146
147entry:
148 %first1 = getelementptr inbounds i8* %ptr, i32 -2
149 %last1 = getelementptr inbounds i8* %ptr, i32 48
150 %last2 = getelementptr inbounds i8* %last1, i32 -6
151 %cmp = icmp ult i8* %first1, %last2
152 ret i1 %cmp
153}
154
155define i1 @gep12(i8* %ptr) {
Stephen Linc1c7a132013-07-14 01:42:54 +0000156; CHECK-LABEL: @gep12(
Chandler Carruth8059c842012-03-25 21:28:14 +0000157; CHECK-NOT: ret
158; CHECK: ret i1 %cmp
159
160entry:
161 %first1 = getelementptr inbounds i8* %ptr, i32 -2
162 %last1 = getelementptr inbounds i8* %ptr, i32 48
163 %last2 = getelementptr inbounds i8* %last1, i32 -6
164 %cmp = icmp slt i8* %first1, %last2
165 ret i1 %cmp
166}
167
Chandler Carruth80d3e562012-12-07 02:08:58 +0000168define i1 @gep13(i8* %ptr) {
Stephen Linc1c7a132013-07-14 01:42:54 +0000169; CHECK-LABEL: @gep13(
Chandler Carruth80d3e562012-12-07 02:08:58 +0000170; We can prove this GEP is non-null because it is inbounds.
171 %x = getelementptr inbounds i8* %ptr, i32 1
172 %cmp = icmp eq i8* %x, null
173 ret i1 %cmp
174; CHECK-NEXT: ret i1 false
175}
176
177define i1 @gep14({ {}, i8 }* %ptr) {
Stephen Linc1c7a132013-07-14 01:42:54 +0000178; CHECK-LABEL: @gep14(
Chandler Carruth80d3e562012-12-07 02:08:58 +0000179; We can't simplify this because the offset of one in the GEP actually doesn't
180; move the pointer.
181 %x = getelementptr inbounds { {}, i8 }* %ptr, i32 0, i32 1
182 %cmp = icmp eq i8* %x, null
183 ret i1 %cmp
184; CHECK-NOT: ret i1 false
185}
186
187define i1 @gep15({ {}, [4 x {i8, i8}]}* %ptr, i32 %y) {
Stephen Linc1c7a132013-07-14 01:42:54 +0000188; CHECK-LABEL: @gep15(
Chandler Carruth80d3e562012-12-07 02:08:58 +0000189; We can prove this GEP is non-null even though there is a user value, as we
190; would necessarily violate inbounds on one side or the other.
191 %x = getelementptr inbounds { {}, [4 x {i8, i8}]}* %ptr, i32 0, i32 1, i32 %y, i32 1
192 %cmp = icmp eq i8* %x, null
193 ret i1 %cmp
194; CHECK-NEXT: ret i1 false
195}
196
197define i1 @gep16(i8* %ptr, i32 %a) {
Stephen Linc1c7a132013-07-14 01:42:54 +0000198; CHECK-LABEL: @gep16(
Chandler Carruth80d3e562012-12-07 02:08:58 +0000199; We can prove this GEP is non-null because it is inbounds and because we know
200; %b is non-zero even though we don't know its value.
201 %b = or i32 %a, 1
202 %x = getelementptr inbounds i8* %ptr, i32 %b
203 %cmp = icmp eq i8* %x, null
204 ret i1 %cmp
205; CHECK-NEXT: ret i1 false
206}
207
Duncan Sands8fb2c382011-01-20 13:21:55 +0000208define i1 @zext(i32 %x) {
Stephen Linc1c7a132013-07-14 01:42:54 +0000209; CHECK-LABEL: @zext(
Duncan Sands8fb2c382011-01-20 13:21:55 +0000210 %e1 = zext i32 %x to i64
211 %e2 = zext i32 %x to i64
212 %r = icmp eq i64 %e1, %e2
213 ret i1 %r
214; CHECK: ret i1 true
215}
216
217define i1 @zext2(i1 %x) {
Stephen Linc1c7a132013-07-14 01:42:54 +0000218; CHECK-LABEL: @zext2(
Duncan Sands8fb2c382011-01-20 13:21:55 +0000219 %e = zext i1 %x to i32
220 %c = icmp ne i32 %e, 0
221 ret i1 %c
222; CHECK: ret i1 %x
223}
224
Duncan Sandsd3951082011-01-25 09:38:29 +0000225define i1 @zext3() {
Stephen Linc1c7a132013-07-14 01:42:54 +0000226; CHECK-LABEL: @zext3(
Duncan Sandsd3951082011-01-25 09:38:29 +0000227 %e = zext i1 1 to i32
228 %c = icmp ne i32 %e, 0
229 ret i1 %c
230; CHECK: ret i1 true
231}
232
Duncan Sands8fb2c382011-01-20 13:21:55 +0000233define i1 @sext(i32 %x) {
Stephen Linc1c7a132013-07-14 01:42:54 +0000234; CHECK-LABEL: @sext(
Duncan Sands8fb2c382011-01-20 13:21:55 +0000235 %e1 = sext i32 %x to i64
236 %e2 = sext i32 %x to i64
237 %r = icmp eq i64 %e1, %e2
238 ret i1 %r
239; CHECK: ret i1 true
240}
241
242define i1 @sext2(i1 %x) {
Stephen Linc1c7a132013-07-14 01:42:54 +0000243; CHECK-LABEL: @sext2(
Duncan Sands8fb2c382011-01-20 13:21:55 +0000244 %e = sext i1 %x to i32
245 %c = icmp ne i32 %e, 0
246 ret i1 %c
247; CHECK: ret i1 %x
248}
Duncan Sandsd3951082011-01-25 09:38:29 +0000249
250define i1 @sext3() {
Stephen Linc1c7a132013-07-14 01:42:54 +0000251; CHECK-LABEL: @sext3(
Duncan Sandsd3951082011-01-25 09:38:29 +0000252 %e = sext i1 1 to i32
253 %c = icmp ne i32 %e, 0
254 ret i1 %c
255; CHECK: ret i1 true
256}
257
258define i1 @add(i32 %x, i32 %y) {
Stephen Linc1c7a132013-07-14 01:42:54 +0000259; CHECK-LABEL: @add(
Duncan Sandsd3951082011-01-25 09:38:29 +0000260 %l = lshr i32 %x, 1
Duncan Sands9e9d5b22011-01-25 15:14:15 +0000261 %q = lshr i32 %y, 1
262 %r = or i32 %q, 1
Duncan Sandsd3951082011-01-25 09:38:29 +0000263 %s = add i32 %l, %r
264 %c = icmp eq i32 %s, 0
265 ret i1 %c
Duncan Sands9e9d5b22011-01-25 15:14:15 +0000266; CHECK: ret i1 false
Duncan Sandsd3951082011-01-25 09:38:29 +0000267}
268
269define i1 @add2(i8 %x, i8 %y) {
Stephen Linc1c7a132013-07-14 01:42:54 +0000270; CHECK-LABEL: @add2(
Duncan Sandsd3951082011-01-25 09:38:29 +0000271 %l = or i8 %x, 128
272 %r = or i8 %y, 129
273 %s = add i8 %l, %r
274 %c = icmp eq i8 %s, 0
275 ret i1 %c
276; CHECK: ret i1 false
277}
278
Duncan Sands9e9d5b22011-01-25 15:14:15 +0000279define i1 @add3(i8 %x, i8 %y) {
Stephen Linc1c7a132013-07-14 01:42:54 +0000280; CHECK-LABEL: @add3(
Duncan Sands9e9d5b22011-01-25 15:14:15 +0000281 %l = zext i8 %x to i32
282 %r = zext i8 %y to i32
283 %s = add i32 %l, %r
284 %c = icmp eq i32 %s, 0
285 ret i1 %c
286; CHECK: ret i1 %c
287}
288
Duncan Sandsd114ab32011-02-13 17:15:40 +0000289define i1 @add4(i32 %x, i32 %y) {
Stephen Linc1c7a132013-07-14 01:42:54 +0000290; CHECK-LABEL: @add4(
Duncan Sandsd114ab32011-02-13 17:15:40 +0000291 %z = add nsw i32 %y, 1
292 %s1 = add nsw i32 %x, %y
293 %s2 = add nsw i32 %x, %z
294 %c = icmp slt i32 %s1, %s2
295 ret i1 %c
296; CHECK: ret i1 true
297}
298
299define i1 @add5(i32 %x, i32 %y) {
Stephen Linc1c7a132013-07-14 01:42:54 +0000300; CHECK-LABEL: @add5(
Duncan Sandsd114ab32011-02-13 17:15:40 +0000301 %z = add nuw i32 %y, 1
302 %s1 = add nuw i32 %x, %z
303 %s2 = add nuw i32 %x, %y
304 %c = icmp ugt i32 %s1, %s2
305 ret i1 %c
306; CHECK: ret i1 true
307}
308
Duncan Sandsc41076c2012-11-16 19:41:26 +0000309define i1 @add6(i64 %A, i64 %B) {
Stephen Linc1c7a132013-07-14 01:42:54 +0000310; CHECK-LABEL: @add6(
Duncan Sandsc41076c2012-11-16 19:41:26 +0000311 %s1 = add i64 %A, %B
312 %s2 = add i64 %B, %A
313 %cmp = icmp eq i64 %s1, %s2
314 ret i1 %cmp
315; CHECK: ret i1 true
316}
317
Duncan Sandsd3951082011-01-25 09:38:29 +0000318define i1 @addpowtwo(i32 %x, i32 %y) {
Stephen Linc1c7a132013-07-14 01:42:54 +0000319; CHECK-LABEL: @addpowtwo(
Duncan Sandsd3951082011-01-25 09:38:29 +0000320 %l = lshr i32 %x, 1
321 %r = shl i32 1, %y
322 %s = add i32 %l, %r
323 %c = icmp eq i32 %s, 0
324 ret i1 %c
325; CHECK: ret i1 false
326}
327
328define i1 @or(i32 %x) {
Stephen Linc1c7a132013-07-14 01:42:54 +0000329; CHECK-LABEL: @or(
Duncan Sandsd3951082011-01-25 09:38:29 +0000330 %o = or i32 %x, 1
331 %c = icmp eq i32 %o, 0
332 ret i1 %c
333; CHECK: ret i1 false
334}
Duncan Sands2e9e4f12011-01-29 13:27:00 +0000335
336define i1 @shl(i32 %x) {
Stephen Linc1c7a132013-07-14 01:42:54 +0000337; CHECK-LABEL: @shl(
Duncan Sands2e9e4f12011-01-29 13:27:00 +0000338 %s = shl i32 1, %x
339 %c = icmp eq i32 %s, 0
340 ret i1 %c
341; CHECK: ret i1 false
342}
343
Nick Lewycky3cec6f52011-03-04 07:00:57 +0000344define i1 @lshr1(i32 %x) {
Stephen Linc1c7a132013-07-14 01:42:54 +0000345; CHECK-LABEL: @lshr1(
Duncan Sands2e9e4f12011-01-29 13:27:00 +0000346 %s = lshr i32 -1, %x
347 %c = icmp eq i32 %s, 0
348 ret i1 %c
349; CHECK: ret i1 false
350}
351
Nick Lewycky3cec6f52011-03-04 07:00:57 +0000352define i1 @lshr2(i32 %x) {
Stephen Linc1c7a132013-07-14 01:42:54 +0000353; CHECK-LABEL: @lshr2(
Nick Lewycky3cec6f52011-03-04 07:00:57 +0000354 %s = lshr i32 %x, 30
355 %c = icmp ugt i32 %s, 8
356 ret i1 %c
357; CHECK: ret i1 false
358}
359
David Majnemera80fed72013-07-09 22:01:22 +0000360define i1 @lshr3(i32 %x) {
Stephen Linc1c7a132013-07-14 01:42:54 +0000361; CHECK-LABEL: @lshr3(
David Majnemera80fed72013-07-09 22:01:22 +0000362 %s = lshr i32 %x, %x
363 %c = icmp eq i32 %s, 0
364 ret i1 %c
365; CHECK: ret i1 true
366}
367
Nick Lewycky3cec6f52011-03-04 07:00:57 +0000368define i1 @ashr1(i32 %x) {
Stephen Linc1c7a132013-07-14 01:42:54 +0000369; CHECK-LABEL: @ashr1(
Duncan Sands2e9e4f12011-01-29 13:27:00 +0000370 %s = ashr i32 -1, %x
371 %c = icmp eq i32 %s, 0
372 ret i1 %c
373; CHECK: ret i1 false
374}
Duncan Sands06504022011-02-03 09:37:39 +0000375
Nick Lewycky3cec6f52011-03-04 07:00:57 +0000376define i1 @ashr2(i32 %x) {
Stephen Linc1c7a132013-07-14 01:42:54 +0000377; CHECK-LABEL: @ashr2(
Nick Lewycky3cec6f52011-03-04 07:00:57 +0000378 %s = ashr i32 %x, 30
379 %c = icmp slt i32 %s, -5
380 ret i1 %c
381; CHECK: ret i1 false
382}
383
David Majnemera80fed72013-07-09 22:01:22 +0000384define i1 @ashr3(i32 %x) {
Stephen Linc1c7a132013-07-14 01:42:54 +0000385; CHECK-LABEL: @ashr3(
David Majnemera80fed72013-07-09 22:01:22 +0000386 %s = ashr i32 %x, %x
387 %c = icmp eq i32 %s, 0
388 ret i1 %c
389; CHECK: ret i1 true
390}
391
Duncan Sands06504022011-02-03 09:37:39 +0000392define i1 @select1(i1 %cond) {
Stephen Linc1c7a132013-07-14 01:42:54 +0000393; CHECK-LABEL: @select1(
Duncan Sands06504022011-02-03 09:37:39 +0000394 %s = select i1 %cond, i32 1, i32 0
395 %c = icmp eq i32 %s, 1
396 ret i1 %c
397; CHECK: ret i1 %cond
398}
399
400define i1 @select2(i1 %cond) {
Stephen Linc1c7a132013-07-14 01:42:54 +0000401; CHECK-LABEL: @select2(
Duncan Sands06504022011-02-03 09:37:39 +0000402 %x = zext i1 %cond to i32
403 %s = select i1 %cond, i32 %x, i32 0
404 %c = icmp ne i32 %s, 0
405 ret i1 %c
406; CHECK: ret i1 %cond
407}
408
409define i1 @select3(i1 %cond) {
Stephen Linc1c7a132013-07-14 01:42:54 +0000410; CHECK-LABEL: @select3(
Duncan Sands06504022011-02-03 09:37:39 +0000411 %x = zext i1 %cond to i32
412 %s = select i1 %cond, i32 1, i32 %x
413 %c = icmp ne i32 %s, 0
414 ret i1 %c
415; CHECK: ret i1 %cond
416}
417
418define i1 @select4(i1 %cond) {
Stephen Linc1c7a132013-07-14 01:42:54 +0000419; CHECK-LABEL: @select4(
Duncan Sands06504022011-02-03 09:37:39 +0000420 %invert = xor i1 %cond, 1
421 %s = select i1 %invert, i32 0, i32 1
422 %c = icmp ne i32 %s, 0
423 ret i1 %c
424; CHECK: ret i1 %cond
425}
Nick Lewyckyc9d20062011-03-01 08:15:50 +0000426
Duncan Sands3d5692a2011-10-30 19:56:36 +0000427define i1 @select5(i32 %x) {
Stephen Linc1c7a132013-07-14 01:42:54 +0000428; CHECK-LABEL: @select5(
Duncan Sands3d5692a2011-10-30 19:56:36 +0000429 %c = icmp eq i32 %x, 0
430 %s = select i1 %c, i32 1, i32 %x
431 %c2 = icmp eq i32 %s, 0
432 ret i1 %c2
433; CHECK: ret i1 false
434}
435
436define i1 @select6(i32 %x) {
Stephen Linc1c7a132013-07-14 01:42:54 +0000437; CHECK-LABEL: @select6(
Duncan Sands3d5692a2011-10-30 19:56:36 +0000438 %c = icmp sgt i32 %x, 0
439 %s = select i1 %c, i32 %x, i32 4
440 %c2 = icmp eq i32 %s, 0
441 ret i1 %c2
442; CHECK: ret i1 %c2
443}
444
Nick Lewyckyc9d20062011-03-01 08:15:50 +0000445define i1 @urem1(i32 %X, i32 %Y) {
Stephen Linc1c7a132013-07-14 01:42:54 +0000446; CHECK-LABEL: @urem1(
Nick Lewyckyc9d20062011-03-01 08:15:50 +0000447 %A = urem i32 %X, %Y
448 %B = icmp ult i32 %A, %Y
449 ret i1 %B
450; CHECK: ret i1 true
451}
452
453define i1 @urem2(i32 %X, i32 %Y) {
Stephen Linc1c7a132013-07-14 01:42:54 +0000454; CHECK-LABEL: @urem2(
Nick Lewyckyc9d20062011-03-01 08:15:50 +0000455 %A = urem i32 %X, %Y
456 %B = icmp eq i32 %A, %Y
457 ret i1 %B
Benjamin Kramer1885d212011-03-09 22:07:31 +0000458; CHECK: ret i1 false
Nick Lewyckyc9d20062011-03-01 08:15:50 +0000459}
Nick Lewycky3cec6f52011-03-04 07:00:57 +0000460
461define i1 @urem3(i32 %X) {
Stephen Linc1c7a132013-07-14 01:42:54 +0000462; CHECK-LABEL: @urem3(
Nick Lewycky3cec6f52011-03-04 07:00:57 +0000463 %A = urem i32 %X, 10
464 %B = icmp ult i32 %A, 15
465 ret i1 %B
466; CHECK: ret i1 true
467}
468
469define i1 @urem4(i32 %X) {
Stephen Linc1c7a132013-07-14 01:42:54 +0000470; CHECK-LABEL: @urem4(
Nick Lewycky3cec6f52011-03-04 07:00:57 +0000471 %A = urem i32 %X, 15
472 %B = icmp ult i32 %A, 10
473 ret i1 %B
474; CHECK: ret i1 %B
475}
476
Nick Lewycky8e3a79d2011-03-04 10:06:52 +0000477define i1 @urem5(i16 %X, i32 %Y) {
Stephen Linc1c7a132013-07-14 01:42:54 +0000478; CHECK-LABEL: @urem5(
Nick Lewycky8e3a79d2011-03-04 10:06:52 +0000479 %A = zext i16 %X to i32
480 %B = urem i32 %A, %Y
481 %C = icmp slt i32 %B, %Y
482 ret i1 %C
Nick Lewycky35aeea92013-07-12 23:42:57 +0000483; CHECK-NOT: ret i1 true
Nick Lewycky8e3a79d2011-03-04 10:06:52 +0000484}
485
Nick Lewycky980104d2011-03-09 06:26:03 +0000486define i1 @urem6(i32 %X, i32 %Y) {
Stephen Linc1c7a132013-07-14 01:42:54 +0000487; CHECK-LABEL: @urem6(
Nick Lewycky980104d2011-03-09 06:26:03 +0000488 %A = urem i32 %X, %Y
489 %B = icmp ugt i32 %Y, %A
490 ret i1 %B
491; CHECK: ret i1 true
492}
493
Nick Lewycky35aeea92013-07-12 23:42:57 +0000494define i1 @urem7(i32 %X) {
Stephen Linc1c7a132013-07-14 01:42:54 +0000495; CHECK-LABEL: @urem7(
Nick Lewycky35aeea92013-07-12 23:42:57 +0000496 %A = urem i32 1, %X
497 %B = icmp sgt i32 %A, %X
498 ret i1 %B
499; CHECK-NOT: ret i1 false
500}
501
Nick Lewycky3cec6f52011-03-04 07:00:57 +0000502define i1 @srem1(i32 %X) {
Stephen Linc1c7a132013-07-14 01:42:54 +0000503; CHECK-LABEL: @srem1(
Nick Lewycky3cec6f52011-03-04 07:00:57 +0000504 %A = srem i32 %X, -5
505 %B = icmp sgt i32 %A, 5
506 ret i1 %B
507; CHECK: ret i1 false
508}
509
Nick Lewyckycc799732011-03-11 09:00:19 +0000510; PR9343 #15
Stephen Linc1c7a132013-07-14 01:42:54 +0000511; CHECK-LABEL: @srem2(
Nick Lewyckycc799732011-03-11 09:00:19 +0000512; CHECK: ret i1 false
513define i1 @srem2(i16 %X, i32 %Y) {
514 %A = zext i16 %X to i32
515 %B = add nsw i32 %A, 1
516 %C = srem i32 %B, %Y
517 %D = icmp slt i32 %C, 0
518 ret i1 %D
519}
Benjamin Kramer5acc7512011-03-12 17:18:11 +0000520
Stephen Linc1c7a132013-07-14 01:42:54 +0000521; CHECK-LABEL: @srem3(
Benjamin Kramer5acc7512011-03-12 17:18:11 +0000522; CHECK-NEXT: ret i1 false
523define i1 @srem3(i16 %X, i32 %Y) {
524 %A = zext i16 %X to i32
525 %B = or i32 2147483648, %A
526 %C = sub nsw i32 1, %B
527 %D = srem i32 %C, %Y
528 %E = icmp slt i32 %D, 0
529 ret i1 %E
530}
531
Nick Lewycky3cec6f52011-03-04 07:00:57 +0000532define i1 @udiv1(i32 %X) {
Stephen Linc1c7a132013-07-14 01:42:54 +0000533; CHECK-LABEL: @udiv1(
Nick Lewycky3cec6f52011-03-04 07:00:57 +0000534 %A = udiv i32 %X, 1000000
535 %B = icmp ult i32 %A, 5000
536 ret i1 %B
537; CHECK: ret i1 true
538}
539
Nick Lewycky9719a712011-03-05 05:19:11 +0000540define i1 @udiv2(i32 %X, i32 %Y, i32 %Z) {
Stephen Linc1c7a132013-07-14 01:42:54 +0000541; CHECK-LABEL: @udiv2(
Nick Lewycky9719a712011-03-05 05:19:11 +0000542 %A = udiv exact i32 10, %Z
543 %B = udiv exact i32 20, %Z
544 %C = icmp ult i32 %A, %B
545 ret i1 %C
546; CHECK: ret i1 true
547}
548
Duncan Sands92af0a82011-10-28 18:17:44 +0000549define i1 @udiv3(i32 %X, i32 %Y) {
Stephen Linc1c7a132013-07-14 01:42:54 +0000550; CHECK-LABEL: @udiv3(
Duncan Sands92af0a82011-10-28 18:17:44 +0000551 %A = udiv i32 %X, %Y
552 %C = icmp ugt i32 %A, %X
553 ret i1 %C
554; CHECK: ret i1 false
555}
556
557define i1 @udiv4(i32 %X, i32 %Y) {
Stephen Linc1c7a132013-07-14 01:42:54 +0000558; CHECK-LABEL: @udiv4(
Duncan Sands92af0a82011-10-28 18:17:44 +0000559 %A = udiv i32 %X, %Y
560 %C = icmp ule i32 %A, %X
561 ret i1 %C
562; CHECK: ret i1 true
563}
564
565define i1 @udiv5(i32 %X) {
Stephen Linc1c7a132013-07-14 01:42:54 +0000566; CHECK-LABEL: @udiv5(
Duncan Sands92af0a82011-10-28 18:17:44 +0000567 %A = udiv i32 123, %X
568 %C = icmp ugt i32 %A, 124
569 ret i1 %C
570; CHECK: ret i1 false
571}
572
Eli Friedman0bae8b22011-11-08 21:08:02 +0000573; PR11340
574define i1 @udiv6(i32 %X) nounwind {
Stephen Linc1c7a132013-07-14 01:42:54 +0000575; CHECK-LABEL: @udiv6(
Eli Friedman0bae8b22011-11-08 21:08:02 +0000576 %A = udiv i32 1, %X
577 %C = icmp eq i32 %A, 0
578 ret i1 %C
579; CHECK: ret i1 %C
580}
581
582
Nick Lewycky3cec6f52011-03-04 07:00:57 +0000583define i1 @sdiv1(i32 %X) {
Stephen Linc1c7a132013-07-14 01:42:54 +0000584; CHECK-LABEL: @sdiv1(
Nick Lewycky3cec6f52011-03-04 07:00:57 +0000585 %A = sdiv i32 %X, 1000000
586 %B = icmp slt i32 %A, 3000
587 ret i1 %B
588; CHECK: ret i1 true
589}
590
591define i1 @or1(i32 %X) {
Stephen Linc1c7a132013-07-14 01:42:54 +0000592; CHECK-LABEL: @or1(
Nick Lewycky3cec6f52011-03-04 07:00:57 +0000593 %A = or i32 %X, 62
594 %B = icmp ult i32 %A, 50
595 ret i1 %B
596; CHECK: ret i1 false
597}
598
599define i1 @and1(i32 %X) {
Stephen Linc1c7a132013-07-14 01:42:54 +0000600; CHECK-LABEL: @and1(
Nick Lewycky3cec6f52011-03-04 07:00:57 +0000601 %A = and i32 %X, 62
602 %B = icmp ugt i32 %A, 70
603 ret i1 %B
604; CHECK: ret i1 false
605}
Duncan Sands7cb61e52011-10-27 19:16:21 +0000606
607define i1 @mul1(i32 %X) {
Stephen Linc1c7a132013-07-14 01:42:54 +0000608; CHECK-LABEL: @mul1(
Duncan Sands7cb61e52011-10-27 19:16:21 +0000609; Square of a non-zero number is non-zero if there is no overflow.
610 %Y = or i32 %X, 1
611 %M = mul nuw i32 %Y, %Y
612 %C = icmp eq i32 %M, 0
613 ret i1 %C
614; CHECK: ret i1 false
615}
616
617define i1 @mul2(i32 %X) {
Stephen Linc1c7a132013-07-14 01:42:54 +0000618; CHECK-LABEL: @mul2(
Duncan Sands7cb61e52011-10-27 19:16:21 +0000619; Square of a non-zero number is positive if there is no signed overflow.
620 %Y = or i32 %X, 1
621 %M = mul nsw i32 %Y, %Y
622 %C = icmp sgt i32 %M, 0
623 ret i1 %C
624; CHECK: ret i1 true
625}
626
627define i1 @mul3(i32 %X, i32 %Y) {
Stephen Linc1c7a132013-07-14 01:42:54 +0000628; CHECK-LABEL: @mul3(
Duncan Sands7cb61e52011-10-27 19:16:21 +0000629; Product of non-negative numbers is non-negative if there is no signed overflow.
630 %XX = mul nsw i32 %X, %X
631 %YY = mul nsw i32 %Y, %Y
632 %M = mul nsw i32 %XX, %YY
633 %C = icmp sge i32 %M, 0
634 ret i1 %C
635; CHECK: ret i1 true
636}
Duncan Sandsbf48ac62012-02-10 14:26:42 +0000637
638define <2 x i1> @vectorselect1(<2 x i1> %cond) {
Stephen Linc1c7a132013-07-14 01:42:54 +0000639; CHECK-LABEL: @vectorselect1(
Duncan Sandsbf48ac62012-02-10 14:26:42 +0000640 %invert = xor <2 x i1> %cond, <i1 1, i1 1>
641 %s = select <2 x i1> %invert, <2 x i32> <i32 0, i32 0>, <2 x i32> <i32 1, i32 1>
642 %c = icmp ne <2 x i32> %s, <i32 0, i32 0>
643 ret <2 x i1> %c
644; CHECK: ret <2 x i1> %cond
645}
Duncan Sands26641d72012-02-10 14:31:24 +0000646
Chris Lattner445d8c62012-02-20 00:42:49 +0000647; PR11948
648define <2 x i1> @vectorselectcrash(i32 %arg1) {
Duncan Sands26641d72012-02-10 14:31:24 +0000649 %tobool40 = icmp ne i32 %arg1, 0
650 %cond43 = select i1 %tobool40, <2 x i16> <i16 -5, i16 66>, <2 x i16> <i16 46, i16 1>
651 %cmp45 = icmp ugt <2 x i16> %cond43, <i16 73, i16 21>
652 ret <2 x i1> %cmp45
653}
Chris Lattner445d8c62012-02-20 00:42:49 +0000654
655; PR12013
656define i1 @alloca_compare(i64 %idx) {
657 %sv = alloca { i32, i32, [124 x i32] }
658 %1 = getelementptr inbounds { i32, i32, [124 x i32] }* %sv, i32 0, i32 2, i64 %idx
659 %2 = icmp eq i32* %1, null
660 ret i1 %2
661 ; CHECK: alloca_compare
662 ; CHECK: ret i1 false
663}
Chris Lattner01990f02012-02-24 19:01:58 +0000664
665; PR12075
666define i1 @infinite_gep() {
667 ret i1 1
668
669unreachableblock:
670 %X = getelementptr i32 *%X, i32 1
671 %Y = icmp eq i32* %X, null
672 ret i1 %Y
673}
Dan Gohman995d40e2013-01-31 23:49:33 +0000674
675; It's not valid to fold a comparison of an argument with an alloca, even though
676; that's tempting. An argument can't *alias* an alloca, however the aliasing rule
677; relies on restrictions against guessing an object's address and dereferencing.
678; There are no restrictions against guessing an object's address and comparing.
679
680define i1 @alloca_argument_compare(i64* %arg) {
681 %alloc = alloca i64
682 %cmp = icmp eq i64* %arg, %alloc
683 ret i1 %cmp
684 ; CHECK: alloca_argument_compare
685 ; CHECK: ret i1 %cmp
686}
Dan Gohmanb3e2d3a2013-02-01 00:11:13 +0000687
688; As above, but with the operands reversed.
689
690define i1 @alloca_argument_compare_swapped(i64* %arg) {
691 %alloc = alloca i64
692 %cmp = icmp eq i64* %alloc, %arg
693 ret i1 %cmp
694 ; CHECK: alloca_argument_compare_swapped
695 ; CHECK: ret i1 %cmp
696}
697
698; Don't assume that a noalias argument isn't equal to a global variable's
699; address. This is an example where AliasAnalysis' NoAlias concept is
700; different from actual pointer inequality.
701
702@y = external global i32
703define zeroext i1 @external_compare(i32* noalias %x) {
704 %cmp = icmp eq i32* %x, @y
705 ret i1 %cmp
706 ; CHECK: external_compare
707 ; CHECK: ret i1 %cmp
708}
Manman Ren12171122013-03-18 21:23:25 +0000709
710define i1 @alloca_gep(i64 %a, i64 %b) {
Stephen Linc1c7a132013-07-14 01:42:54 +0000711; CHECK-LABEL: @alloca_gep(
Manman Ren12171122013-03-18 21:23:25 +0000712; We can prove this GEP is non-null because it is inbounds and the pointer
713; is non-null.
714 %strs = alloca [1000 x [1001 x i8]], align 16
715 %x = getelementptr inbounds [1000 x [1001 x i8]]* %strs, i64 0, i64 %a, i64 %b
716 %cmp = icmp eq i8* %x, null
717 ret i1 %cmp
718; CHECK-NEXT: ret i1 false
719}