Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1738,7 +1738,7 @@ Instruction *InstCombinerImpl::foldICmpAndShift(ICmpInst &Cmp,

// Compute X & (C2 << Y).
Value *NewAnd = Builder.CreateAnd(Shift->getOperand(0), NewShift);
return replaceOperand(Cmp, 0, NewAnd);
return new ICmpInst(Cmp.getPredicate(), NewAnd, Cmp.getOperand(1));
}

return nullptr;
Expand Down Expand Up @@ -1844,7 +1844,7 @@ Instruction *InstCombinerImpl::foldICmpAndConstConst(ICmpInst &Cmp,
/*HasNUW=*/true),
One, Or->getName());
Value *NewAnd = Builder.CreateAnd(A, NewOr, And->getName());
return replaceOperand(Cmp, 0, NewAnd);
return new ICmpInst(Cmp.getPredicate(), NewAnd, Cmp.getOperand(1));
}
}
}
Expand Down
1 change: 1 addition & 0 deletions llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1448,6 +1448,7 @@ Instruction *InstCombinerImpl::foldSelectEqualityTest(SelectInst &Sel) {
m_c_SpecificICmp(ICmpInst::ICMP_EQ, m_Specific(X), m_Specific(Y))))
return nullptr;

cast<ICmpInst>(XeqY)->setSameSign(false);
return replaceInstUsesWith(Sel, XeqY);
}

Expand Down
13 changes: 13 additions & 0 deletions llvm/test/Transforms/InstCombine/icmp-and-shift.ll
Original file line number Diff line number Diff line change
Expand Up @@ -619,6 +619,19 @@ define i1 @test_shr_and_1_ne_0(i32 %a, i32 %b) {
ret i1 %cmp
}

define i1 @test_shr_and_1_ne_0_samesign(i32 %a, i32 %b) {
; CHECK-LABEL: @test_shr_and_1_ne_0_samesign(
; CHECK-NEXT: [[TMP1:%.*]] = shl nuw i32 1, [[B:%.*]]
; CHECK-NEXT: [[TMP2:%.*]] = and i32 [[A:%.*]], [[TMP1]]
; CHECK-NEXT: [[CMP:%.*]] = icmp ne i32 [[TMP2]], 0
; CHECK-NEXT: ret i1 [[CMP]]
;
%shr = lshr i32 %a, %b
%and = and i32 %shr, 1
%cmp = icmp samesign ne i32 %and, 0
ret i1 %cmp
}

define i1 @test_const_shr_and_1_ne_0(i32 %b) {
; CHECK-LABEL: @test_const_shr_and_1_ne_0(
; CHECK-NEXT: [[TMP1:%.*]] = shl nuw i32 1, [[B:%.*]]
Expand Down
16 changes: 16 additions & 0 deletions llvm/test/Transforms/InstCombine/icmp-equality-test.ll
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,22 @@ entry:
ret i1 %equal
}

define i1 @icmp_equality_test_constant_samesign(i42 %X, i42 %Y) {
; CHECK-LABEL: @icmp_equality_test_constant_samesign(
; CHECK-NEXT: entry:
; CHECK-NEXT: [[XEQY:%.*]] = icmp eq i42 [[X:%.*]], [[Y:%.*]]
; CHECK-NEXT: ret i1 [[XEQY]]
;
entry:
%XeqC = icmp eq i42 %X, -42
%YeqC = icmp eq i42 %Y, -42
%XeqY = icmp samesign eq i42 %X, %Y
%not.YeqC = xor i1 %YeqC, true
%and = select i1 %not.YeqC, i1 %XeqY, i1 false
%equal = select i1 %XeqC, i1 %YeqC, i1 %and
ret i1 %equal
}

define i1 @icmp_equality_test_swift_optional_pointers(i64 %X, i64 %Y) {
; CHECK-LABEL: @icmp_equality_test_swift_optional_pointers(
; CHECK-NEXT: entry:
Expand Down
15 changes: 15 additions & 0 deletions llvm/test/Transforms/InstCombine/icmp.ll
Original file line number Diff line number Diff line change
Expand Up @@ -3203,6 +3203,21 @@ define i1 @icmp_and_or_lshr(i32 %x, i32 %y) {
ret i1 %ret
}

define i1 @icmp_and_or_lshr_samesign(i32 %x, i32 %y) {
; CHECK-LABEL: @icmp_and_or_lshr_samesign(
; CHECK-NEXT: [[SHF1:%.*]] = shl nuw i32 1, [[Y:%.*]]
; CHECK-NEXT: [[OR2:%.*]] = or i32 [[SHF1]], 1
; CHECK-NEXT: [[AND3:%.*]] = and i32 [[X:%.*]], [[OR2]]
; CHECK-NEXT: [[RET:%.*]] = icmp ne i32 [[AND3]], 0
; CHECK-NEXT: ret i1 [[RET]]
;
%shf = lshr i32 %x, %y
%or = or i32 %shf, %x
%and = and i32 %or, 1
%ret = icmp samesign ne i32 %and, 0
ret i1 %ret
}

define <2 x i1> @icmp_and_or_lshr_vec(<2 x i32> %x, <2 x i32> %y) {
; CHECK-LABEL: @icmp_and_or_lshr_vec(
; CHECK-NEXT: [[SHF:%.*]] = lshr <2 x i32> [[X:%.*]], [[Y:%.*]]
Expand Down
Loading