Skip to content

Commit cef862e

Browse files
committed
[InstCombine] Tests for (icmp eq/ne (and (shl -1, X), Y), 0) -> (icmp eq/ne (lshr Y, X), 0); NFC
1 parent 7b275aa commit cef862e

File tree

1 file changed

+88
-0
lines changed

1 file changed

+88
-0
lines changed

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

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -520,3 +520,91 @@ define i1 @slt_and_shl_one(i8 %x, i8 %y) {
520520
%cmp = icmp slt i8 %and, %pow2
521521
ret i1 %cmp
522522
}
523+
524+
define i1 @fold_eq_lhs(i8 %x, i8 %y) {
525+
; CHECK-LABEL: @fold_eq_lhs(
526+
; CHECK-NEXT: [[SHL:%.*]] = shl nsw i8 -1, [[X:%.*]]
527+
; CHECK-NEXT: [[AND:%.*]] = and i8 [[SHL]], [[Y:%.*]]
528+
; CHECK-NEXT: [[R:%.*]] = icmp eq i8 [[AND]], 0
529+
; CHECK-NEXT: ret i1 [[R]]
530+
;
531+
%shl = shl i8 -1, %x
532+
%and = and i8 %shl, %y
533+
%r = icmp eq i8 %and, 0
534+
ret i1 %r
535+
}
536+
537+
define i1 @fold_eq_lhs_fail_eq_nonzero(i8 %x, i8 %y) {
538+
; CHECK-LABEL: @fold_eq_lhs_fail_eq_nonzero(
539+
; CHECK-NEXT: [[SHL:%.*]] = shl nsw i8 -1, [[X:%.*]]
540+
; CHECK-NEXT: [[AND:%.*]] = and i8 [[SHL]], [[Y:%.*]]
541+
; CHECK-NEXT: [[R:%.*]] = icmp eq i8 [[AND]], 1
542+
; CHECK-NEXT: ret i1 [[R]]
543+
;
544+
%shl = shl i8 -1, %x
545+
%and = and i8 %shl, %y
546+
%r = icmp eq i8 %and, 1
547+
ret i1 %r
548+
}
549+
550+
define i1 @fold_eq_lhs_fail_multiuse_shl(i8 %x, i8 %y) {
551+
; CHECK-LABEL: @fold_eq_lhs_fail_multiuse_shl(
552+
; CHECK-NEXT: [[SHL:%.*]] = shl nsw i8 -1, [[X:%.*]]
553+
; CHECK-NEXT: call void @use(i8 [[SHL]])
554+
; CHECK-NEXT: [[AND:%.*]] = and i8 [[SHL]], [[Y:%.*]]
555+
; CHECK-NEXT: [[R:%.*]] = icmp eq i8 [[AND]], 0
556+
; CHECK-NEXT: ret i1 [[R]]
557+
;
558+
%shl = shl i8 -1, %x
559+
call void @use(i8 %shl)
560+
%and = and i8 %shl, %y
561+
%r = icmp eq i8 %and, 0
562+
ret i1 %r
563+
}
564+
565+
define i1 @fold_ne_rhs(i8 %x, i8 %yy) {
566+
; CHECK-LABEL: @fold_ne_rhs(
567+
; CHECK-NEXT: [[Y:%.*]] = xor i8 [[YY:%.*]], 123
568+
; CHECK-NEXT: [[SHL:%.*]] = shl nsw i8 -1, [[X:%.*]]
569+
; CHECK-NEXT: [[AND:%.*]] = and i8 [[Y]], [[SHL]]
570+
; CHECK-NEXT: [[R:%.*]] = icmp ne i8 [[AND]], 0
571+
; CHECK-NEXT: ret i1 [[R]]
572+
;
573+
%y = xor i8 %yy, 123
574+
%shl = shl i8 -1, %x
575+
%and = and i8 %y, %shl
576+
%r = icmp ne i8 %and, 0
577+
ret i1 %r
578+
}
579+
580+
define i1 @fold_ne_rhs_fail_multiuse_and(i8 %x, i8 %yy) {
581+
; CHECK-LABEL: @fold_ne_rhs_fail_multiuse_and(
582+
; CHECK-NEXT: [[Y:%.*]] = xor i8 [[YY:%.*]], 123
583+
; CHECK-NEXT: [[SHL:%.*]] = shl nsw i8 -1, [[X:%.*]]
584+
; CHECK-NEXT: [[AND:%.*]] = and i8 [[Y]], [[SHL]]
585+
; CHECK-NEXT: call void @use(i8 [[AND]])
586+
; CHECK-NEXT: [[R:%.*]] = icmp ne i8 [[AND]], 0
587+
; CHECK-NEXT: ret i1 [[R]]
588+
;
589+
%y = xor i8 %yy, 123
590+
%shl = shl i8 -1, %x
591+
%and = and i8 %y, %shl
592+
call void @use(i8 %and)
593+
%r = icmp ne i8 %and, 0
594+
ret i1 %r
595+
}
596+
597+
define i1 @fold_ne_rhs_fail_shift_not_1s(i8 %x, i8 %yy) {
598+
; CHECK-LABEL: @fold_ne_rhs_fail_shift_not_1s(
599+
; CHECK-NEXT: [[Y:%.*]] = xor i8 [[YY:%.*]], 122
600+
; CHECK-NEXT: [[SHL:%.*]] = shl i8 -2, [[X:%.*]]
601+
; CHECK-NEXT: [[AND:%.*]] = and i8 [[Y]], [[SHL]]
602+
; CHECK-NEXT: [[R:%.*]] = icmp ne i8 [[AND]], 0
603+
; CHECK-NEXT: ret i1 [[R]]
604+
;
605+
%y = xor i8 %yy, 123
606+
%shl = shl i8 -2, %x
607+
%and = and i8 %y, %shl
608+
%r = icmp ne i8 %and, 0
609+
ret i1 %r
610+
}

0 commit comments

Comments
 (0)