1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2 ; RUN: opt < %s -passes=instcombine -S | FileCheck %s
3 ; These should be InstSimplify checks, but most of the code
4 ; is currently only in InstCombine. TODO: move supporting code
7 declare void @use_vec(<2 x i8>)
9 ; Definitely out of range
10 define i1 @test_nonzero(i32* nocapture readonly %arg) {
11 ; CHECK-LABEL: @test_nonzero(
12 ; CHECK-NEXT: ret i1 true
14 %val = load i32, i32* %arg, !range !0
15 %rval = icmp ne i32 %val, 0
18 define i1 @test_nonzero2(i32* nocapture readonly %arg) {
19 ; CHECK-LABEL: @test_nonzero2(
20 ; CHECK-NEXT: ret i1 false
22 %val = load i32, i32* %arg, !range !0
23 %rval = icmp eq i32 %val, 0
27 ; Potentially in range
28 define i1 @test_nonzero3(i32* nocapture readonly %arg) {
29 ; CHECK-LABEL: @test_nonzero3(
30 ; CHECK-NEXT: [[VAL:%.*]] = load i32, i32* [[ARG:%.*]], align 4, !range [[RNG0:![0-9]+]]
31 ; CHECK-NEXT: [[RVAL:%.*]] = icmp ne i32 [[VAL]], 0
32 ; CHECK-NEXT: ret i1 [[RVAL]]
34 ; Check that this does not trigger - it wouldn't be legal
35 %val = load i32, i32* %arg, !range !1
36 %rval = icmp ne i32 %val, 0
41 define i1 @test_nonzero4(i8* nocapture readonly %arg) {
42 ; CHECK-LABEL: @test_nonzero4(
43 ; CHECK-NEXT: ret i1 false
45 %val = load i8, i8* %arg, !range !2
46 %rval = icmp ne i8 %val, 0
50 define i1 @test_nonzero5(i8* nocapture readonly %arg) {
51 ; CHECK-LABEL: @test_nonzero5(
52 ; CHECK-NEXT: ret i1 false
54 %val = load i8, i8* %arg, !range !2
55 %rval = icmp ugt i8 %val, 0
59 ; Cheaper checks (most values in range meet requirements)
60 define i1 @test_nonzero6(i8* %argw) {
61 ; CHECK-LABEL: @test_nonzero6(
62 ; CHECK-NEXT: [[VAL:%.*]] = load i8, i8* [[ARGW:%.*]], align 1, !range [[RNG1:![0-9]+]]
63 ; CHECK-NEXT: [[RVAL:%.*]] = icmp ne i8 [[VAL]], 0
64 ; CHECK-NEXT: ret i1 [[RVAL]]
66 %val = load i8, i8* %argw, !range !3
67 %rval = icmp sgt i8 %val, 0
71 ; Constant not in range, should return true.
72 define i1 @test_not_in_range(i32* nocapture readonly %arg) {
73 ; CHECK-LABEL: @test_not_in_range(
74 ; CHECK-NEXT: ret i1 true
76 %val = load i32, i32* %arg, !range !0
77 %rval = icmp ne i32 %val, 6
81 ; Constant in range, can not fold.
82 define i1 @test_in_range(i32* nocapture readonly %arg) {
83 ; CHECK-LABEL: @test_in_range(
84 ; CHECK-NEXT: [[VAL:%.*]] = load i32, i32* [[ARG:%.*]], align 4, !range [[RNG2:![0-9]+]]
85 ; CHECK-NEXT: [[RVAL:%.*]] = icmp ne i32 [[VAL]], 3
86 ; CHECK-NEXT: ret i1 [[RVAL]]
88 %val = load i32, i32* %arg, !range !0
89 %rval = icmp ne i32 %val, 3
93 ; Values in range greater than constant.
94 define i1 @test_range_sgt_constant(i32* nocapture readonly %arg) {
95 ; CHECK-LABEL: @test_range_sgt_constant(
96 ; CHECK-NEXT: ret i1 true
98 %val = load i32, i32* %arg, !range !0
99 %rval = icmp sgt i32 %val, 0
103 ; Values in range less than constant.
104 define i1 @test_range_slt_constant(i32* nocapture readonly %arg) {
105 ; CHECK-LABEL: @test_range_slt_constant(
106 ; CHECK-NEXT: ret i1 false
108 %val = load i32, i32* %arg, !range !0
109 %rval = icmp sgt i32 %val, 6
113 ; Values in union of multiple sub ranges not equal to constant.
114 define i1 @test_multi_range1(i32* nocapture readonly %arg) {
115 ; CHECK-LABEL: @test_multi_range1(
116 ; CHECK-NEXT: ret i1 true
118 %val = load i32, i32* %arg, !range !4
119 %rval = icmp ne i32 %val, 0
123 ; Values in multiple sub ranges not equal to constant, but in
124 ; union of sub ranges could possibly equal to constant. This
125 ; in theory could also be folded and might be implemented in
126 ; the future if shown profitable in practice.
127 define i1 @test_multi_range2(i32* nocapture readonly %arg) {
128 ; CHECK-LABEL: @test_multi_range2(
129 ; CHECK-NEXT: [[VAL:%.*]] = load i32, i32* [[ARG:%.*]], align 4, !range [[RNG3:![0-9]+]]
130 ; CHECK-NEXT: [[RVAL:%.*]] = icmp ne i32 [[VAL]], 7
131 ; CHECK-NEXT: ret i1 [[RVAL]]
133 %val = load i32, i32* %arg, !range !4
134 %rval = icmp ne i32 %val, 7
138 ; Values' ranges overlap each other, so it can not be simplified.
139 define i1 @test_two_ranges(i32* nocapture readonly %arg1, i32* nocapture readonly %arg2) {
140 ; CHECK-LABEL: @test_two_ranges(
141 ; CHECK-NEXT: [[VAL1:%.*]] = load i32, i32* [[ARG1:%.*]], align 4, !range [[RNG4:![0-9]+]]
142 ; CHECK-NEXT: [[VAL2:%.*]] = load i32, i32* [[ARG2:%.*]], align 4, !range [[RNG5:![0-9]+]]
143 ; CHECK-NEXT: [[RVAL:%.*]] = icmp ult i32 [[VAL2]], [[VAL1]]
144 ; CHECK-NEXT: ret i1 [[RVAL]]
146 %val1 = load i32, i32* %arg1, !range !5
147 %val2 = load i32, i32* %arg2, !range !6
148 %rval = icmp ult i32 %val2, %val1
152 ; Values' ranges do not overlap each other, so it can simplified to false.
153 define i1 @test_two_ranges2(i32* nocapture readonly %arg1, i32* nocapture readonly %arg2) {
154 ; CHECK-LABEL: @test_two_ranges2(
155 ; CHECK-NEXT: ret i1 false
157 %val1 = load i32, i32* %arg1, !range !0
158 %val2 = load i32, i32* %arg2, !range !6
159 %rval = icmp ult i32 %val2, %val1
163 ; Values' ranges do not overlap each other, so it can simplified to true.
164 define i1 @test_two_ranges3(i32* nocapture readonly %arg1, i32* nocapture readonly %arg2) {
165 ; CHECK-LABEL: @test_two_ranges3(
166 ; CHECK-NEXT: ret i1 true
168 %val1 = load i32, i32* %arg1, !range !0
169 %val2 = load i32, i32* %arg2, !range !6
170 %rval = icmp ugt i32 %val2, %val1
174 define i1 @ugt_zext(i1 %b, i8 %x) {
175 ; CHECK-LABEL: @ugt_zext(
176 ; CHECK-NEXT: [[TMP1:%.*]] = icmp eq i8 [[X:%.*]], 0
177 ; CHECK-NEXT: [[R:%.*]] = and i1 [[TMP1]], [[B:%.*]]
178 ; CHECK-NEXT: ret i1 [[R]]
180 %z = zext i1 %b to i8
181 %r = icmp ugt i8 %z, %x
185 define <2 x i1> @ult_zext(<2 x i1> %b, <2 x i8> %p) {
186 ; CHECK-LABEL: @ult_zext(
187 ; CHECK-NEXT: [[X:%.*]] = mul <2 x i8> [[P:%.*]], [[P]]
188 ; CHECK-NEXT: [[TMP1:%.*]] = icmp eq <2 x i8> [[X]], zeroinitializer
189 ; CHECK-NEXT: [[R:%.*]] = and <2 x i1> [[TMP1]], [[B:%.*]]
190 ; CHECK-NEXT: ret <2 x i1> [[R]]
192 %x = mul <2 x i8> %p, %p ; thwart complexity-based canonicalization
193 %z = zext <2 x i1> %b to <2 x i8>
194 %r = icmp ult <2 x i8> %x, %z
198 ; negative test - need ult/ugt
200 define i1 @uge_zext(i1 %b, i8 %x) {
201 ; CHECK-LABEL: @uge_zext(
202 ; CHECK-NEXT: [[Z:%.*]] = zext i1 [[B:%.*]] to i8
203 ; CHECK-NEXT: [[R:%.*]] = icmp uge i8 [[Z]], [[X:%.*]]
204 ; CHECK-NEXT: ret i1 [[R]]
206 %z = zext i1 %b to i8
207 %r = icmp uge i8 %z, %x
211 ; negative test - need ult/ugt
213 define i1 @ule_zext(i1 %b, i8 %p) {
214 ; CHECK-LABEL: @ule_zext(
215 ; CHECK-NEXT: [[X:%.*]] = mul i8 [[P:%.*]], [[P]]
216 ; CHECK-NEXT: [[Z:%.*]] = zext i1 [[B:%.*]] to i8
217 ; CHECK-NEXT: [[R:%.*]] = icmp ule i8 [[X]], [[Z]]
218 ; CHECK-NEXT: ret i1 [[R]]
220 %x = mul i8 %p, %p ; thwart complexity-based canonicalization
221 %z = zext i1 %b to i8
222 %r = icmp ule i8 %x, %z
226 ; negative test - extra use
228 define i1 @ugt_zext_use(i1 %b, i8 %x) {
229 ; CHECK-LABEL: @ugt_zext_use(
230 ; CHECK-NEXT: [[Z:%.*]] = zext i1 [[B:%.*]] to i8
231 ; CHECK-NEXT: call void @use(i8 [[Z]])
232 ; CHECK-NEXT: [[R:%.*]] = icmp ugt i8 [[Z]], [[X:%.*]]
233 ; CHECK-NEXT: ret i1 [[R]]
235 %z = zext i1 %b to i8
236 call void @use(i8 %z)
237 %r = icmp ugt i8 %z, %x
241 ; negative test - must be zext of i1
243 define i1 @ult_zext_not_i1(i2 %b, i8 %x) {
244 ; CHECK-LABEL: @ult_zext_not_i1(
245 ; CHECK-NEXT: [[Z:%.*]] = zext i2 [[B:%.*]] to i8
246 ; CHECK-NEXT: [[R:%.*]] = icmp ugt i8 [[Z]], [[X:%.*]]
247 ; CHECK-NEXT: ret i1 [[R]]
249 %z = zext i2 %b to i8
250 %r = icmp ult i8 %x, %z
256 define i1 @sub_ult_zext(i1 %b, i8 %x, i8 %y) {
257 ; CHECK-LABEL: @sub_ult_zext(
258 ; CHECK-NEXT: [[TMP1:%.*]] = icmp eq i8 [[X:%.*]], [[Y:%.*]]
259 ; CHECK-NEXT: [[R:%.*]] = and i1 [[TMP1]], [[B:%.*]]
260 ; CHECK-NEXT: ret i1 [[R]]
262 %z = zext i1 %b to i8
264 %r = icmp ult i8 %s, %z
268 define i1 @zext_ult_zext(i1 %b, i8 %p) {
269 ; CHECK-LABEL: @zext_ult_zext(
270 ; CHECK-NEXT: [[X:%.*]] = mul i8 [[P:%.*]], [[P]]
271 ; CHECK-NEXT: [[TMP1:%.*]] = icmp eq i8 [[X]], 0
272 ; CHECK-NEXT: [[R:%.*]] = and i1 [[TMP1]], [[B:%.*]]
273 ; CHECK-NEXT: ret i1 [[R]]
275 %x = mul i8 %p, %p ; thwart complexity-based canonicalization
276 %z = zext i1 %b to i16
277 %zx = zext i8 %x to i16
278 %r = icmp ult i16 %zx, %z
282 ; match and fold even if both sides are zexts (from different source types)
284 define i1 @zext_ugt_zext(i1 %b, i4 %x) {
285 ; CHECK-LABEL: @zext_ugt_zext(
286 ; CHECK-NEXT: [[ZX:%.*]] = zext i4 [[X:%.*]] to i8
287 ; CHECK-NEXT: call void @use(i8 [[ZX]])
288 ; CHECK-NEXT: [[TMP1:%.*]] = icmp eq i4 [[X]], 0
289 ; CHECK-NEXT: [[R:%.*]] = and i1 [[TMP1]], [[B:%.*]]
290 ; CHECK-NEXT: ret i1 [[R]]
292 %z = zext i1 %b to i8
293 %zx = zext i4 %x to i8
294 call void @use(i8 %zx)
295 %r = icmp ugt i8 %z, %zx
299 ; negative test - must be zext of i1
301 define i1 @sub_ult_zext_not_i1(i2 %b, i8 %x, i8 %y) {
302 ; CHECK-LABEL: @sub_ult_zext_not_i1(
303 ; CHECK-NEXT: [[Z:%.*]] = zext i2 [[B:%.*]] to i8
304 ; CHECK-NEXT: [[S:%.*]] = sub i8 [[X:%.*]], [[Y:%.*]]
305 ; CHECK-NEXT: [[R:%.*]] = icmp ult i8 [[S]], [[Z]]
306 ; CHECK-NEXT: ret i1 [[R]]
308 %z = zext i2 %b to i8
310 %r = icmp ult i8 %s, %z
314 ; negative test - extra use (but we could try harder to fold this)
316 define i1 @sub_ult_zext_use1(i1 %b, i8 %x, i8 %y) {
317 ; CHECK-LABEL: @sub_ult_zext_use1(
318 ; CHECK-NEXT: [[Z:%.*]] = zext i1 [[B:%.*]] to i8
319 ; CHECK-NEXT: call void @use(i8 [[Z]])
320 ; CHECK-NEXT: [[S:%.*]] = sub i8 [[X:%.*]], [[Y:%.*]]
321 ; CHECK-NEXT: [[R:%.*]] = icmp ult i8 [[S]], [[Z]]
322 ; CHECK-NEXT: ret i1 [[R]]
324 %z = zext i1 %b to i8
325 call void @use(i8 %z)
327 %r = icmp ult i8 %s, %z
331 define <2 x i1> @zext_ugt_sub_use2(<2 x i1> %b, <2 x i8> %x, <2 x i8> %y) {
332 ; CHECK-LABEL: @zext_ugt_sub_use2(
333 ; CHECK-NEXT: [[S:%.*]] = sub <2 x i8> [[X:%.*]], [[Y:%.*]]
334 ; CHECK-NEXT: call void @use_vec(<2 x i8> [[S]])
335 ; CHECK-NEXT: [[TMP1:%.*]] = icmp eq <2 x i8> [[X]], [[Y]]
336 ; CHECK-NEXT: [[R:%.*]] = and <2 x i1> [[TMP1]], [[B:%.*]]
337 ; CHECK-NEXT: ret <2 x i1> [[R]]
339 %z = zext <2 x i1> %b to <2 x i8>
340 %s = sub <2 x i8> %x, %y
341 call void @use_vec(<2 x i8> %s)
342 %r = icmp ugt <2 x i8> %z, %s
346 define i1 @sub_ult_zext_use3(i1 %b, i8 %x, i8 %y) {
347 ; CHECK-LABEL: @sub_ult_zext_use3(
348 ; CHECK-NEXT: [[Z:%.*]] = zext i1 [[B:%.*]] to i8
349 ; CHECK-NEXT: call void @use(i8 [[Z]])
350 ; CHECK-NEXT: [[S:%.*]] = sub i8 [[X:%.*]], [[Y:%.*]]
351 ; CHECK-NEXT: call void @use(i8 [[S]])
352 ; CHECK-NEXT: [[R:%.*]] = icmp ult i8 [[S]], [[Z]]
353 ; CHECK-NEXT: ret i1 [[R]]
355 %z = zext i1 %b to i8
356 call void @use(i8 %z)
358 call void @use(i8 %s)
359 %r = icmp ult i8 %s, %z
363 define i1 @sub_ule_zext(i1 %b, i8 %x, i8 %y) {
364 ; CHECK-LABEL: @sub_ule_zext(
365 ; CHECK-NEXT: [[Z:%.*]] = zext i1 [[B:%.*]] to i8
366 ; CHECK-NEXT: [[S:%.*]] = sub i8 [[X:%.*]], [[Y:%.*]]
367 ; CHECK-NEXT: [[R:%.*]] = icmp ule i8 [[S]], [[Z]]
368 ; CHECK-NEXT: ret i1 [[R]]
370 %z = zext i1 %b to i8
372 %r = icmp ule i8 %s, %z
376 define <2 x i1> @sub_ult_and(<2 x i8> %b, <2 x i8> %x, <2 x i8> %y) {
377 ; CHECK-LABEL: @sub_ult_and(
378 ; CHECK-NEXT: [[A:%.*]] = and <2 x i8> [[B:%.*]], <i8 1, i8 1>
379 ; CHECK-NEXT: [[S:%.*]] = sub <2 x i8> [[X:%.*]], [[Y:%.*]]
380 ; CHECK-NEXT: [[R:%.*]] = icmp ult <2 x i8> [[S]], [[A]]
381 ; CHECK-NEXT: ret <2 x i1> [[R]]
383 %a = and <2 x i8> %b, <i8 1, i8 1>
384 %s = sub <2 x i8> %x, %y
385 %r = icmp ult <2 x i8> %s, %a
389 define i1 @and_ugt_sub(i8 %b, i8 %x, i8 %y) {
390 ; CHECK-LABEL: @and_ugt_sub(
391 ; CHECK-NEXT: [[A:%.*]] = and i8 [[B:%.*]], 1
392 ; CHECK-NEXT: [[S:%.*]] = sub i8 [[X:%.*]], [[Y:%.*]]
393 ; CHECK-NEXT: [[R:%.*]] = icmp ugt i8 [[A]], [[S]]
394 ; CHECK-NEXT: ret i1 [[R]]
398 %r = icmp ugt i8 %a, %s
402 ; Repeat the zext set of tests with a sext instead.
404 define i1 @uge_sext(i1 %b, i8 %x) {
405 ; CHECK-LABEL: @uge_sext(
406 ; CHECK-NEXT: [[TMP1:%.*]] = icmp eq i8 [[X:%.*]], 0
407 ; CHECK-NEXT: [[R:%.*]] = or i1 [[TMP1]], [[B:%.*]]
408 ; CHECK-NEXT: ret i1 [[R]]
410 %s = sext i1 %b to i8
411 %r = icmp uge i8 %s, %x
415 define <2 x i1> @ule_sext(<2 x i1> %b, <2 x i8> %p) {
416 ; CHECK-LABEL: @ule_sext(
417 ; CHECK-NEXT: [[X:%.*]] = mul <2 x i8> [[P:%.*]], [[P]]
418 ; CHECK-NEXT: [[TMP1:%.*]] = icmp eq <2 x i8> [[X]], zeroinitializer
419 ; CHECK-NEXT: [[R:%.*]] = or <2 x i1> [[TMP1]], [[B:%.*]]
420 ; CHECK-NEXT: ret <2 x i1> [[R]]
422 %x = mul <2 x i8> %p, %p ; thwart complexity-based canonicalization
423 %s = sext <2 x i1> %b to <2 x i8>
424 %r = icmp ule <2 x i8> %x, %s
428 ; negative test - need ule/uge
430 define i1 @ugt_sext(i1 %b, i8 %x) {
431 ; CHECK-LABEL: @ugt_sext(
432 ; CHECK-NEXT: [[S:%.*]] = sext i1 [[B:%.*]] to i8
433 ; CHECK-NEXT: [[R:%.*]] = icmp ugt i8 [[S]], [[X:%.*]]
434 ; CHECK-NEXT: ret i1 [[R]]
436 %s = sext i1 %b to i8
437 %r = icmp ugt i8 %s, %x
441 ; negative test - need ule/uge
443 define i1 @ult_sext(i1 %b, i8 %p) {
444 ; CHECK-LABEL: @ult_sext(
445 ; CHECK-NEXT: [[X:%.*]] = mul i8 [[P:%.*]], [[P]]
446 ; CHECK-NEXT: [[S:%.*]] = sext i1 [[B:%.*]] to i8
447 ; CHECK-NEXT: [[R:%.*]] = icmp ult i8 [[X]], [[S]]
448 ; CHECK-NEXT: ret i1 [[R]]
450 %x = mul i8 %p, %p ; thwart complexity-based canonicalization
451 %s = sext i1 %b to i8
452 %r = icmp ult i8 %x, %s
456 ; negative test - extra use
458 define i1 @uge_sext_use(i1 %b, i8 %x) {
459 ; CHECK-LABEL: @uge_sext_use(
460 ; CHECK-NEXT: [[S:%.*]] = sext i1 [[B:%.*]] to i8
461 ; CHECK-NEXT: call void @use(i8 [[S]])
462 ; CHECK-NEXT: [[R:%.*]] = icmp uge i8 [[S]], [[X:%.*]]
463 ; CHECK-NEXT: ret i1 [[R]]
465 %s = sext i1 %b to i8
466 call void @use(i8 %s)
467 %r = icmp uge i8 %s, %x
471 ; negative test - must be sext of i1
473 define i1 @ule_sext_not_i1(i2 %b, i8 %x) {
474 ; CHECK-LABEL: @ule_sext_not_i1(
475 ; CHECK-NEXT: [[S:%.*]] = sext i2 [[B:%.*]] to i8
476 ; CHECK-NEXT: [[R:%.*]] = icmp uge i8 [[S]], [[X:%.*]]
477 ; CHECK-NEXT: ret i1 [[R]]
479 %s = sext i2 %b to i8
480 %r = icmp ule i8 %x, %s
486 define i1 @sub_ule_sext(i1 %b, i8 %x, i8 %y) {
487 ; CHECK-LABEL: @sub_ule_sext(
488 ; CHECK-NEXT: [[TMP1:%.*]] = icmp eq i8 [[X:%.*]], [[Y:%.*]]
489 ; CHECK-NEXT: [[R:%.*]] = or i1 [[TMP1]], [[B:%.*]]
490 ; CHECK-NEXT: ret i1 [[R]]
492 %s = sext i1 %b to i8
494 %r = icmp ule i8 %d, %s
498 define i1 @sext_ule_sext(i1 %b, i8 %p) {
499 ; CHECK-LABEL: @sext_ule_sext(
500 ; CHECK-NEXT: [[X:%.*]] = mul i8 [[P:%.*]], [[P]]
501 ; CHECK-NEXT: [[TMP1:%.*]] = icmp eq i8 [[X]], 0
502 ; CHECK-NEXT: [[R:%.*]] = or i1 [[TMP1]], [[B:%.*]]
503 ; CHECK-NEXT: ret i1 [[R]]
505 %x = mul i8 %p, %p ; thwart complexity-based canonicalization
506 %s = sext i1 %b to i16
507 %sx = sext i8 %x to i16
508 %r = icmp ule i16 %sx, %s
512 ; match and fold even if both sides are sexts (from different source types)
514 define i1 @sext_uge_sext(i1 %b, i4 %x) {
515 ; CHECK-LABEL: @sext_uge_sext(
516 ; CHECK-NEXT: [[SX:%.*]] = sext i4 [[X:%.*]] to i8
517 ; CHECK-NEXT: call void @use(i8 [[SX]])
518 ; CHECK-NEXT: [[TMP1:%.*]] = icmp eq i4 [[X]], 0
519 ; CHECK-NEXT: [[R:%.*]] = or i1 [[TMP1]], [[B:%.*]]
520 ; CHECK-NEXT: ret i1 [[R]]
522 %s = sext i1 %b to i8
523 %sx = sext i4 %x to i8
524 call void @use(i8 %sx)
525 %r = icmp uge i8 %s, %sx
529 ; negative test - must be sext of i1
531 define i1 @sub_ule_sext_not_i1(i2 %b, i8 %x, i8 %y) {
532 ; CHECK-LABEL: @sub_ule_sext_not_i1(
533 ; CHECK-NEXT: [[S:%.*]] = sext i2 [[B:%.*]] to i8
534 ; CHECK-NEXT: [[D:%.*]] = sub i8 [[X:%.*]], [[Y:%.*]]
535 ; CHECK-NEXT: [[R:%.*]] = icmp ule i8 [[D]], [[S]]
536 ; CHECK-NEXT: ret i1 [[R]]
538 %s = sext i2 %b to i8
540 %r = icmp ule i8 %d, %s
544 ; negative test - extra use (but we could try harder to fold this)
546 define i1 @sub_ule_sext_use1(i1 %b, i8 %x, i8 %y) {
547 ; CHECK-LABEL: @sub_ule_sext_use1(
548 ; CHECK-NEXT: [[S:%.*]] = sext i1 [[B:%.*]] to i8
549 ; CHECK-NEXT: call void @use(i8 [[S]])
550 ; CHECK-NEXT: [[D:%.*]] = sub i8 [[X:%.*]], [[Y:%.*]]
551 ; CHECK-NEXT: [[R:%.*]] = icmp ule i8 [[D]], [[S]]
552 ; CHECK-NEXT: ret i1 [[R]]
554 %s = sext i1 %b to i8
555 call void @use(i8 %s)
557 %r = icmp ule i8 %d, %s
561 define <2 x i1> @sext_uge_sub_use2(<2 x i1> %b, <2 x i8> %x, <2 x i8> %y) {
562 ; CHECK-LABEL: @sext_uge_sub_use2(
563 ; CHECK-NEXT: [[D:%.*]] = sub <2 x i8> [[X:%.*]], [[Y:%.*]]
564 ; CHECK-NEXT: call void @use_vec(<2 x i8> [[D]])
565 ; CHECK-NEXT: [[TMP1:%.*]] = icmp eq <2 x i8> [[X]], [[Y]]
566 ; CHECK-NEXT: [[R:%.*]] = or <2 x i1> [[TMP1]], [[B:%.*]]
567 ; CHECK-NEXT: ret <2 x i1> [[R]]
569 %s = sext <2 x i1> %b to <2 x i8>
570 %d = sub <2 x i8> %x, %y
571 call void @use_vec(<2 x i8> %d)
572 %r = icmp uge <2 x i8> %s, %d
576 define i1 @sub_ule_sext_use3(i1 %b, i8 %x, i8 %y) {
577 ; CHECK-LABEL: @sub_ule_sext_use3(
578 ; CHECK-NEXT: [[S:%.*]] = sext i1 [[B:%.*]] to i8
579 ; CHECK-NEXT: call void @use(i8 [[S]])
580 ; CHECK-NEXT: [[D:%.*]] = sub i8 [[X:%.*]], [[Y:%.*]]
581 ; CHECK-NEXT: call void @use(i8 [[D]])
582 ; CHECK-NEXT: [[R:%.*]] = icmp ule i8 [[D]], [[S]]
583 ; CHECK-NEXT: ret i1 [[R]]
585 %s = sext i1 %b to i8
586 call void @use(i8 %s)
588 call void @use(i8 %d)
589 %r = icmp ule i8 %d, %s
593 define i1 @sub_ult_sext(i1 %b, i8 %x, i8 %y) {
594 ; CHECK-LABEL: @sub_ult_sext(
595 ; CHECK-NEXT: [[S:%.*]] = sext i1 [[B:%.*]] to i8
596 ; CHECK-NEXT: [[D:%.*]] = sub i8 [[X:%.*]], [[Y:%.*]]
597 ; CHECK-NEXT: [[R:%.*]] = icmp ult i8 [[D]], [[S]]
598 ; CHECK-NEXT: ret i1 [[R]]
600 %s = sext i1 %b to i8
602 %r = icmp ult i8 %d, %s
606 define <2 x i1> @sub_ule_ashr(<2 x i8> %b, <2 x i8> %x, <2 x i8> %y) {
607 ; CHECK-LABEL: @sub_ule_ashr(
608 ; CHECK-NEXT: [[A:%.*]] = ashr <2 x i8> [[B:%.*]], <i8 7, i8 7>
609 ; CHECK-NEXT: [[S:%.*]] = sub <2 x i8> [[X:%.*]], [[Y:%.*]]
610 ; CHECK-NEXT: [[R:%.*]] = icmp ule <2 x i8> [[S]], [[A]]
611 ; CHECK-NEXT: ret <2 x i1> [[R]]
613 %a = ashr <2 x i8> %b, <i8 7, i8 7>
614 %s = sub <2 x i8> %x, %y
615 %r = icmp ule <2 x i8> %s, %a
619 define i1 @ashr_uge_sub(i8 %b, i8 %x, i8 %y) {
620 ; CHECK-LABEL: @ashr_uge_sub(
621 ; CHECK-NEXT: [[A:%.*]] = ashr i8 [[B:%.*]], 7
622 ; CHECK-NEXT: [[S:%.*]] = sub i8 [[X:%.*]], [[Y:%.*]]
623 ; CHECK-NEXT: [[R:%.*]] = icmp uge i8 [[A]], [[S]]
624 ; CHECK-NEXT: ret i1 [[R]]
628 %r = icmp uge i8 %a, %s
636 !4 = !{i32 1, i32 6, i32 8, i32 10}
637 !5 = !{i32 5, i32 10}
638 !6 = !{i32 8, i32 16}