Skip to content
Draft
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 @@ -5435,7 +5435,6 @@ Instruction *InstCombinerImpl::foldICmpBinOp(ICmpInst &I,
}

if (BO0 && BO1 && BO0->getOpcode() == BO1->getOpcode() &&
(BO0->hasOneUse() || BO1->hasOneUse()) &&
BO0->getOperand(1) == BO1->getOperand(1)) {
switch (BO0->getOpcode()) {
default:
Expand Down Expand Up @@ -5468,7 +5467,8 @@ Instruction *InstCombinerImpl::foldICmpBinOp(ICmpInst &I,
break;

const APInt *C;
if (match(BO0->getOperand(1), m_APInt(C)) && !C->isZero() &&
if (BO0->hasOneUse() && BO1->hasOneUse() &&
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should it be ||?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No. We create two and instructions and one icmp here. See the test eq_mul_constants_with_tz_extra_use1.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah fair enough, just this case is not relaxing the constraint, its tightening it.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes. I already pointed out this in the PR description.

match(BO0->getOperand(1), m_APInt(C)) && !C->isZero() &&
!C->isOne()) {
// icmp eq/ne (X * C), (Y * C) --> icmp (X & Mask), (Y & Mask)
// Mask = -1 >> count-trailing-zeros(C).
Expand Down
33 changes: 33 additions & 0 deletions llvm/test/Transforms/InstCombine/icmp-mul.ll
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

declare void @llvm.assume(i1)
declare void @use(i8)
declare void @use32(i32)
declare void @usev2xi8(<2 x i8>)


Expand Down Expand Up @@ -780,6 +781,38 @@ define i1 @eq_mul_constants_with_tz(i32 %x, i32 %y) {
ret i1 %C
}

define i1 @eq_mul_constants_with_tz_extra_use1(i32 %x, i32 %y) {
; CHECK-LABEL: @eq_mul_constants_with_tz_extra_use1(
; CHECK-NEXT: [[A:%.*]] = mul i32 [[X:%.*]], 12
; CHECK-NEXT: call void @use32(i32 [[A]])
; CHECK-NEXT: [[B:%.*]] = mul i32 [[Y:%.*]], 12
; CHECK-NEXT: [[C:%.*]] = icmp ne i32 [[A]], [[B]]
; CHECK-NEXT: ret i1 [[C]]
;
%A = mul i32 %x, 12
call void @use32(i32 %A)
%B = mul i32 %y, 12
%C = icmp ne i32 %A, %B
ret i1 %C
}

define i1 @eq_mul_constants_with_tz_extra_use2(i32 %x, i32 %y) {
; CHECK-LABEL: @eq_mul_constants_with_tz_extra_use2(
; CHECK-NEXT: [[A:%.*]] = mul i32 [[X:%.*]], 12
; CHECK-NEXT: call void @use32(i32 [[A]])
; CHECK-NEXT: [[B:%.*]] = mul i32 [[Y:%.*]], 12
; CHECK-NEXT: call void @use32(i32 [[B]])
; CHECK-NEXT: [[C:%.*]] = icmp ne i32 [[A]], [[B]]
; CHECK-NEXT: ret i1 [[C]]
;
%A = mul i32 %x, 12
call void @use32(i32 %A)
%B = mul i32 %y, 12
call void @use32(i32 %B)
%C = icmp ne i32 %A, %B
ret i1 %C
}

define <2 x i1> @eq_mul_constants_with_tz_splat(<2 x i32> %x, <2 x i32> %y) {
; CHECK-LABEL: @eq_mul_constants_with_tz_splat(
; CHECK-NEXT: [[TMP1:%.*]] = xor <2 x i32> [[X:%.*]], [[Y:%.*]]
Expand Down
2 changes: 1 addition & 1 deletion llvm/test/Transforms/InstCombine/icmp.ll
Original file line number Diff line number Diff line change
Expand Up @@ -849,7 +849,7 @@ define i1 @test46_multiuse3(i32 %X, i32 %Y, i32 %Z) {
; CHECK-NEXT: call void @use_i32(i32 [[A]])
; CHECK-NEXT: [[B:%.*]] = ashr exact i32 [[Y:%.*]], [[Z]]
; CHECK-NEXT: call void @use_i32(i32 [[B]])
; CHECK-NEXT: [[C:%.*]] = icmp ult i32 [[A]], [[B]]
; CHECK-NEXT: [[C:%.*]] = icmp ult i32 [[X]], [[Y]]
; CHECK-NEXT: ret i1 [[C]]
;
%A = ashr exact i32 %X, %Z
Expand Down
Loading