Skip to content

Commit 17d508f

Browse files
committed
[InstCombine] Test foldSelectICmpAnd with cast. (NFC)
1 parent c01c3cf commit 17d508f

File tree

1 file changed

+46
-0
lines changed

1 file changed

+46
-0
lines changed

llvm/test/Transforms/InstCombine/select-icmp-and.ll

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -388,6 +388,37 @@ define i32 @test15e_extra_use(i32 %X) {
388388
ret i32 %t3
389389
}
390390

391+
;; (a & 128) ? 256 : 0
392+
define i32 @test15e_zext(i8 %X) {
393+
; CHECK-LABEL: @test15e_zext(
394+
; CHECK-NEXT: [[TMP1:%.*]] = and i8 [[X:%.*]], -128
395+
; CHECK-NEXT: [[TMP2:%.*]] = zext i8 [[TMP1]] to i32
396+
; CHECK-NEXT: [[T3:%.*]] = shl nuw nsw i32 [[TMP2]], 1
397+
; CHECK-NEXT: ret i32 [[T3]]
398+
;
399+
%t1 = and i8 %X, 128
400+
%t2 = icmp ne i8 %t1, 0
401+
%t3 = select i1 %t2, i32 256, i32 0
402+
ret i32 %t3
403+
}
404+
405+
;; (a & 128) ? 256 : 0
406+
define i32 @test15e_zext_extra_use(i8 %X) {
407+
; CHECK-LABEL: @test15e_zext_extra_use(
408+
; CHECK-NEXT: [[T2:%.*]] = icmp slt i8 [[X:%.*]], 0
409+
; CHECK-NEXT: [[TMP1:%.*]] = and i8 [[X]], -128
410+
; CHECK-NEXT: [[TMP2:%.*]] = zext i8 [[TMP1]] to i32
411+
; CHECK-NEXT: [[T3:%.*]] = shl nuw nsw i32 [[TMP2]], 1
412+
; CHECK-NEXT: call void @use1(i1 [[T2]])
413+
; CHECK-NEXT: ret i32 [[T3]]
414+
;
415+
%t1 = and i8 %X, 128
416+
%t2 = icmp ne i8 %t1, 0
417+
%t3 = select i1 %t2, i32 256, i32 0
418+
call void @use1(i1 %t2)
419+
ret i32 %t3
420+
}
421+
391422
;; (a & 128) ? 0 : 256
392423
define i32 @test15f(i32 %X) {
393424
; CHECK-LABEL: @test15f(
@@ -419,6 +450,21 @@ define i32 @test15f_extra_use(i32 %X) {
419450
ret i32 %t3
420451
}
421452

453+
;; (a & 128) ? 0 : 256
454+
define i16 @test15f_trunc(i32 %X) {
455+
; CHECK-LABEL: @test15f_trunc(
456+
; CHECK-NEXT: [[TMP1:%.*]] = trunc i32 [[X:%.*]] to i16
457+
; CHECK-NEXT: [[TMP2:%.*]] = shl i16 [[TMP1]], 1
458+
; CHECK-NEXT: [[TMP3:%.*]] = and i16 [[TMP2]], 256
459+
; CHECK-NEXT: [[T3:%.*]] = xor i16 [[TMP3]], 256
460+
; CHECK-NEXT: ret i16 [[T3]]
461+
;
462+
%t1 = and i32 %X, 128
463+
%t2 = icmp ne i32 %t1, 0
464+
%t3 = select i1 %t2, i16 0, i16 256
465+
ret i16 %t3
466+
}
467+
422468
;; (a & 8) ? -1 : -9
423469
define i32 @test15g(i32 %X) {
424470
; CHECK-LABEL: @test15g(

0 commit comments

Comments
 (0)