llvm.org GIT mirror llvm / f982483
[InstSimplify] add tests to show missing vector icmp folds git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@279534 91177308-0d34-0410-b5e6-96231b3b80d8 Sanjay Patel 3 years ago
1 changed file(s) with 238 addition(s) and 0 deletion(s). Raw diff Collapse all Expand all
1010 ret i1 %cmp
1111 }
1212
13 define <2 x i1> @tautological_ule_vec(<2 x i8> %x) {
14 ; CHECK-LABEL: @tautological_ule_vec(
15 ; CHECK-NEXT: [[CMP:%.*]] = icmp ule <2 x i8> %x,
16 ; CHECK-NEXT: ret <2 x i1> [[CMP]]
17 ;
18 %cmp = icmp ule <2 x i8> %x,
19 ret <2 x i1> %cmp
20 }
21
1322 define i1 @tautological_ugt(i8 %x) {
1423 ; CHECK-LABEL: @tautological_ugt(
1524 ; CHECK-NEXT: ret i1 false
1625 ;
1726 %cmp = icmp ugt i8 %x, 255
1827 ret i1 %cmp
28 }
29
30 define <2 x i1> @tautological_ugt_vec(<2 x i8> %x) {
31 ; CHECK-LABEL: @tautological_ugt_vec(
32 ; CHECK-NEXT: [[CMP:%.*]] = icmp ugt <2 x i8> %x,
33 ; CHECK-NEXT: ret <2 x i1> [[CMP]]
34 ;
35 %cmp = icmp ugt <2 x i8> %x,
36 ret <2 x i1> %cmp
1937 }
2038
2139 ; 'urem x, C2' produces [0, C2)
2846 ret i1 %B
2947 }
3048
49 define <2 x i1> @urem3_vec(<2 x i32> %X) {
50 ; CHECK-LABEL: @urem3_vec(
51 ; CHECK-NEXT: [[A:%.*]] = urem <2 x i32> %X,
52 ; CHECK-NEXT: [[B:%.*]] = icmp ult <2 x i32> [[A]],
53 ; CHECK-NEXT: ret <2 x i1> [[B]]
54 ;
55 %A = urem <2 x i32> %X,
56 %B = icmp ult <2 x i32> %A,
57 ret <2 x i1> %B
58 }
59
3160 ;'srem x, C2' produces (-|C2|, |C2|)
3261 define i1 @srem1(i32 %X) {
3362 ; CHECK-LABEL: @srem1(
3867 ret i1 %B
3968 }
4069
70 define <2 x i1> @srem1_vec(<2 x i32> %X) {
71 ; CHECK-LABEL: @srem1_vec(
72 ; CHECK-NEXT: [[A:%.*]] = srem <2 x i32> %X,
73 ; CHECK-NEXT: [[B:%.*]] = icmp sgt <2 x i32> [[A]],
74 ; CHECK-NEXT: ret <2 x i1> [[B]]
75 ;
76 %A = srem <2 x i32> %X,
77 %B = icmp sgt <2 x i32> %A,
78 ret <2 x i1> %B
79 }
80
4181 ;'udiv C2, x' produces [0, C2]
4282 define i1 @udiv5(i32 %X) {
4383 ; CHECK-LABEL: @udiv5(
4888 ret i1 %C
4989 }
5090
91 define <2 x i1> @udiv5_vec(<2 x i32> %X) {
92 ; CHECK-LABEL: @udiv5_vec(
93 ; CHECK-NEXT: [[A:%.*]] = udiv <2 x i32> , %X
94 ; CHECK-NEXT: [[C:%.*]] = icmp ugt <2 x i32> [[A]],
95 ; CHECK-NEXT: ret <2 x i1> [[C]]
96 ;
97 %A = udiv <2 x i32> , %X
98 %C = icmp ugt <2 x i32> %A,
99 ret <2 x i1> %C
100 }
101
51102 ; 'udiv x, C2' produces [0, UINT_MAX / C2]
52103 define i1 @udiv1(i32 %X) {
53104 ; CHECK-LABEL: @udiv1(
58109 ret i1 %B
59110 }
60111
112 define <2 x i1> @udiv1_vec(<2 x i32> %X) {
113 ; CHECK-LABEL: @udiv1_vec(
114 ; CHECK-NEXT: [[A:%.*]] = udiv <2 x i32> %X,
115 ; CHECK-NEXT: [[B:%.*]] = icmp ult <2 x i32> [[A]],
116 ; CHECK-NEXT: ret <2 x i1> [[B]]
117 ;
118 %A = udiv <2 x i32> %X,
119 %B = icmp ult <2 x i32> %A,
120 ret <2 x i1> %B
121 }
122
61123 ; 'sdiv C2, x' produces [-|C2|, |C2|]
62124 define i1 @compare_dividend(i32 %a) {
63125 ; CHECK-LABEL: @compare_dividend(
66128 %div = sdiv i32 2, %a
67129 %cmp = icmp eq i32 %div, 3
68130 ret i1 %cmp
131 }
132
133 define <2 x i1> @compare_dividend_vec(<2 x i32> %a) {
134 ; CHECK-LABEL: @compare_dividend_vec(
135 ; CHECK-NEXT: [[DIV:%.*]] = sdiv <2 x i32> , %a
136 ; CHECK-NEXT: [[CMP:%.*]] = icmp eq <2 x i32> [[DIV]],
137 ; CHECK-NEXT: ret <2 x i1> [[CMP]]
138 ;
139 %div = sdiv <2 x i32> , %a
140 %cmp = icmp eq <2 x i32> %div,
141 ret <2 x i1> %cmp
69142 }
70143
71144 ; 'sdiv x, C2' produces [INT_MIN / C2, INT_MAX / C2]
79152 ret i1 %B
80153 }
81154
155 define <2 x i1> @sdiv1_vec(<2 x i32> %X) {
156 ; CHECK-LABEL: @sdiv1_vec(
157 ; CHECK-NEXT: [[A:%.*]] = sdiv <2 x i32> %X,
158 ; CHECK-NEXT: [[B:%.*]] = icmp slt <2 x i32> [[A]],
159 ; CHECK-NEXT: ret <2 x i1> [[B]]
160 ;
161 %A = sdiv <2 x i32> %X,
162 %B = icmp slt <2 x i32> %A,
163 ret <2 x i1> %B
164 }
165
82166 ; 'shl nuw C2, x' produces [C2, C2 << CLZ(C2)]
83167 define i1 @shl5(i32 %X) {
84168 ; CHECK-LABEL: @shl5(
89173 ret i1 %cmp
90174 }
91175
176 define <2 x i1> @shl5_vec(<2 x i32> %X) {
177 ; CHECK-LABEL: @shl5_vec(
178 ; CHECK-NEXT: [[SUB:%.*]] = shl nuw <2 x i32> , %X
179 ; CHECK-NEXT: [[CMP:%.*]] = icmp ugt <2 x i32> [[SUB]],
180 ; CHECK-NEXT: ret <2 x i1> [[CMP]]
181 ;
182 %sub = shl nuw <2 x i32> , %X
183 %cmp = icmp ugt <2 x i32> %sub,
184 ret <2 x i1> %cmp
185 }
186
92187 ; 'shl nsw C2, x' produces [C2 << CLO(C2)-1, C2]
93188 define i1 @shl2(i32 %X) {
94189 ; CHECK-LABEL: @shl2(
99194 ret i1 %cmp
100195 }
101196
197 define <2 x i1> @shl2_vec(<2 x i32> %X) {
198 ; CHECK-LABEL: @shl2_vec(
199 ; CHECK-NEXT: [[SUB:%.*]] = shl nsw <2 x i32> , %X
200 ; CHECK-NEXT: [[CMP:%.*]] = icmp eq <2 x i32> [[SUB]],
201 ; CHECK-NEXT: ret <2 x i1> [[CMP]]
202 ;
203 %sub = shl nsw <2 x i32> , %X
204 %cmp = icmp eq <2 x i32> %sub,
205 ret <2 x i1> %cmp
206 }
207
102208 ; 'shl nsw C2, x' produces [C2 << CLO(C2)-1, C2]
103209 define i1 @shl4(i32 %X) {
104210 ; CHECK-LABEL: @shl4(
109215 ret i1 %cmp
110216 }
111217
218 define <2 x i1> @shl4_vec(<2 x i32> %X) {
219 ; CHECK-LABEL: @shl4_vec(
220 ; CHECK-NEXT: [[SUB:%.*]] = shl nsw <2 x i32> , %X
221 ; CHECK-NEXT: [[CMP:%.*]] = icmp sle <2 x i32> [[SUB]],
222 ; CHECK-NEXT: ret <2 x i1> [[CMP]]
223 ;
224 %sub = shl nsw <2 x i32> , %X
225 %cmp = icmp sle <2 x i32> %sub,
226 ret <2 x i1> %cmp
227 }
228
112229 ; 'shl nsw C2, x' produces [C2, C2 << CLZ(C2)-1]
113230 define i1 @icmp_shl_nsw_1(i64 %a) {
114231 ; CHECK-LABEL: @icmp_shl_nsw_1(
119236 ret i1 %cmp
120237 }
121238
239 define <2 x i1> @icmp_shl_nsw_1_vec(<2 x i64> %a) {
240 ; CHECK-LABEL: @icmp_shl_nsw_1_vec(
241 ; CHECK-NEXT: [[SHL:%.*]] = shl nsw <2 x i64> , %a
242 ; CHECK-NEXT: [[CMP:%.*]] = icmp sge <2 x i64> [[SHL]], zeroinitializer
243 ; CHECK-NEXT: ret <2 x i1> [[CMP]]
244 ;
245 %shl = shl nsw <2 x i64> , %a
246 %cmp = icmp sge <2 x i64> %shl, zeroinitializer
247 ret <2 x i1> %cmp
248 }
249
122250 ; 'shl nsw C2, x' produces [C2 << CLO(C2)-1, C2]
123251 define i1 @icmp_shl_nsw_neg1(i64 %a) {
124252 ; CHECK-LABEL: @icmp_shl_nsw_neg1(
129257 ret i1 %cmp
130258 }
131259
260 define <2 x i1> @icmp_shl_nsw_neg1_vec(<2 x i64> %a) {
261 ; CHECK-LABEL: @icmp_shl_nsw_neg1_vec(
262 ; CHECK-NEXT: [[SHL:%.*]] = shl nsw <2 x i64> , %a
263 ; CHECK-NEXT: [[CMP:%.*]] = icmp sge <2 x i64> [[SHL]],
264 ; CHECK-NEXT: ret <2 x i1> [[CMP]]
265 ;
266 %shl = shl nsw <2 x i64> , %a
267 %cmp = icmp sge <2 x i64> %shl,
268 ret <2 x i1> %cmp
269 }
270
132271 ; 'lshr x, C2' produces [0, UINT_MAX >> C2]
133272 define i1 @lshr2(i32 %x) {
134273 ; CHECK-LABEL: @lshr2(
139278 ret i1 %c
140279 }
141280
281 define <2 x i1> @lshr2_vec(<2 x i32> %x) {
282 ; CHECK-LABEL: @lshr2_vec(
283 ; CHECK-NEXT: [[S:%.*]] = lshr <2 x i32> %x,
284 ; CHECK-NEXT: [[C:%.*]] = icmp ugt <2 x i32> [[S]],
285 ; CHECK-NEXT: ret <2 x i1> [[C]]
286 ;
287 %s = lshr <2 x i32> %x,
288 %c = icmp ugt <2 x i32> %s,
289 ret <2 x i1> %c
290 }
291
142292 ; 'lshr C2, x' produces [C2 >> (Width-1), C2]
143293 define i1 @exact_lshr_ugt_false(i32 %a) {
144294 ; CHECK-LABEL: @exact_lshr_ugt_false(
149299 ret i1 %cmp
150300 }
151301
302 define <2 x i1> @exact_lshr_ugt_false_vec(<2 x i32> %a) {
303 ; CHECK-LABEL: @exact_lshr_ugt_false_vec(
304 ; CHECK-NEXT: [[SHR:%.*]] = lshr exact <2 x i32> , %a
305 ; CHECK-NEXT: [[CMP:%.*]] = icmp ult <2 x i32> [[SHR]],
306 ; CHECK-NEXT: ret <2 x i1> [[CMP]]
307 ;
308 %shr = lshr exact <2 x i32> , %a
309 %cmp = icmp ult <2 x i32> %shr,
310 ret <2 x i1> %cmp
311 }
312
152313 ; 'lshr C2, x' produces [C2 >> (Width-1), C2]
153314 define i1 @lshr_sgt_false(i32 %a) {
154315 ; CHECK-LABEL: @lshr_sgt_false(
159320 ret i1 %cmp
160321 }
161322
323 define <2 x i1> @lshr_sgt_false_vec(<2 x i32> %a) {
324 ; CHECK-LABEL: @lshr_sgt_false_vec(
325 ; CHECK-NEXT: [[SHR:%.*]] = lshr <2 x i32> , %a
326 ; CHECK-NEXT: [[CMP:%.*]] = icmp sgt <2 x i32> [[SHR]],
327 ; CHECK-NEXT: ret <2 x i1> [[CMP]]
328 ;
329 %shr = lshr <2 x i32> , %a
330 %cmp = icmp sgt <2 x i32> %shr,
331 ret <2 x i1> %cmp
332 }
333
162334 ; 'ashr x, C2' produces [INT_MIN >> C2, INT_MAX >> C2]
163335 define i1 @ashr2(i32 %x) {
164336 ; CHECK-LABEL: @ashr2(
169341 ret i1 %c
170342 }
171343
344 define <2 x i1> @ashr2_vec(<2 x i32> %x) {
345 ; CHECK-LABEL: @ashr2_vec(
346 ; CHECK-NEXT: [[S:%.*]] = ashr <2 x i32> %x,
347 ; CHECK-NEXT: [[C:%.*]] = icmp slt <2 x i32> [[S]],
348 ; CHECK-NEXT: ret <2 x i1> [[C]]
349 ;
350 %s = ashr <2 x i32> %x,
351 %c = icmp slt <2 x i32> %s,
352 ret <2 x i1> %c
353 }
354
172355 ; 'ashr C2, x' produces [C2, C2 >> (Width-1)]
173356 define i1 @ashr_sgt_false(i32 %a) {
174357 ; CHECK-LABEL: @ashr_sgt_false(
179362 ret i1 %cmp
180363 }
181364
365 define <2 x i1> @ashr_sgt_false_vec(<2 x i32> %a) {
366 ; CHECK-LABEL: @ashr_sgt_false_vec(
367 ; CHECK-NEXT: [[SHR:%.*]] = ashr <2 x i32> , %a
368 ; CHECK-NEXT: [[CMP:%.*]] = icmp sgt <2 x i32> [[SHR]],
369 ; CHECK-NEXT: ret <2 x i1> [[CMP]]
370 ;
371 %shr = ashr <2 x i32> , %a
372 %cmp = icmp sgt <2 x i32> %shr,
373 ret <2 x i1> %cmp
374 }
375
182376 ; 'ashr C2, x' produces [C2, C2 >> (Width-1)]
183377 define i1 @exact_ashr_sgt_false(i32 %a) {
184378 ; CHECK-LABEL: @exact_ashr_sgt_false(
189383 ret i1 %cmp
190384 }
191385
386 define <2 x i1> @exact_ashr_sgt_false_vec(<2 x i32> %a) {
387 ; CHECK-LABEL: @exact_ashr_sgt_false_vec(
388 ; CHECK-NEXT: [[SHR:%.*]] = ashr exact <2 x i32> , %a
389 ; CHECK-NEXT: [[CMP:%.*]] = icmp sgt <2 x i32> [[SHR]],
390 ; CHECK-NEXT: ret <2 x i1> [[CMP]]
391 ;
392 %shr = ashr exact <2 x i32> , %a
393 %cmp = icmp sgt <2 x i32> %shr,
394 ret <2 x i1> %cmp
395 }
396
192397 ; 'or x, C2' produces [C2, UINT_MAX]
193398 define i1 @or1(i32 %X) {
194399 ; CHECK-LABEL: @or1(
199404 ret i1 %B
200405 }
201406
407 define <2 x i1> @or1_vec(<2 x i32> %X) {
408 ; CHECK-LABEL: @or1_vec(
409 ; CHECK-NEXT: [[A:%.*]] = or <2 x i32> %X,
410 ; CHECK-NEXT: [[B:%.*]] = icmp ult <2 x i32> [[A]],
411 ; CHECK-NEXT: ret <2 x i1> [[B]]
412 ;
413 %A = or <2 x i32> %X,
414 %B = icmp ult <2 x i32> %A,
415 ret <2 x i1> %B
416 }
417
202418 ; 'and x, C2' produces [0, C2]
203419 define i1 @and1(i32 %X) {
204420 ; CHECK-LABEL: @and1(
209425 ret i1 %B
210426 }
211427
428 define <2 x i1> @and1_vec(<2 x i32> %X) {
429 ; CHECK-LABEL: @and1_vec(
430 ; CHECK-NEXT: [[A:%.*]] = and <2 x i32> %X,
431 ; CHECK-NEXT: [[B:%.*]] = icmp ugt <2 x i32> [[A]],
432 ; CHECK-NEXT: ret <2 x i1> [[B]]
433 ;
434 %A = and <2 x i32> %X,
435 %B = icmp ugt <2 x i32> %A,
436 ret <2 x i1> %B
437 }
438
212439 ; 'add nuw x, C2' produces [C2, UINT_MAX]
213440 define i1 @tautological9(i32 %x) {
214441 ; CHECK-LABEL: @tautological9(
219446 ret i1 %cmp
220447 }
221448
449 define <2 x i1> @tautological9_vec(<2 x i32> %x) {
450 ; CHECK-LABEL: @tautological9_vec(
451 ; CHECK-NEXT: [[ADD:%.*]] = add nuw <2 x i32> %x,
452 ; CHECK-NEXT: [[CMP:%.*]] = icmp ne <2 x i32> [[ADD]],
453 ; CHECK-NEXT: ret <2 x i1> [[CMP]]
454 ;
455 %add = add nuw <2 x i32> %x,
456 %cmp = icmp ne <2 x i32> %add,
457 ret <2 x i1> %cmp
458 }
459