Skip to content

Commit 7f79822

Browse files
committed
Update InstCombineAddSub.cpp
1 parent 5b11d5d commit 7f79822

File tree

1 file changed

+8
-10
lines changed

1 file changed

+8
-10
lines changed

llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1691,26 +1691,24 @@ Instruction *InstCombinerImpl::visitAdd(BinaryOperator &I) {
16911691

16921692
// Handle constant case: sext(x > C1) + zext(x < C2) where C2 = C1 + 1
16931693
// This represents (x >= C1+1) - (x <= C1+1) => scmp/ucmp(x, C1+1)
1694-
Value *X, *Const1, *Const2;
1694+
Value *X;
1695+
ConstantInt *Const1, *Const2;
16951696
CmpPredicate Pred1, Pred2;
16961697
if (match(&I,
1697-
m_c_Add(m_SExt(m_c_ICmp(Pred1, m_Value(X), m_Value(Const1))),
1698-
m_ZExt(m_c_ICmp(Pred2, m_Deferred(X), m_Value(Const2))))) &&
1699-
X->getType()->isIntOrIntVectorTy() && isa<ConstantInt>(Const1) &&
1700-
isa<ConstantInt>(Const2)) {
1698+
m_c_Add(
1699+
m_SExt(m_ICmp(Pred1, m_Value(X), m_ConstantInt(Const1))),
1700+
m_ZExt(m_ICmp(Pred2, m_Deferred(X), m_ConstantInt(Const2))))) &&
1701+
X->getType()->isIntOrIntVectorTy()) {
17011702

17021703
// Check if we have x > C1 and x < C2 where C2 = C1 + 2
17031704
if (ICmpInst::isGT(Pred1) && ICmpInst::isLT(Pred2)) {
1704-
ConstantInt *ConstC1 = cast<ConstantInt>(Const1);
1705-
ConstantInt *ConstC2 = cast<ConstantInt>(Const2);
1706-
17071705
// Check if C2 = C1 + 2
1708-
if (ConstC2->getValue() == ConstC1->getValue() + 2) {
1706+
if (Const2->getValue() == Const1->getValue() + 2) {
17091707
// This represents (x >= C1+1) - (x <= C1+1) => scmp/ucmp(x, C1+1)
17101708
Intrinsic::ID IID =
17111709
ICmpInst::isSigned(Pred1) ? Intrinsic::scmp : Intrinsic::ucmp;
17121710
Constant *C1Plus1 =
1713-
ConstantInt::get(Const1->getType(), ConstC1->getValue() + 1);
1711+
ConstantInt::get(Const1->getType(), Const1->getValue() + 1);
17141712
return replaceInstUsesWith(
17151713
I, Builder.CreateIntrinsic(Ty, IID, {X, C1Plus1}));
17161714
}

0 commit comments

Comments
 (0)