Skip to content

Commit 6b64a2b

Browse files
committed
[InstCombine] Drop samesign in InstCombinerImpl::foldICmpAndShift
1 parent e1c281d commit 6b64a2b

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1738,6 +1738,7 @@ Instruction *InstCombinerImpl::foldICmpAndShift(ICmpInst &Cmp,
17381738

17391739
// Compute X & (C2 << Y).
17401740
Value *NewAnd = Builder.CreateAnd(Shift->getOperand(0), NewShift);
1741+
Cmp.setSameSign(false);
17411742
return replaceOperand(Cmp, 0, NewAnd);
17421743
}
17431744

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

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -619,6 +619,19 @@ define i1 @test_shr_and_1_ne_0(i32 %a, i32 %b) {
619619
ret i1 %cmp
620620
}
621621

622+
define i1 @test_shr_and_1_ne_0_samesign(i32 %a, i32 %b) {
623+
; CHECK-LABEL: @test_shr_and_1_ne_0_samesign(
624+
; CHECK-NEXT: [[TMP1:%.*]] = shl nuw i32 1, [[B:%.*]]
625+
; CHECK-NEXT: [[TMP2:%.*]] = and i32 [[A:%.*]], [[TMP1]]
626+
; CHECK-NEXT: [[CMP:%.*]] = icmp ne i32 [[TMP2]], 0
627+
; CHECK-NEXT: ret i1 [[CMP]]
628+
;
629+
%shr = lshr i32 %a, %b
630+
%and = and i32 %shr, 1
631+
%cmp = icmp samesign ne i32 %and, 0
632+
ret i1 %cmp
633+
}
634+
622635
define i1 @test_const_shr_and_1_ne_0(i32 %b) {
623636
; CHECK-LABEL: @test_const_shr_and_1_ne_0(
624637
; CHECK-NEXT: [[TMP1:%.*]] = shl nuw i32 1, [[B:%.*]]

0 commit comments

Comments
 (0)