Skip to content

Commit 29aa3cc

Browse files
committed
Addressed review comments
1 parent cdc9f51 commit 29aa3cc

File tree

2 files changed

+80
-1
lines changed

2 files changed

+80
-1
lines changed

llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4633,7 +4633,6 @@ Instruction *InstCombinerImpl::foldICmpBinOp(ICmpInst &I,
46334633
bool Op0HasNSW = false, Op1HasNSW = false;
46344634
// Analyze the case when either Op0 or Op1 is an add instruction.
46354635
// Op0 = A + B (or A and B are null); Op1 = C + D (or C and D are null).
4636-
Value *A = nullptr, *B = nullptr, *C = nullptr, *D = nullptr;
46374636
auto hasNoWrapProblem = [](const BinaryOperator &BO, CmpInst::Predicate Pred,
46384637
bool &HasNSW, bool &HasNUW) -> bool {
46394638
if (isa<OverflowingBinaryOperator>(BO)) {
@@ -4650,6 +4649,7 @@ Instruction *InstCombinerImpl::foldICmpBinOp(ICmpInst &I,
46504649
return false;
46514650
}
46524651
};
4652+
Value *A = nullptr, *B = nullptr, *C = nullptr, *D = nullptr;
46534653

46544654
if (BO0) {
46554655
match(BO0, m_AddLike(m_Value(A), m_Value(B)));
@@ -4660,6 +4660,8 @@ Instruction *InstCombinerImpl::foldICmpBinOp(ICmpInst &I,
46604660
NoOp1WrapProblem = hasNoWrapProblem(*BO1, Pred, Op1HasNSW, Op1HasNUW);
46614661
}
46624662

4663+
// icmp (A+B), A -> icmp B, 0 for equalities or if there is no overflow.
4664+
// icmp (A+B), B -> icmp A, 0 for equalities or if there is no overflow.
46634665
if ((A == Op1 || B == Op1) && NoOp0WrapProblem)
46644666
return new ICmpInst(Pred, A == Op1 ? B : A,
46654667
Constant::getNullValue(Op1->getType()));

llvm/test/Transforms/InstCombine/icmp.ll

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5005,3 +5005,80 @@ define i1 @or_positive_sgt_zero_multi_use(i8 %a) {
50055005
%cmp = icmp sgt i8 %b, 0
50065006
ret i1 %cmp
50075007
}
5008+
5009+
5010+
define i1 @disjoint_or_sgt_1(i8 %a, i8 %b) {
5011+
; CHECK-LABEL: @disjoint_or_sgt_1(
5012+
; CHECK-NEXT: [[B1:%.*]] = add nsw i8 [[B:%.*]], 2
5013+
; CHECK-NEXT: [[ICMP_:%.*]] = icmp sle i8 [[B1]], [[A:%.*]]
5014+
; CHECK-NEXT: ret i1 [[ICMP_]]
5015+
;
5016+
%a1 = or disjoint i8 %a, 1
5017+
%b1 = add nsw i8 %b, 2
5018+
%icmp_ = icmp sgt i8 %a1, %b1
5019+
ret i1 %icmp_
5020+
}
5021+
5022+
define i1 @disjoint_or_sgt_2(i8 %a, i8 %b) {
5023+
; CHECK-LABEL: @disjoint_or_sgt_2(
5024+
; CHECK-NEXT: [[A1:%.*]] = or disjoint i8 [[A:%.*]], 2
5025+
; CHECK-NEXT: [[B1:%.*]] = add i8 [[B:%.*]], 1
5026+
; CHECK-NEXT: [[ICMP_:%.*]] = icmp sgt i8 [[A1]], [[B1]]
5027+
; CHECK-NEXT: ret i1 [[ICMP_]]
5028+
;
5029+
%a1 = or disjoint i8 %a, 2
5030+
%b1 = add i8 %b, 1
5031+
%icmp_ = icmp sgt i8 %a1, %b1
5032+
ret i1 %icmp_
5033+
}
5034+
5035+
define i1 @disjoint_or_sgt_3(i8 %a, i8 %b) {
5036+
; CHECK-LABEL: @disjoint_or_sgt_3(
5037+
; CHECK-NEXT: [[A1:%.*]] = or disjoint i8 [[A:%.*]], 2
5038+
; CHECK-NEXT: [[B1:%.*]] = add nuw i8 [[B:%.*]], 1
5039+
; CHECK-NEXT: [[ICMP_:%.*]] = icmp sgt i8 [[A1]], [[B1]]
5040+
; CHECK-NEXT: ret i1 [[ICMP_]]
5041+
;
5042+
%a1 = or disjoint i8 %a, 2
5043+
%b1 = add nuw i8 %b, 1
5044+
%icmp_ = icmp sgt i8 %a1, %b1
5045+
ret i1 %icmp_
5046+
}
5047+
5048+
define i1 @disjoint_or_ugt_1(i8 %a, i8 %b) {
5049+
; CHECK-LABEL: @disjoint_or_ugt_1(
5050+
; CHECK-NEXT: [[B1:%.*]] = add nsw i8 [[B:%.*]], 2
5051+
; CHECK-NEXT: [[ICMP_:%.*]] = icmp ule i8 [[B1]], [[A:%.*]]
5052+
; CHECK-NEXT: ret i1 [[ICMP_]]
5053+
;
5054+
%a1 = or disjoint i8 %a, 1
5055+
%b1 = add nsw i8 %b, 2
5056+
%icmp_ = icmp ugt i8 %a1, %b1
5057+
ret i1 %icmp_
5058+
}
5059+
5060+
define i1 @disjoint_or_ugt_2(i8 %a, i8 %b) {
5061+
; CHECK-LABEL: @disjoint_or_ugt_2(
5062+
; CHECK-NEXT: [[A1:%.*]] = or disjoint i8 [[A:%.*]], 2
5063+
; CHECK-NEXT: [[B1:%.*]] = add i8 [[B:%.*]], 1
5064+
; CHECK-NEXT: [[ICMP_:%.*]] = icmp ugt i8 [[A1]], [[B1]]
5065+
; CHECK-NEXT: ret i1 [[ICMP_]]
5066+
;
5067+
%a1 = or disjoint i8 %a, 2
5068+
%b1 = add i8 %b, 1
5069+
%icmp_ = icmp ugt i8 %a1, %b1
5070+
ret i1 %icmp_
5071+
}
5072+
5073+
define i1 @disjoint_or_ugt_3(i8 %a, i8 %b) {
5074+
; CHECK-LABEL: @disjoint_or_ugt_3(
5075+
; CHECK-NEXT: [[A1:%.*]] = or disjoint i8 [[A:%.*]], 2
5076+
; CHECK-NEXT: [[B1:%.*]] = add nuw i8 [[B:%.*]], 1
5077+
; CHECK-NEXT: [[ICMP_:%.*]] = icmp ugt i8 [[A1]], [[B1]]
5078+
; CHECK-NEXT: ret i1 [[ICMP_]]
5079+
;
5080+
%a1 = or disjoint i8 %a, 2
5081+
%b1 = add nuw i8 %b, 1
5082+
%icmp_ = icmp ugt i8 %a1, %b1
5083+
ret i1 %icmp_
5084+
}

0 commit comments

Comments
 (0)