Skip to content

Commit 62e9f40

Browse files
authored
[PatternMatch] Use m_SpecificCmp matchers. NFC. (#100878)
Compile-time improvement: http://llvm-compile-time-tracker.com/compare.php?from=13996378d81c8fa9a364aeaafd7382abbc1db83a&to=861ffa4ec5f7bde5a194a7715593a1b5359eb581&stat=instructions:u baseline: 803eaf2 ``` Top 5 improvements: stockfish/movegen.ll 2541620819 2538599412 -0.12% minetest/profiler.cpp.ll 431724935 431246500 -0.11% abc/luckySwap.c.ll 581173720 580581935 -0.10% abc/kitTruth.c.ll 2521936288 2519445570 -0.10% abc/extraUtilTruth.c.ll 1216674614 1215495502 -0.10% Top 5 regressions: openssl/libcrypto-shlib-sm4.ll 1155054721 1155943201 +0.08% openssl/libcrypto-lib-sm4.ll 1155054838 1155943063 +0.08% spike/vsm4r_vv.ll 1296430080 1297039258 +0.05% spike/vsm4r_vs.ll 1312496906 1313093460 +0.05% nuttx/lib_rand48.c.ll 126201233 126246692 +0.04% Overall: -0.02112308% ```
1 parent 378fe2f commit 62e9f40

17 files changed

+131
-115
lines changed

llvm/include/llvm/IR/PatternMatch.h

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1616,7 +1616,8 @@ m_FCmp(const LHS &L, const RHS &R) {
16161616

16171617
// Same as CmpClass, but instead of saving Pred as out output variable, match a
16181618
// specific input pred for equality.
1619-
template <typename LHS_t, typename RHS_t, typename Class, typename PredicateTy>
1619+
template <typename LHS_t, typename RHS_t, typename Class, typename PredicateTy,
1620+
bool Commutable = false>
16201621
struct SpecificCmpClass_match {
16211622
const PredicateTy Predicate;
16221623
LHS_t L;
@@ -1626,9 +1627,17 @@ struct SpecificCmpClass_match {
16261627
: Predicate(Pred), L(LHS), R(RHS) {}
16271628

16281629
template <typename OpTy> bool match(OpTy *V) {
1629-
if (auto *I = dyn_cast<Class>(V))
1630-
return I->getPredicate() == Predicate && L.match(I->getOperand(0)) &&
1631-
R.match(I->getOperand(1));
1630+
if (auto *I = dyn_cast<Class>(V)) {
1631+
if (I->getPredicate() == Predicate && L.match(I->getOperand(0)) &&
1632+
R.match(I->getOperand(1)))
1633+
return true;
1634+
if constexpr (Commutable) {
1635+
if (I->getPredicate() == Class::getSwappedPredicate(Predicate) &&
1636+
L.match(I->getOperand(1)) && R.match(I->getOperand(0)))
1637+
return true;
1638+
}
1639+
}
1640+
16321641
return false;
16331642
}
16341643
};
@@ -1647,6 +1656,13 @@ m_SpecificICmp(ICmpInst::Predicate MatchPred, const LHS &L, const RHS &R) {
16471656
MatchPred, L, R);
16481657
}
16491658

1659+
template <typename LHS, typename RHS>
1660+
inline SpecificCmpClass_match<LHS, RHS, ICmpInst, ICmpInst::Predicate, true>
1661+
m_c_SpecificICmp(ICmpInst::Predicate MatchPred, const LHS &L, const RHS &R) {
1662+
return SpecificCmpClass_match<LHS, RHS, ICmpInst, ICmpInst::Predicate, true>(
1663+
MatchPred, L, R);
1664+
}
1665+
16501666
template <typename LHS, typename RHS>
16511667
inline SpecificCmpClass_match<LHS, RHS, FCmpInst, FCmpInst::Predicate>
16521668
m_SpecificFCmp(FCmpInst::Predicate MatchPred, const LHS &L, const RHS &R) {

llvm/lib/Analysis/InstructionSimplify.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ static Value *foldSelectWithBinaryOp(Value *Cond, Value *TrueVal,
8888
else
8989
return nullptr;
9090

91-
CmpInst::Predicate ExpectedPred, Pred1, Pred2;
91+
CmpInst::Predicate ExpectedPred;
9292
if (BinOpCode == BinaryOperator::Or) {
9393
ExpectedPred = ICmpInst::ICMP_NE;
9494
} else if (BinOpCode == BinaryOperator::And) {
@@ -110,10 +110,10 @@ static Value *foldSelectWithBinaryOp(Value *Cond, Value *TrueVal,
110110
// -->
111111
// %TV
112112
Value *X, *Y;
113-
if (!match(Cond, m_c_BinOp(m_c_ICmp(Pred1, m_Specific(TrueVal),
114-
m_Specific(FalseVal)),
115-
m_ICmp(Pred2, m_Value(X), m_Value(Y)))) ||
116-
Pred1 != Pred2 || Pred1 != ExpectedPred)
113+
if (!match(Cond,
114+
m_c_BinOp(m_c_SpecificICmp(ExpectedPred, m_Specific(TrueVal),
115+
m_Specific(FalseVal)),
116+
m_SpecificICmp(ExpectedPred, m_Value(X), m_Value(Y)))))
117117
return nullptr;
118118

119119
if (X == TrueVal || X == FalseVal || Y == TrueVal || Y == FalseVal)

llvm/lib/Analysis/ValueTracking.cpp

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -254,8 +254,7 @@ bool llvm::haveNoCommonBitsSet(const WithCache<const Value *> &LHSCache,
254254

255255
bool llvm::isOnlyUsedInZeroComparison(const Instruction *I) {
256256
return !I->user_empty() && all_of(I->users(), [](const User *U) {
257-
ICmpInst::Predicate P;
258-
return match(U, m_ICmp(P, m_Value(), m_Zero()));
257+
return match(U, m_ICmp(m_Value(), m_Zero()));
259258
});
260259
}
261260

@@ -2594,10 +2593,10 @@ static bool isNonZeroRecurrence(const PHINode *PN) {
25942593
}
25952594

25962595
static bool matchOpWithOpEqZero(Value *Op0, Value *Op1) {
2597-
ICmpInst::Predicate Pred;
2598-
return (match(Op0, m_ZExtOrSExt(m_ICmp(Pred, m_Specific(Op1), m_Zero()))) ||
2599-
match(Op1, m_ZExtOrSExt(m_ICmp(Pred, m_Specific(Op0), m_Zero())))) &&
2600-
Pred == ICmpInst::ICMP_EQ;
2596+
return match(Op0, m_ZExtOrSExt(m_SpecificICmp(ICmpInst::ICMP_EQ,
2597+
m_Specific(Op1), m_Zero()))) ||
2598+
match(Op1, m_ZExtOrSExt(m_SpecificICmp(ICmpInst::ICMP_EQ,
2599+
m_Specific(Op0), m_Zero())));
26012600
}
26022601

26032602
static bool isNonZeroAdd(const APInt &DemandedElts, unsigned Depth,

llvm/lib/Target/AMDGPU/AMDGPULowerKernelAttributes.cpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -225,10 +225,8 @@ static bool processUse(CallInst *CI, bool IsV5OrAbove) {
225225
: m_Intrinsic<Intrinsic::amdgcn_workgroup_id_z>());
226226

227227
for (User *ICmp : BlockCount->users()) {
228-
ICmpInst::Predicate Pred;
229-
if (match(ICmp, m_ICmp(Pred, GroupIDIntrin, m_Specific(BlockCount)))) {
230-
if (Pred != ICmpInst::ICMP_ULT)
231-
continue;
228+
if (match(ICmp, m_SpecificICmp(ICmpInst::ICMP_ULT, GroupIDIntrin,
229+
m_Specific(BlockCount)))) {
232230
ICmp->replaceAllUsesWith(llvm::ConstantInt::getTrue(ICmp->getType()));
233231
MadeChange = true;
234232
}

llvm/lib/Target/X86/X86ISelLowering.cpp

Lines changed: 23 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -3435,12 +3435,9 @@ X86TargetLowering::getJumpConditionMergingParams(Instruction::BinaryOps Opc,
34353435
if (BaseCost >= 0 && Subtarget.hasCCMP())
34363436
BaseCost += BrMergingCcmpBias;
34373437
// a == b && a == c is a fast pattern on x86.
3438-
ICmpInst::Predicate Pred;
34393438
if (BaseCost >= 0 && Opc == Instruction::And &&
3440-
match(Lhs, m_ICmp(Pred, m_Value(), m_Value())) &&
3441-
Pred == ICmpInst::ICMP_EQ &&
3442-
match(Rhs, m_ICmp(Pred, m_Value(), m_Value())) &&
3443-
Pred == ICmpInst::ICMP_EQ)
3439+
match(Lhs, m_SpecificICmp(ICmpInst::ICMP_EQ, m_Value(), m_Value())) &&
3440+
match(Rhs, m_SpecificICmp(ICmpInst::ICMP_EQ, m_Value(), m_Value())))
34443441
BaseCost += 1;
34453442
return {BaseCost, BrMergingLikelyBias.getValue(),
34463443
BrMergingUnlikelyBias.getValue()};
@@ -30760,21 +30757,25 @@ static bool shouldExpandCmpArithRMWInIR(AtomicRMWInst *AI) {
3076030757
if (match(I, m_c_ICmp(Pred, m_Sub(m_ZeroInt(), m_Specific(Op)), m_Value())))
3076130758
return Pred == CmpInst::ICMP_EQ || Pred == CmpInst::ICMP_NE;
3076230759
if (match(I, m_OneUse(m_c_Add(m_Specific(Op), m_Value())))) {
30763-
if (match(I->user_back(), m_ICmp(Pred, m_Value(), m_ZeroInt())))
30764-
return Pred == CmpInst::ICMP_SLT;
30765-
if (match(I->user_back(), m_ICmp(Pred, m_Value(), m_AllOnes())))
30766-
return Pred == CmpInst::ICMP_SGT;
30760+
if (match(I->user_back(),
30761+
m_SpecificICmp(CmpInst::ICMP_SLT, m_Value(), m_ZeroInt())))
30762+
return true;
30763+
if (match(I->user_back(),
30764+
m_SpecificICmp(CmpInst::ICMP_SGT, m_Value(), m_AllOnes())))
30765+
return true;
3076730766
}
3076830767
return false;
3076930768
}
3077030769
if (Opc == AtomicRMWInst::Sub) {
3077130770
if (match(I, m_c_ICmp(Pred, m_Specific(Op), m_Value())))
3077230771
return Pred == CmpInst::ICMP_EQ || Pred == CmpInst::ICMP_NE;
3077330772
if (match(I, m_OneUse(m_Sub(m_Value(), m_Specific(Op))))) {
30774-
if (match(I->user_back(), m_ICmp(Pred, m_Value(), m_ZeroInt())))
30775-
return Pred == CmpInst::ICMP_SLT;
30776-
if (match(I->user_back(), m_ICmp(Pred, m_Value(), m_AllOnes())))
30777-
return Pred == CmpInst::ICMP_SGT;
30773+
if (match(I->user_back(),
30774+
m_SpecificICmp(CmpInst::ICMP_SLT, m_Value(), m_ZeroInt())))
30775+
return true;
30776+
if (match(I->user_back(),
30777+
m_SpecificICmp(CmpInst::ICMP_SGT, m_Value(), m_AllOnes())))
30778+
return true;
3077830779
}
3077930780
return false;
3078030781
}
@@ -30785,18 +30786,21 @@ static bool shouldExpandCmpArithRMWInIR(AtomicRMWInst *AI) {
3078530786
if (match(I->user_back(), m_ICmp(Pred, m_Value(), m_ZeroInt())))
3078630787
return Pred == CmpInst::ICMP_EQ || Pred == CmpInst::ICMP_NE ||
3078730788
Pred == CmpInst::ICMP_SLT;
30788-
if (match(I->user_back(), m_ICmp(Pred, m_Value(), m_AllOnes())))
30789-
return Pred == CmpInst::ICMP_SGT;
30789+
if (match(I->user_back(),
30790+
m_SpecificICmp(CmpInst::ICMP_SGT, m_Value(), m_AllOnes())))
30791+
return true;
3079030792
return false;
3079130793
}
3079230794
if (Opc == AtomicRMWInst::Xor) {
3079330795
if (match(I, m_c_ICmp(Pred, m_Specific(Op), m_Value())))
3079430796
return Pred == CmpInst::ICMP_EQ || Pred == CmpInst::ICMP_NE;
3079530797
if (match(I, m_OneUse(m_c_Xor(m_Specific(Op), m_Value())))) {
30796-
if (match(I->user_back(), m_ICmp(Pred, m_Value(), m_ZeroInt())))
30797-
return Pred == CmpInst::ICMP_SLT;
30798-
if (match(I->user_back(), m_ICmp(Pred, m_Value(), m_AllOnes())))
30799-
return Pred == CmpInst::ICMP_SGT;
30798+
if (match(I->user_back(),
30799+
m_SpecificICmp(CmpInst::ICMP_SLT, m_Value(), m_ZeroInt())))
30800+
return true;
30801+
if (match(I->user_back(),
30802+
m_SpecificICmp(CmpInst::ICMP_SGT, m_Value(), m_AllOnes())))
30803+
return true;
3080030804
}
3080130805
return false;
3080230806
}

llvm/lib/Transforms/AggressiveInstCombine/AggressiveInstCombine.cpp

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -135,15 +135,12 @@ static bool foldGuardedFunnelShift(Instruction &I, const DominatorTree &DT) {
135135
if (!DT.dominates(ShVal0, TermI) || !DT.dominates(ShVal1, TermI))
136136
return false;
137137

138-
ICmpInst::Predicate Pred;
139138
BasicBlock *PhiBB = Phi.getParent();
140-
if (!match(TermI, m_Br(m_ICmp(Pred, m_Specific(ShAmt), m_ZeroInt()),
139+
if (!match(TermI, m_Br(m_SpecificICmp(CmpInst::ICMP_EQ, m_Specific(ShAmt),
140+
m_ZeroInt()),
141141
m_SpecificBB(PhiBB), m_SpecificBB(FunnelBB))))
142142
return false;
143143

144-
if (Pred != CmpInst::ICMP_EQ)
145-
return false;
146-
147144
IRBuilder<> Builder(PhiBB, PhiBB->getFirstInsertionPt());
148145

149146
if (ShVal0 == ShVal1)

llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1694,12 +1694,10 @@ Instruction *InstCombinerImpl::visitAdd(BinaryOperator &I) {
16941694

16951695
// Canonicalize signum variant that ends in add:
16961696
// (A s>> (BW - 1)) + (zext (A s> 0)) --> (A s>> (BW - 1)) | (zext (A != 0))
1697-
ICmpInst::Predicate Pred;
16981697
uint64_t BitWidth = Ty->getScalarSizeInBits();
16991698
if (match(LHS, m_AShr(m_Value(A), m_SpecificIntAllowPoison(BitWidth - 1))) &&
1700-
match(RHS, m_OneUse(m_ZExt(
1701-
m_OneUse(m_ICmp(Pred, m_Specific(A), m_ZeroInt()))))) &&
1702-
Pred == CmpInst::ICMP_SGT) {
1699+
match(RHS, m_OneUse(m_ZExt(m_OneUse(m_SpecificICmp(
1700+
CmpInst::ICMP_SGT, m_Specific(A), m_ZeroInt())))))) {
17031701
Value *NotZero = Builder.CreateIsNotNull(A, "isnotnull");
17041702
Value *Zext = Builder.CreateZExt(NotZero, Ty, "isnotnull.zext");
17051703
return BinaryOperator::CreateOr(LHS, Zext);
@@ -1711,12 +1709,13 @@ Instruction *InstCombinerImpl::visitAdd(BinaryOperator &I) {
17111709
// (add X, (sext/zext (icmp eq X, C)))
17121710
// -> (select (icmp eq X, C), (add C, (sext/zext 1)), X)
17131711
auto CondMatcher = m_CombineAnd(
1714-
m_Value(Cond), m_ICmp(Pred, m_Deferred(A), m_ImmConstant(C)));
1712+
m_Value(Cond),
1713+
m_SpecificICmp(ICmpInst::ICMP_EQ, m_Deferred(A), m_ImmConstant(C)));
17151714

17161715
if (match(&I,
17171716
m_c_Add(m_Value(A),
17181717
m_CombineAnd(m_Value(Ext), m_ZExtOrSExt(CondMatcher)))) &&
1719-
Pred == ICmpInst::ICMP_EQ && Ext->hasOneUse()) {
1718+
Ext->hasOneUse()) {
17201719
Value *Add = isa<ZExtInst>(Ext) ? InstCombiner::AddOne(C)
17211720
: InstCombiner::SubOne(C);
17221721
return replaceInstUsesWith(I, Builder.CreateSelect(Cond, Add, A));
@@ -1791,6 +1790,7 @@ Instruction *InstCombinerImpl::visitAdd(BinaryOperator &I) {
17911790
// -->
17921791
// BW - ctlz(A - 1, false)
17931792
const APInt *XorC;
1793+
ICmpInst::Predicate Pred;
17941794
if (match(&I,
17951795
m_c_Add(
17961796
m_ZExt(m_ICmp(Pred, m_Intrinsic<Intrinsic::ctpop>(m_Value(A)),

llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp

Lines changed: 30 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -818,11 +818,11 @@ static Value *foldSignedTruncationCheck(ICmpInst *ICmp0, ICmpInst *ICmp1,
818818
// Match icmp ult (add %arg, C01), C1 (C1 == C01 << 1; powers of two)
819819
auto tryToMatchSignedTruncationCheck = [](ICmpInst *ICmp, Value *&X,
820820
APInt &SignBitMask) -> bool {
821-
CmpInst::Predicate Pred;
822821
const APInt *I01, *I1; // powers of two; I1 == I01 << 1
823-
if (!(match(ICmp,
824-
m_ICmp(Pred, m_Add(m_Value(X), m_Power2(I01)), m_Power2(I1))) &&
825-
Pred == ICmpInst::ICMP_ULT && I1->ugt(*I01) && I01->shl(1) == *I1))
822+
if (!(match(ICmp, m_SpecificICmp(ICmpInst::ICMP_ULT,
823+
m_Add(m_Value(X), m_Power2(I01)),
824+
m_Power2(I1))) &&
825+
I1->ugt(*I01) && I01->shl(1) == *I1))
826826
return false;
827827
// Which bit is the new sign bit as per the 'signed truncation' pattern?
828828
SignBitMask = *I01;
@@ -936,20 +936,21 @@ static Value *foldIsPowerOf2(ICmpInst *Cmp0, ICmpInst *Cmp1, bool JoinedByAnd,
936936
std::swap(Cmp0, Cmp1);
937937

938938
// (X != 0) && (ctpop(X) u< 2) --> ctpop(X) == 1
939-
CmpInst::Predicate Pred0, Pred1;
940939
Value *X;
941-
if (JoinedByAnd && match(Cmp0, m_ICmp(Pred0, m_Value(X), m_ZeroInt())) &&
942-
match(Cmp1, m_ICmp(Pred1, m_Intrinsic<Intrinsic::ctpop>(m_Specific(X)),
943-
m_SpecificInt(2))) &&
944-
Pred0 == ICmpInst::ICMP_NE && Pred1 == ICmpInst::ICMP_ULT) {
940+
if (JoinedByAnd &&
941+
match(Cmp0, m_SpecificICmp(ICmpInst::ICMP_NE, m_Value(X), m_ZeroInt())) &&
942+
match(Cmp1, m_SpecificICmp(ICmpInst::ICMP_ULT,
943+
m_Intrinsic<Intrinsic::ctpop>(m_Specific(X)),
944+
m_SpecificInt(2)))) {
945945
Value *CtPop = Cmp1->getOperand(0);
946946
return Builder.CreateICmpEQ(CtPop, ConstantInt::get(CtPop->getType(), 1));
947947
}
948948
// (X == 0) || (ctpop(X) u> 1) --> ctpop(X) != 1
949-
if (!JoinedByAnd && match(Cmp0, m_ICmp(Pred0, m_Value(X), m_ZeroInt())) &&
950-
match(Cmp1, m_ICmp(Pred1, m_Intrinsic<Intrinsic::ctpop>(m_Specific(X)),
951-
m_SpecificInt(1))) &&
952-
Pred0 == ICmpInst::ICMP_EQ && Pred1 == ICmpInst::ICMP_UGT) {
949+
if (!JoinedByAnd &&
950+
match(Cmp0, m_SpecificICmp(ICmpInst::ICMP_EQ, m_Value(X), m_ZeroInt())) &&
951+
match(Cmp1, m_SpecificICmp(ICmpInst::ICMP_UGT,
952+
m_Intrinsic<Intrinsic::ctpop>(m_Specific(X)),
953+
m_SpecificInt(1)))) {
953954
Value *CtPop = Cmp1->getOperand(0);
954955
return Builder.CreateICmpNE(CtPop, ConstantInt::get(CtPop->getType(), 1));
955956
}
@@ -1608,31 +1609,30 @@ static Instruction *reassociateFCmps(BinaryOperator &BO,
16081609
// There are 4 commuted variants of the pattern. Canonicalize operands of this
16091610
// logic op so an fcmp is operand 0 and a matching logic op is operand 1.
16101611
Value *Op0 = BO.getOperand(0), *Op1 = BO.getOperand(1), *X;
1611-
FCmpInst::Predicate Pred;
1612-
if (match(Op1, m_FCmp(Pred, m_Value(), m_AnyZeroFP())))
1612+
if (match(Op1, m_FCmp(m_Value(), m_AnyZeroFP())))
16131613
std::swap(Op0, Op1);
16141614

16151615
// Match inner binop and the predicate for combining 2 NAN checks into 1.
16161616
Value *BO10, *BO11;
16171617
FCmpInst::Predicate NanPred = Opcode == Instruction::And ? FCmpInst::FCMP_ORD
16181618
: FCmpInst::FCMP_UNO;
1619-
if (!match(Op0, m_FCmp(Pred, m_Value(X), m_AnyZeroFP())) || Pred != NanPred ||
1619+
if (!match(Op0, m_SpecificFCmp(NanPred, m_Value(X), m_AnyZeroFP())) ||
16201620
!match(Op1, m_BinOp(Opcode, m_Value(BO10), m_Value(BO11))))
16211621
return nullptr;
16221622

16231623
// The inner logic op must have a matching fcmp operand.
16241624
Value *Y;
1625-
if (!match(BO10, m_FCmp(Pred, m_Value(Y), m_AnyZeroFP())) ||
1626-
Pred != NanPred || X->getType() != Y->getType())
1625+
if (!match(BO10, m_SpecificFCmp(NanPred, m_Value(Y), m_AnyZeroFP())) ||
1626+
X->getType() != Y->getType())
16271627
std::swap(BO10, BO11);
16281628

1629-
if (!match(BO10, m_FCmp(Pred, m_Value(Y), m_AnyZeroFP())) ||
1630-
Pred != NanPred || X->getType() != Y->getType())
1629+
if (!match(BO10, m_SpecificFCmp(NanPred, m_Value(Y), m_AnyZeroFP())) ||
1630+
X->getType() != Y->getType())
16311631
return nullptr;
16321632

16331633
// and (fcmp ord X, 0), (and (fcmp ord Y, 0), Z) --> and (fcmp ord X, Y), Z
16341634
// or (fcmp uno X, 0), (or (fcmp uno Y, 0), Z) --> or (fcmp uno X, Y), Z
1635-
Value *NewFCmp = Builder.CreateFCmp(Pred, X, Y);
1635+
Value *NewFCmp = Builder.CreateFCmp(NanPred, X, Y);
16361636
if (auto *NewFCmpInst = dyn_cast<FCmpInst>(NewFCmp)) {
16371637
// Intersect FMF from the 2 source fcmps.
16381638
NewFCmpInst->copyIRFlags(Op0);
@@ -1744,14 +1744,13 @@ Instruction *InstCombinerImpl::foldCastedBitwiseLogic(BinaryOperator &I) {
17441744
// -> zext(bitwise(A < 0, icmp))
17451745
auto FoldBitwiseICmpZeroWithICmp = [&](Value *Op0,
17461746
Value *Op1) -> Instruction * {
1747-
ICmpInst::Predicate Pred;
17481747
Value *A;
17491748
bool IsMatched =
17501749
match(Op0,
17511750
m_OneUse(m_LShr(
17521751
m_Value(A),
17531752
m_SpecificInt(Op0->getType()->getScalarSizeInBits() - 1)))) &&
1754-
match(Op1, m_OneUse(m_ZExt(m_ICmp(Pred, m_Value(), m_Value()))));
1753+
match(Op1, m_OneUse(m_ZExt(m_ICmp(m_Value(), m_Value()))));
17551754

17561755
if (!IsMatched)
17571756
return nullptr;
@@ -3878,14 +3877,14 @@ Instruction *InstCombinerImpl::visitOr(BinaryOperator &I) {
38783877
if (match(&I,
38793878
m_c_Or(m_CombineAnd(m_ExtractValue<1>(m_Value(UMulWithOv)),
38803879
m_Value(Ov)),
3881-
m_CombineAnd(m_ICmp(Pred,
3882-
m_CombineAnd(m_ExtractValue<0>(
3883-
m_Deferred(UMulWithOv)),
3884-
m_Value(Mul)),
3885-
m_ZeroInt()),
3886-
m_Value(MulIsNotZero)))) &&
3887-
(Ov->hasOneUse() || (MulIsNotZero->hasOneUse() && Mul->hasOneUse())) &&
3888-
Pred == CmpInst::ICMP_NE) {
3880+
m_CombineAnd(
3881+
m_SpecificICmp(ICmpInst::ICMP_NE,
3882+
m_CombineAnd(m_ExtractValue<0>(
3883+
m_Deferred(UMulWithOv)),
3884+
m_Value(Mul)),
3885+
m_ZeroInt()),
3886+
m_Value(MulIsNotZero)))) &&
3887+
(Ov->hasOneUse() || (MulIsNotZero->hasOneUse() && Mul->hasOneUse()))) {
38893888
Value *A, *B;
38903889
if (match(UMulWithOv, m_Intrinsic<Intrinsic::umul_with_overflow>(
38913890
m_Value(A), m_Value(B)))) {

0 commit comments

Comments
 (0)