blob: 56e1e6a29c49903d7d5099a6c55d3128e843d966 [file] [log] [blame]
Sanjay Patel69632442016-03-25 20:12:25 +00001; NOTE: Assertions have been autogenerated by update_test_checks.py
Philip Reames13f023c2015-09-28 17:14:24 +00002; RUN: opt -S %s -instsimplify | FileCheck %s
3
4; A ==> A -> true
5define i1 @test(i32 %length.i, i32 %i) {
Sanjay Patel69632442016-03-25 20:12:25 +00006; CHECK-LABEL: @test(
7; CHECK: ret i1 true
8;
Philip Reames13f023c2015-09-28 17:14:24 +00009 %var29 = icmp slt i32 %i, %length.i
10 %res = icmp uge i1 %var29, %var29
11 ret i1 %res
12}
13
14; i +_{nsw} C_{>0} <s L ==> i <s L -> true
15define i1 @test2(i32 %length.i, i32 %i) {
Sanjay Patel69632442016-03-25 20:12:25 +000016; CHECK-LABEL: @test2(
17; CHECK: ret i1 true
18;
Philip Reames13f023c2015-09-28 17:14:24 +000019 %iplus1 = add nsw i32 %i, 1
20 %var29 = icmp slt i32 %i, %length.i
21 %var30 = icmp slt i32 %iplus1, %length.i
22 %res = icmp ule i1 %var30, %var29
23 ret i1 %res
24}
25
26; i + C_{>0} <s L ==> i <s L -> unknown without the nsw
27define i1 @test2_neg(i32 %length.i, i32 %i) {
Sanjay Patel69632442016-03-25 20:12:25 +000028; CHECK-LABEL: @test2_neg(
29; CHECK: [[IPLUS1:%.*]] = add i32 %i, 1
30; CHECK-NEXT: [[VAR29:%.*]] = icmp slt i32 %i, %length.i
31; CHECK-NEXT: [[VAR30:%.*]] = icmp slt i32 [[IPLUS1]], %length.i
32; CHECK-NEXT: [[RES:%.*]] = icmp ule i1 [[VAR30]], [[VAR29]]
33; CHECK-NEXT: ret i1 [[RES]]
34;
Philip Reames13f023c2015-09-28 17:14:24 +000035 %iplus1 = add i32 %i, 1
36 %var29 = icmp slt i32 %i, %length.i
37 %var30 = icmp slt i32 %iplus1, %length.i
38 %res = icmp ule i1 %var30, %var29
39 ret i1 %res
40}
41
42; sle is not implication
43define i1 @test2_neg2(i32 %length.i, i32 %i) {
Sanjay Patel69632442016-03-25 20:12:25 +000044; CHECK-LABEL: @test2_neg2(
45; CHECK: [[IPLUS1:%.*]] = add i32 %i, 1
46; CHECK-NEXT: [[VAR29:%.*]] = icmp slt i32 %i, %length.i
47; CHECK-NEXT: [[VAR30:%.*]] = icmp slt i32 [[IPLUS1]], %length.i
48; CHECK-NEXT: [[RES:%.*]] = icmp sle i1 [[VAR30]], [[VAR29]]
49; CHECK-NEXT: ret i1 [[RES]]
50;
Philip Reames13f023c2015-09-28 17:14:24 +000051 %iplus1 = add i32 %i, 1
52 %var29 = icmp slt i32 %i, %length.i
53 %var30 = icmp slt i32 %iplus1, %length.i
54 %res = icmp sle i1 %var30, %var29
55 ret i1 %res
56}
57
58; The binary operator has to be an add
59define i1 @test2_neg3(i32 %length.i, i32 %i) {
Sanjay Patel69632442016-03-25 20:12:25 +000060; CHECK-LABEL: @test2_neg3(
61; CHECK: [[IPLUS1:%.*]] = sub nsw i32 %i, 1
62; CHECK-NEXT: [[VAR29:%.*]] = icmp slt i32 %i, %length.i
63; CHECK-NEXT: [[VAR30:%.*]] = icmp slt i32 [[IPLUS1]], %length.i
64; CHECK-NEXT: [[RES:%.*]] = icmp ule i1 [[VAR30]], [[VAR29]]
65; CHECK-NEXT: ret i1 [[RES]]
66;
Philip Reames13f023c2015-09-28 17:14:24 +000067 %iplus1 = sub nsw i32 %i, 1
68 %var29 = icmp slt i32 %i, %length.i
69 %var30 = icmp slt i32 %iplus1, %length.i
70 %res = icmp ule i1 %var30, %var29
71 ret i1 %res
72}
73
74; i +_{nsw} C_{>0} <s L ==> i <s L -> true
75; With an inverted conditional (ule B A rather than canonical ugt A B
76define i1 @test3(i32 %length.i, i32 %i) {
Sanjay Patel69632442016-03-25 20:12:25 +000077; CHECK-LABEL: @test3(
78; CHECK: ret i1 true
79;
Philip Reames13f023c2015-09-28 17:14:24 +000080 %iplus1 = add nsw i32 %i, 1
81 %var29 = icmp slt i32 %i, %length.i
82 %var30 = icmp slt i32 %iplus1, %length.i
83 %res = icmp uge i1 %var29, %var30
84 ret i1 %res
85}
86
Sanjoy Dasc01b4d22015-11-06 19:01:03 +000087; i +_{nuw} C <u L ==> i <u L
Philip Reames13f023c2015-09-28 17:14:24 +000088define i1 @test4(i32 %length.i, i32 %i) {
Sanjay Patel69632442016-03-25 20:12:25 +000089; CHECK-LABEL: @test4(
90; CHECK: ret i1 true
91;
Philip Reames13f023c2015-09-28 17:14:24 +000092 %iplus1 = add nuw i32 %i, 1
93 %var29 = icmp ult i32 %i, %length.i
94 %var30 = icmp ult i32 %iplus1, %length.i
95 %res = icmp ule i1 %var30, %var29
96 ret i1 %res
97}
Philip Reames600a9152015-10-06 19:00:02 +000098
99; A ==> A for vectors
100define <4 x i1> @test5(<4 x i1> %vec) {
Sanjay Patel69632442016-03-25 20:12:25 +0000101; CHECK-LABEL: @test5(
102; CHECK: ret <4 x i1> <i1 true, i1 true, i1 true, i1 true>
103;
Philip Reames600a9152015-10-06 19:00:02 +0000104 %res = icmp ule <4 x i1> %vec, %vec
105 ret <4 x i1> %res
106}
107
108; Don't crash on vector inputs - pr25040
109define <4 x i1> @test6(<4 x i1> %a, <4 x i1> %b) {
Sanjay Patel69632442016-03-25 20:12:25 +0000110; CHECK-LABEL: @test6(
111; CHECK: [[RES:%.*]] = icmp ule <4 x i1> %a, %b
112; CHECK-NEXT: ret <4 x i1> [[RES]]
113;
Philip Reames600a9152015-10-06 19:00:02 +0000114 %res = icmp ule <4 x i1> %a, %b
115 ret <4 x i1> %res
116}
Philip Reamesdbbd7792015-10-29 03:19:10 +0000117
Sanjoy Das9349dcc2015-11-06 19:00:57 +0000118; i +_{nsw} 1 <s L ==> i < L +_{nsw} 1
119define i1 @test7(i32 %length.i, i32 %i) {
120; CHECK-LABEL: @test7(
Sanjay Patel69632442016-03-25 20:12:25 +0000121; CHECK: ret i1 true
122;
Sanjoy Das9349dcc2015-11-06 19:00:57 +0000123 %iplus1 = add nsw i32 %i, 1
124 %len.plus.one = add nsw i32 %length.i, 1
125 %var29 = icmp slt i32 %i, %len.plus.one
126 %var30 = icmp slt i32 %iplus1, %length.i
127 %res = icmp ule i1 %var30, %var29
128 ret i1 %res
129}
130
Chad Rosiere30fed72016-04-18 19:11:45 +0000131; i +_{nuw} 1 <u L ==> i < L +_{nuw} 1
Sanjoy Das9349dcc2015-11-06 19:00:57 +0000132define i1 @test8(i32 %length.i, i32 %i) {
133; CHECK-LABEL: @test8(
Sanjay Patel69632442016-03-25 20:12:25 +0000134; CHECK: ret i1 true
135;
Sanjoy Das9349dcc2015-11-06 19:00:57 +0000136 %iplus1 = add nuw i32 %i, 1
137 %len.plus.one = add nuw i32 %length.i, 1
138 %var29 = icmp ult i32 %i, %len.plus.one
139 %var30 = icmp ult i32 %iplus1, %length.i
140 %res = icmp ule i1 %var30, %var29
141 ret i1 %res
142}
143
Chad Rosiere30fed72016-04-18 19:11:45 +0000144; i +_{nuw} C <u L ==> i < L, even if C is negative
Sanjoy Dasc01b4d22015-11-06 19:01:03 +0000145define i1 @test9(i32 %length.i, i32 %i) {
146; CHECK-LABEL: @test9(
Sanjay Patel69632442016-03-25 20:12:25 +0000147; CHECK: ret i1 true
148;
Sanjoy Dasc01b4d22015-11-06 19:01:03 +0000149 %iplus1 = add nuw i32 %i, -100
150 %var29 = icmp ult i32 %i, %length.i
151 %var30 = icmp ult i32 %iplus1, %length.i
152 %res = icmp ule i1 %var30, %var29
153 ret i1 %res
154}
155
Sanjoy Das92568102015-11-10 23:56:20 +0000156define i1 @test10(i32 %length.i, i32 %x.full) {
157; CHECK-LABEL: @test10(
Sanjay Patel69632442016-03-25 20:12:25 +0000158; CHECK: ret i1 true
159;
Sanjoy Das92568102015-11-10 23:56:20 +0000160 %x = and i32 %x.full, 4294901760 ;; 4294901760 == 0xffff0000
161 %large = or i32 %x, 100
162 %small = or i32 %x, 90
163 %known = icmp ult i32 %large, %length.i
164 %to.prove = icmp ult i32 %small, %length.i
165 %res = icmp ule i1 %known, %to.prove
166 ret i1 %res
167}
168
169define i1 @test11(i32 %length.i, i32 %x) {
170; CHECK-LABEL: @test11(
Sanjay Patel69632442016-03-25 20:12:25 +0000171; CHECK: [[LARGE:%.*]] = or i32 %x, 100
172; CHECK-NEXT: [[SMALL:%.*]] = or i32 %x, 90
173; CHECK-NEXT: [[KNOWN:%.*]] = icmp ult i32 [[LARGE]], %length.i
174; CHECK-NEXT: [[TO_PROVE:%.*]] = icmp ult i32 [[SMALL]], %length.i
175; CHECK-NEXT: [[RES:%.*]] = icmp ule i1 [[KNOWN]], [[TO_PROVE]]
176; CHECK-NEXT: ret i1 [[RES]]
177;
Sanjoy Das92568102015-11-10 23:56:20 +0000178 %large = or i32 %x, 100
179 %small = or i32 %x, 90
180 %known = icmp ult i32 %large, %length.i
181 %to.prove = icmp ult i32 %small, %length.i
182 %res = icmp ule i1 %known, %to.prove
183 ret i1 %res
184}
185
186define i1 @test12(i32 %length.i, i32 %x.full) {
187; CHECK-LABEL: @test12(
Sanjay Patel69632442016-03-25 20:12:25 +0000188; CHECK: [[X:%.*]] = and i32 [[X:%.*]].full, -65536
189; CHECK-NEXT: [[LARGE:%.*]] = or i32 [[X]], 65536
190; CHECK-NEXT: [[SMALL:%.*]] = or i32 [[X]], 90
191; CHECK-NEXT: [[KNOWN:%.*]] = icmp ult i32 [[LARGE]], %length.i
192; CHECK-NEXT: [[TO_PROVE:%.*]] = icmp ult i32 [[SMALL]], %length.i
193; CHECK-NEXT: [[RES:%.*]] = icmp ule i1 [[KNOWN]], [[TO_PROVE]]
194; CHECK-NEXT: ret i1 [[RES]]
195;
Sanjoy Das92568102015-11-10 23:56:20 +0000196 %x = and i32 %x.full, 4294901760 ;; 4294901760 == 0xffff0000
197 %large = or i32 %x, 65536 ;; 65536 == 0x00010000
198 %small = or i32 %x, 90
199 %known = icmp ult i32 %large, %length.i
200 %to.prove = icmp ult i32 %small, %length.i
201 %res = icmp ule i1 %known, %to.prove
202 ret i1 %res
203}
204
205define i1 @test13(i32 %length.i, i32 %x) {
206; CHECK-LABEL: @test13(
Sanjay Patel69632442016-03-25 20:12:25 +0000207; CHECK: ret i1 true
208;
Sanjoy Das92568102015-11-10 23:56:20 +0000209 %large = add nuw i32 %x, 100
210 %small = add nuw i32 %x, 90
211 %known = icmp ult i32 %large, %length.i
212 %to.prove = icmp ult i32 %small, %length.i
213 %res = icmp ule i1 %known, %to.prove
214 ret i1 %res
215}
216
217define i1 @test14(i32 %length.i, i32 %x.full) {
218; CHECK-LABEL: @test14(
Sanjay Patel69632442016-03-25 20:12:25 +0000219; CHECK: ret i1 true
220;
Sanjoy Das92568102015-11-10 23:56:20 +0000221 %x = and i32 %x.full, 4294905615 ;; 4294905615 == 0xffff0f0f
222 %large = or i32 %x, 8224 ;; == 0x2020
223 %small = or i32 %x, 4112 ;; == 0x1010
224 %known = icmp ult i32 %large, %length.i
225 %to.prove = icmp ult i32 %small, %length.i
226 %res = icmp ule i1 %known, %to.prove
227 ret i1 %res
228}
229
230define i1 @test15(i32 %length.i, i32 %x) {
231; CHECK-LABEL: @test15(
Sanjay Patel69632442016-03-25 20:12:25 +0000232; CHECK: [[LARGE:%.*]] = add nuw i32 %x, 100
233; CHECK-NEXT: [[SMALL:%.*]] = add nuw i32 %x, 110
234; CHECK-NEXT: [[KNOWN:%.*]] = icmp ult i32 [[LARGE]], %length.i
235; CHECK-NEXT: [[TO_PROVE:%.*]] = icmp ult i32 [[SMALL]], %length.i
236; CHECK-NEXT: [[RES:%.*]] = icmp ule i1 [[KNOWN]], [[TO_PROVE]]
237; CHECK-NEXT: ret i1 [[RES]]
238;
Sanjoy Das92568102015-11-10 23:56:20 +0000239 %large = add nuw i32 %x, 100
240 %small = add nuw i32 %x, 110
241 %known = icmp ult i32 %large, %length.i
242 %to.prove = icmp ult i32 %small, %length.i
243 %res = icmp ule i1 %known, %to.prove
244 ret i1 %res
245}
246
Philip Reamesdbbd7792015-10-29 03:19:10 +0000247; X >=(s) Y == X ==> Y (i1 1 becomes -1 for reasoning)
248define i1 @test_sge(i32 %length.i, i32 %i) {
Sanjay Patel69632442016-03-25 20:12:25 +0000249; CHECK-LABEL: @test_sge(
250; CHECK: ret i1 true
251;
Philip Reamesdbbd7792015-10-29 03:19:10 +0000252 %iplus1 = add nsw nuw i32 %i, 1
253 %var29 = icmp ult i32 %i, %length.i
254 %var30 = icmp ult i32 %iplus1, %length.i
255 %res = icmp sge i1 %var30, %var29
256 ret i1 %res
257}