-
Notifications
You must be signed in to change notification settings - Fork 14.5k
[PatternMatch] Use m_SpecificCmp
matchers. NFC.
#100878
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
@llvm/pr-subscribers-llvm-ir @llvm/pr-subscribers-backend-amdgpu Author: Yingwei Zheng (dtcxzyw) ChangesCompile-time improvement: http://llvm-compile-time-tracker.com/compare.php?from=13996378d81c8fa9a364aeaafd7382abbc1db83a&to=861ffa4ec5f7bde5a194a7715593a1b5359eb581&stat=instructions:u
Patch is 26.20 KiB, truncated to 20.00 KiB below, full version: https://github.com/llvm/llvm-project/pull/100878.diff 15 Files Affected:
diff --git a/llvm/lib/Analysis/InstructionSimplify.cpp b/llvm/lib/Analysis/InstructionSimplify.cpp
index 3a7ae577bb068..abf0735aa2c99 100644
--- a/llvm/lib/Analysis/InstructionSimplify.cpp
+++ b/llvm/lib/Analysis/InstructionSimplify.cpp
@@ -110,10 +110,11 @@ static Value *foldSelectWithBinaryOp(Value *Cond, Value *TrueVal,
// -->
// %TV
Value *X, *Y;
- if (!match(Cond, m_c_BinOp(m_c_ICmp(Pred1, m_Specific(TrueVal),
- m_Specific(FalseVal)),
- m_ICmp(Pred2, m_Value(X), m_Value(Y)))) ||
- Pred1 != Pred2 || Pred1 != ExpectedPred)
+ if (!match(
+ Cond,
+ m_c_BinOp(m_c_ICmp(Pred1, m_Specific(TrueVal), m_Specific(FalseVal)),
+ m_SpecificICmp(ExpectedPred, m_Value(X), m_Value(Y)))) ||
+ Pred1 != ExpectedPred)
return nullptr;
if (X == TrueVal || X == FalseVal || Y == TrueVal || Y == FalseVal)
diff --git a/llvm/lib/Analysis/ValueTracking.cpp b/llvm/lib/Analysis/ValueTracking.cpp
index bfd26fadd237b..10884f8d32b86 100644
--- a/llvm/lib/Analysis/ValueTracking.cpp
+++ b/llvm/lib/Analysis/ValueTracking.cpp
@@ -254,8 +254,7 @@ bool llvm::haveNoCommonBitsSet(const WithCache<const Value *> &LHSCache,
bool llvm::isOnlyUsedInZeroComparison(const Instruction *I) {
return !I->user_empty() && all_of(I->users(), [](const User *U) {
- ICmpInst::Predicate P;
- return match(U, m_ICmp(P, m_Value(), m_Zero()));
+ return match(U, m_ICmp(m_Value(), m_Zero()));
});
}
@@ -2594,10 +2593,10 @@ static bool isNonZeroRecurrence(const PHINode *PN) {
}
static bool matchOpWithOpEqZero(Value *Op0, Value *Op1) {
- ICmpInst::Predicate Pred;
- return (match(Op0, m_ZExtOrSExt(m_ICmp(Pred, m_Specific(Op1), m_Zero()))) ||
- match(Op1, m_ZExtOrSExt(m_ICmp(Pred, m_Specific(Op0), m_Zero())))) &&
- Pred == ICmpInst::ICMP_EQ;
+ return match(Op0, m_ZExtOrSExt(m_SpecificICmp(ICmpInst::ICMP_EQ,
+ m_Specific(Op1), m_Zero()))) ||
+ match(Op1, m_ZExtOrSExt(m_SpecificICmp(ICmpInst::ICMP_EQ,
+ m_Specific(Op0), m_Zero())));
}
static bool isNonZeroAdd(const APInt &DemandedElts, unsigned Depth,
diff --git a/llvm/lib/Target/AMDGPU/AMDGPULowerKernelAttributes.cpp b/llvm/lib/Target/AMDGPU/AMDGPULowerKernelAttributes.cpp
index e91d05954a1c9..e724c978c44b6 100644
--- a/llvm/lib/Target/AMDGPU/AMDGPULowerKernelAttributes.cpp
+++ b/llvm/lib/Target/AMDGPU/AMDGPULowerKernelAttributes.cpp
@@ -225,10 +225,8 @@ static bool processUse(CallInst *CI, bool IsV5OrAbove) {
: m_Intrinsic<Intrinsic::amdgcn_workgroup_id_z>());
for (User *ICmp : BlockCount->users()) {
- ICmpInst::Predicate Pred;
- if (match(ICmp, m_ICmp(Pred, GroupIDIntrin, m_Specific(BlockCount)))) {
- if (Pred != ICmpInst::ICMP_ULT)
- continue;
+ if (match(ICmp, m_SpecificICmp(ICmpInst::ICMP_ULT, GroupIDIntrin,
+ m_Specific(BlockCount)))) {
ICmp->replaceAllUsesWith(llvm::ConstantInt::getTrue(ICmp->getType()));
MadeChange = true;
}
diff --git a/llvm/lib/Target/X86/X86ISelLowering.cpp b/llvm/lib/Target/X86/X86ISelLowering.cpp
index ad59b13933a6a..b971afda4229a 100644
--- a/llvm/lib/Target/X86/X86ISelLowering.cpp
+++ b/llvm/lib/Target/X86/X86ISelLowering.cpp
@@ -3435,12 +3435,9 @@ X86TargetLowering::getJumpConditionMergingParams(Instruction::BinaryOps Opc,
if (BaseCost >= 0 && Subtarget.hasCCMP())
BaseCost += BrMergingCcmpBias;
// a == b && a == c is a fast pattern on x86.
- ICmpInst::Predicate Pred;
if (BaseCost >= 0 && Opc == Instruction::And &&
- match(Lhs, m_ICmp(Pred, m_Value(), m_Value())) &&
- Pred == ICmpInst::ICMP_EQ &&
- match(Rhs, m_ICmp(Pred, m_Value(), m_Value())) &&
- Pred == ICmpInst::ICMP_EQ)
+ match(Lhs, m_SpecificICmp(ICmpInst::ICMP_EQ, m_Value(), m_Value())) &&
+ match(Rhs, m_SpecificICmp(ICmpInst::ICMP_EQ, m_Value(), m_Value())))
BaseCost += 1;
return {BaseCost, BrMergingLikelyBias.getValue(),
BrMergingUnlikelyBias.getValue()};
@@ -30760,10 +30757,12 @@ static bool shouldExpandCmpArithRMWInIR(AtomicRMWInst *AI) {
if (match(I, m_c_ICmp(Pred, m_Sub(m_ZeroInt(), m_Specific(Op)), m_Value())))
return Pred == CmpInst::ICMP_EQ || Pred == CmpInst::ICMP_NE;
if (match(I, m_OneUse(m_c_Add(m_Specific(Op), m_Value())))) {
- if (match(I->user_back(), m_ICmp(Pred, m_Value(), m_ZeroInt())))
- return Pred == CmpInst::ICMP_SLT;
- if (match(I->user_back(), m_ICmp(Pred, m_Value(), m_AllOnes())))
- return Pred == CmpInst::ICMP_SGT;
+ if (match(I->user_back(),
+ m_SpecificICmp(CmpInst::ICMP_SLT, m_Value(), m_ZeroInt())))
+ return true;
+ if (match(I->user_back(),
+ m_SpecificICmp(CmpInst::ICMP_SGT, m_Value(), m_AllOnes())))
+ return true;
}
return false;
}
@@ -30771,10 +30770,12 @@ static bool shouldExpandCmpArithRMWInIR(AtomicRMWInst *AI) {
if (match(I, m_c_ICmp(Pred, m_Specific(Op), m_Value())))
return Pred == CmpInst::ICMP_EQ || Pred == CmpInst::ICMP_NE;
if (match(I, m_OneUse(m_Sub(m_Value(), m_Specific(Op))))) {
- if (match(I->user_back(), m_ICmp(Pred, m_Value(), m_ZeroInt())))
- return Pred == CmpInst::ICMP_SLT;
- if (match(I->user_back(), m_ICmp(Pred, m_Value(), m_AllOnes())))
- return Pred == CmpInst::ICMP_SGT;
+ if (match(I->user_back(),
+ m_SpecificICmp(CmpInst::ICMP_SLT, m_Value(), m_ZeroInt())))
+ return true;
+ if (match(I->user_back(),
+ m_SpecificICmp(CmpInst::ICMP_SGT, m_Value(), m_AllOnes())))
+ return true;
}
return false;
}
@@ -30785,18 +30786,21 @@ static bool shouldExpandCmpArithRMWInIR(AtomicRMWInst *AI) {
if (match(I->user_back(), m_ICmp(Pred, m_Value(), m_ZeroInt())))
return Pred == CmpInst::ICMP_EQ || Pred == CmpInst::ICMP_NE ||
Pred == CmpInst::ICMP_SLT;
- if (match(I->user_back(), m_ICmp(Pred, m_Value(), m_AllOnes())))
- return Pred == CmpInst::ICMP_SGT;
+ if (match(I->user_back(),
+ m_SpecificICmp(CmpInst::ICMP_SGT, m_Value(), m_AllOnes())))
+ return true;
return false;
}
if (Opc == AtomicRMWInst::Xor) {
if (match(I, m_c_ICmp(Pred, m_Specific(Op), m_Value())))
return Pred == CmpInst::ICMP_EQ || Pred == CmpInst::ICMP_NE;
if (match(I, m_OneUse(m_c_Xor(m_Specific(Op), m_Value())))) {
- if (match(I->user_back(), m_ICmp(Pred, m_Value(), m_ZeroInt())))
- return Pred == CmpInst::ICMP_SLT;
- if (match(I->user_back(), m_ICmp(Pred, m_Value(), m_AllOnes())))
- return Pred == CmpInst::ICMP_SGT;
+ if (match(I->user_back(),
+ m_SpecificICmp(CmpInst::ICMP_SLT, m_Value(), m_ZeroInt())))
+ return true;
+ if (match(I->user_back(),
+ m_SpecificICmp(CmpInst::ICMP_SGT, m_Value(), m_AllOnes())))
+ return true;
}
return false;
}
diff --git a/llvm/lib/Transforms/AggressiveInstCombine/AggressiveInstCombine.cpp b/llvm/lib/Transforms/AggressiveInstCombine/AggressiveInstCombine.cpp
index d5a38ec17a2a8..09ffc2d184f18 100644
--- a/llvm/lib/Transforms/AggressiveInstCombine/AggressiveInstCombine.cpp
+++ b/llvm/lib/Transforms/AggressiveInstCombine/AggressiveInstCombine.cpp
@@ -135,15 +135,12 @@ static bool foldGuardedFunnelShift(Instruction &I, const DominatorTree &DT) {
if (!DT.dominates(ShVal0, TermI) || !DT.dominates(ShVal1, TermI))
return false;
- ICmpInst::Predicate Pred;
BasicBlock *PhiBB = Phi.getParent();
- if (!match(TermI, m_Br(m_ICmp(Pred, m_Specific(ShAmt), m_ZeroInt()),
+ if (!match(TermI, m_Br(m_SpecificICmp(CmpInst::ICMP_EQ, m_Specific(ShAmt),
+ m_ZeroInt()),
m_SpecificBB(PhiBB), m_SpecificBB(FunnelBB))))
return false;
- if (Pred != CmpInst::ICMP_EQ)
- return false;
-
IRBuilder<> Builder(PhiBB, PhiBB->getFirstInsertionPt());
if (ShVal0 == ShVal1)
diff --git a/llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp b/llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp
index 0a55f4762fdf0..4341ad99f7175 100644
--- a/llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp
+++ b/llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp
@@ -1697,9 +1697,8 @@ Instruction *InstCombinerImpl::visitAdd(BinaryOperator &I) {
ICmpInst::Predicate Pred;
uint64_t BitWidth = Ty->getScalarSizeInBits();
if (match(LHS, m_AShr(m_Value(A), m_SpecificIntAllowPoison(BitWidth - 1))) &&
- match(RHS, m_OneUse(m_ZExt(
- m_OneUse(m_ICmp(Pred, m_Specific(A), m_ZeroInt()))))) &&
- Pred == CmpInst::ICMP_SGT) {
+ match(RHS, m_OneUse(m_ZExt(m_OneUse(m_SpecificICmp(
+ CmpInst::ICMP_SGT, m_Specific(A), m_ZeroInt())))))) {
Value *NotZero = Builder.CreateIsNotNull(A, "isnotnull");
Value *Zext = Builder.CreateZExt(NotZero, Ty, "isnotnull.zext");
return BinaryOperator::CreateOr(LHS, Zext);
diff --git a/llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp b/llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp
index f9caa4da44931..4ca12d5b92f18 100644
--- a/llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp
+++ b/llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp
@@ -818,11 +818,11 @@ static Value *foldSignedTruncationCheck(ICmpInst *ICmp0, ICmpInst *ICmp1,
// Match icmp ult (add %arg, C01), C1 (C1 == C01 << 1; powers of two)
auto tryToMatchSignedTruncationCheck = [](ICmpInst *ICmp, Value *&X,
APInt &SignBitMask) -> bool {
- CmpInst::Predicate Pred;
const APInt *I01, *I1; // powers of two; I1 == I01 << 1
- if (!(match(ICmp,
- m_ICmp(Pred, m_Add(m_Value(X), m_Power2(I01)), m_Power2(I1))) &&
- Pred == ICmpInst::ICMP_ULT && I1->ugt(*I01) && I01->shl(1) == *I1))
+ if (!(match(ICmp, m_SpecificICmp(ICmpInst::ICMP_ULT,
+ m_Add(m_Value(X), m_Power2(I01)),
+ m_Power2(I1))) &&
+ I1->ugt(*I01) && I01->shl(1) == *I1))
return false;
// Which bit is the new sign bit as per the 'signed truncation' pattern?
SignBitMask = *I01;
@@ -936,20 +936,21 @@ static Value *foldIsPowerOf2(ICmpInst *Cmp0, ICmpInst *Cmp1, bool JoinedByAnd,
std::swap(Cmp0, Cmp1);
// (X != 0) && (ctpop(X) u< 2) --> ctpop(X) == 1
- CmpInst::Predicate Pred0, Pred1;
Value *X;
- if (JoinedByAnd && match(Cmp0, m_ICmp(Pred0, m_Value(X), m_ZeroInt())) &&
- match(Cmp1, m_ICmp(Pred1, m_Intrinsic<Intrinsic::ctpop>(m_Specific(X)),
- m_SpecificInt(2))) &&
- Pred0 == ICmpInst::ICMP_NE && Pred1 == ICmpInst::ICMP_ULT) {
+ if (JoinedByAnd &&
+ match(Cmp0, m_SpecificICmp(ICmpInst::ICMP_NE, m_Value(X), m_ZeroInt())) &&
+ match(Cmp1, m_SpecificICmp(ICmpInst::ICMP_ULT,
+ m_Intrinsic<Intrinsic::ctpop>(m_Specific(X)),
+ m_SpecificInt(2)))) {
Value *CtPop = Cmp1->getOperand(0);
return Builder.CreateICmpEQ(CtPop, ConstantInt::get(CtPop->getType(), 1));
}
// (X == 0) || (ctpop(X) u> 1) --> ctpop(X) != 1
- if (!JoinedByAnd && match(Cmp0, m_ICmp(Pred0, m_Value(X), m_ZeroInt())) &&
- match(Cmp1, m_ICmp(Pred1, m_Intrinsic<Intrinsic::ctpop>(m_Specific(X)),
- m_SpecificInt(1))) &&
- Pred0 == ICmpInst::ICMP_EQ && Pred1 == ICmpInst::ICMP_UGT) {
+ if (!JoinedByAnd &&
+ match(Cmp0, m_SpecificICmp(ICmpInst::ICMP_EQ, m_Value(X), m_ZeroInt())) &&
+ match(Cmp1, m_SpecificICmp(ICmpInst::ICMP_UGT,
+ m_Intrinsic<Intrinsic::ctpop>(m_Specific(X)),
+ m_SpecificInt(1)))) {
Value *CtPop = Cmp1->getOperand(0);
return Builder.CreateICmpNE(CtPop, ConstantInt::get(CtPop->getType(), 1));
}
@@ -1608,31 +1609,30 @@ static Instruction *reassociateFCmps(BinaryOperator &BO,
// There are 4 commuted variants of the pattern. Canonicalize operands of this
// logic op so an fcmp is operand 0 and a matching logic op is operand 1.
Value *Op0 = BO.getOperand(0), *Op1 = BO.getOperand(1), *X;
- FCmpInst::Predicate Pred;
- if (match(Op1, m_FCmp(Pred, m_Value(), m_AnyZeroFP())))
+ if (match(Op1, m_FCmp(m_Value(), m_AnyZeroFP())))
std::swap(Op0, Op1);
// Match inner binop and the predicate for combining 2 NAN checks into 1.
Value *BO10, *BO11;
FCmpInst::Predicate NanPred = Opcode == Instruction::And ? FCmpInst::FCMP_ORD
: FCmpInst::FCMP_UNO;
- if (!match(Op0, m_FCmp(Pred, m_Value(X), m_AnyZeroFP())) || Pred != NanPred ||
+ if (!match(Op0, m_SpecificFCmp(NanPred, m_Value(X), m_AnyZeroFP())) ||
!match(Op1, m_BinOp(Opcode, m_Value(BO10), m_Value(BO11))))
return nullptr;
// The inner logic op must have a matching fcmp operand.
Value *Y;
- if (!match(BO10, m_FCmp(Pred, m_Value(Y), m_AnyZeroFP())) ||
- Pred != NanPred || X->getType() != Y->getType())
+ if (!match(BO10, m_SpecificFCmp(NanPred, m_Value(Y), m_AnyZeroFP())) ||
+ X->getType() != Y->getType())
std::swap(BO10, BO11);
- if (!match(BO10, m_FCmp(Pred, m_Value(Y), m_AnyZeroFP())) ||
- Pred != NanPred || X->getType() != Y->getType())
+ if (!match(BO10, m_SpecificFCmp(NanPred, m_Value(Y), m_AnyZeroFP())) ||
+ X->getType() != Y->getType())
return nullptr;
// and (fcmp ord X, 0), (and (fcmp ord Y, 0), Z) --> and (fcmp ord X, Y), Z
// or (fcmp uno X, 0), (or (fcmp uno Y, 0), Z) --> or (fcmp uno X, Y), Z
- Value *NewFCmp = Builder.CreateFCmp(Pred, X, Y);
+ Value *NewFCmp = Builder.CreateFCmp(NanPred, X, Y);
if (auto *NewFCmpInst = dyn_cast<FCmpInst>(NewFCmp)) {
// Intersect FMF from the 2 source fcmps.
NewFCmpInst->copyIRFlags(Op0);
@@ -1744,14 +1744,13 @@ Instruction *InstCombinerImpl::foldCastedBitwiseLogic(BinaryOperator &I) {
// -> zext(bitwise(A < 0, icmp))
auto FoldBitwiseICmpZeroWithICmp = [&](Value *Op0,
Value *Op1) -> Instruction * {
- ICmpInst::Predicate Pred;
Value *A;
bool IsMatched =
match(Op0,
m_OneUse(m_LShr(
m_Value(A),
m_SpecificInt(Op0->getType()->getScalarSizeInBits() - 1)))) &&
- match(Op1, m_OneUse(m_ZExt(m_ICmp(Pred, m_Value(), m_Value()))));
+ match(Op1, m_OneUse(m_ZExt(m_ICmp(m_Value(), m_Value()))));
if (!IsMatched)
return nullptr;
@@ -3878,14 +3877,14 @@ Instruction *InstCombinerImpl::visitOr(BinaryOperator &I) {
if (match(&I,
m_c_Or(m_CombineAnd(m_ExtractValue<1>(m_Value(UMulWithOv)),
m_Value(Ov)),
- m_CombineAnd(m_ICmp(Pred,
- m_CombineAnd(m_ExtractValue<0>(
- m_Deferred(UMulWithOv)),
- m_Value(Mul)),
- m_ZeroInt()),
- m_Value(MulIsNotZero)))) &&
- (Ov->hasOneUse() || (MulIsNotZero->hasOneUse() && Mul->hasOneUse())) &&
- Pred == CmpInst::ICMP_NE) {
+ m_CombineAnd(
+ m_SpecificICmp(ICmpInst::ICMP_NE,
+ m_CombineAnd(m_ExtractValue<0>(
+ m_Deferred(UMulWithOv)),
+ m_Value(Mul)),
+ m_ZeroInt()),
+ m_Value(MulIsNotZero)))) &&
+ (Ov->hasOneUse() || (MulIsNotZero->hasOneUse() && Mul->hasOneUse()))) {
Value *A, *B;
if (match(UMulWithOv, m_Intrinsic<Intrinsic::umul_with_overflow>(
m_Value(A), m_Value(B)))) {
diff --git a/llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp b/llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp
index f6c4b6e180937..9e690cd2c624f 100644
--- a/llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp
+++ b/llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp
@@ -3031,10 +3031,10 @@ Instruction *InstCombinerImpl::visitCallInst(CallInst &CI) {
// assume( (load addr) != null ) -> add 'nonnull' metadata to load
// (if assume is valid at the load)
- CmpInst::Predicate Pred;
Instruction *LHS;
- if (match(IIOperand, m_ICmp(Pred, m_Instruction(LHS), m_Zero())) &&
- Pred == ICmpInst::ICMP_NE && LHS->getOpcode() == Instruction::Load &&
+ if (match(IIOperand, m_SpecificICmp(ICmpInst::ICMP_NE, m_Instruction(LHS),
+ m_Zero())) &&
+ LHS->getOpcode() == Instruction::Load &&
LHS->getType()->isPointerTy() &&
isValidAssumeForContext(II, LHS, &DT)) {
MDNode *MD = MDNode::get(II->getContext(), std::nullopt);
@@ -3073,8 +3073,9 @@ Instruction *InstCombinerImpl::visitCallInst(CallInst &CI) {
// into
// call void @llvm.assume(i1 true) [ "nonnull"(i32* %PTR) ]
if (EnableKnowledgeRetention &&
- match(IIOperand, m_Cmp(Pred, m_Value(A), m_Zero())) &&
- Pred == CmpInst::ICMP_NE && A->getType()->isPointerTy()) {
+ match(IIOperand,
+ m_SpecificICmp(ICmpInst::ICMP_NE, m_Value(A), m_Zero())) &&
+ A->getType()->isPointerTy()) {
if (auto *Replacement = buildAssumeFromKnowledge(
{RetainedKnowledge{Attribute::NonNull, 0, A}}, Next, &AC, &DT)) {
@@ -3094,9 +3095,9 @@ Instruction *InstCombinerImpl::visitCallInst(CallInst &CI) {
uint64_t AlignMask;
if (EnableKnowledgeRetention &&
match(IIOperand,
- m_Cmp(Pred, m_And(m_Value(A), m_ConstantInt(AlignMask)),
- m_Zero())) &&
- Pred == CmpInst::ICMP_EQ) {
+ m_SpecificICmp(ICmpInst::ICMP_EQ,
+ m_And(m_Value(A), m_ConstantInt(AlignMask)),
+ m_Zero()))) {
if (isPowerOf2_64(AlignMask + 1)) {
uint64_t Offset = 0;
match(A, m_Add(m_Value(A), m_ConstantInt(Offset)));
diff --git a/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp b/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp
index abadf54a96767..3b6df2760ecc2 100644
--- a/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp
+++ b/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp
@@ -5772,8 +5772,7 @@ Instruction *InstCombinerImpl::foldICmpEquality(ICmpInst &I) {
// -> icmp eq/ne X, rotate-left(X)
// We generally try to convert rotate-right -> rotate-left, this just
// canonicalizes another case.
- CmpInst::Predicate PredUnused = Pred;
- if (match(&I, m_c_ICmp(PredUnused, m_Value(A),
+ if (match(&I, m_c_ICmp(m_Value(A),
m_OneUse(m_Intrinsic<Intrinsic::fshr>(
m_Deferred(A), m_Deferred(A), m_Value(B))))))
return new ICmpInst(
@@ -5783,8 +5782,7 @@ Instruction *InstCombinerImpl::foldICmpEquality(ICmpInst &I) {
// Canonicalize:
// icmp eq/ne OneUse(A ^ Cst), B --> icmp eq/ne (A ^ B), Cst
Constant *Cst;
- if (match(&I, m_c_ICmp(PredUnused,
- m_OneUse(m_Xor(m_Value(A), m_ImmConstant(Cst))),
+ if (match(&I, m_c_ICmp(m_OneUse(m_Xor(m_Value(A), m_ImmConstant(Cst))),
m_CombineAnd(m_Value(B), m_Unless(m_ImmConstant())))))
return new ICmpInst(Pred, Builder.CreateXor(A, B), Cst);
@@ -5795,13 +5793,12 @@ Instruction *InstCombinerImpl::foldICmpEquality(ICmpInst &I) {
m_c_Xor(m_Value(B), m_Deferred(A))),
m_Sub(m_Value(B), m_Deferred(A)));
std::optional<bool> IsZero = std::nullopt;
- if (match(&I, m_c_ICmp(PredUnused, m_OneUse(m_c_And(m_Value(A), m_Matcher)),
+ if (match(&I, m_c_ICmp(m_OneUse(m_c_And(m_Value(A), m_Matcher)),
m_Deferred(A))))
IsZero = false;
// (icmp eq/ne (and (add/sub/xor X, P2), P2), 0)
else if (match(&I,
- m_ICmp(PredUnused, m_OneUse(m_c_And(m_Value(A), m_Matcher)),
- m_Zero())))
+ m_ICmp(m_OneUse(m_c_And(m_Value(A), m_Matcher)), m_Zero())))
IsZero = true;
...
[truncated]
|
@llvm/pr-subscribers-backend-x86 Author: Yingwei Zheng (dtcxzyw) ChangesCompile-time improvement: http://llvm-compile-time-tracker.com/compare.php?from=13996378d81c8fa9a364aeaafd7382abbc1db83a&to=861ffa4ec5f7bde5a194a7715593a1b5359eb581&stat=instructions:u
Patch is 26.20 KiB, truncated to 20.00 KiB below, full version: https://github.com/llvm/llvm-project/pull/100878.diff 15 Files Affected:
diff --git a/llvm/lib/Analysis/InstructionSimplify.cpp b/llvm/lib/Analysis/InstructionSimplify.cpp
index 3a7ae577bb068..abf0735aa2c99 100644
--- a/llvm/lib/Analysis/InstructionSimplify.cpp
+++ b/llvm/lib/Analysis/InstructionSimplify.cpp
@@ -110,10 +110,11 @@ static Value *foldSelectWithBinaryOp(Value *Cond, Value *TrueVal,
// -->
// %TV
Value *X, *Y;
- if (!match(Cond, m_c_BinOp(m_c_ICmp(Pred1, m_Specific(TrueVal),
- m_Specific(FalseVal)),
- m_ICmp(Pred2, m_Value(X), m_Value(Y)))) ||
- Pred1 != Pred2 || Pred1 != ExpectedPred)
+ if (!match(
+ Cond,
+ m_c_BinOp(m_c_ICmp(Pred1, m_Specific(TrueVal), m_Specific(FalseVal)),
+ m_SpecificICmp(ExpectedPred, m_Value(X), m_Value(Y)))) ||
+ Pred1 != ExpectedPred)
return nullptr;
if (X == TrueVal || X == FalseVal || Y == TrueVal || Y == FalseVal)
diff --git a/llvm/lib/Analysis/ValueTracking.cpp b/llvm/lib/Analysis/ValueTracking.cpp
index bfd26fadd237b..10884f8d32b86 100644
--- a/llvm/lib/Analysis/ValueTracking.cpp
+++ b/llvm/lib/Analysis/ValueTracking.cpp
@@ -254,8 +254,7 @@ bool llvm::haveNoCommonBitsSet(const WithCache<const Value *> &LHSCache,
bool llvm::isOnlyUsedInZeroComparison(const Instruction *I) {
return !I->user_empty() && all_of(I->users(), [](const User *U) {
- ICmpInst::Predicate P;
- return match(U, m_ICmp(P, m_Value(), m_Zero()));
+ return match(U, m_ICmp(m_Value(), m_Zero()));
});
}
@@ -2594,10 +2593,10 @@ static bool isNonZeroRecurrence(const PHINode *PN) {
}
static bool matchOpWithOpEqZero(Value *Op0, Value *Op1) {
- ICmpInst::Predicate Pred;
- return (match(Op0, m_ZExtOrSExt(m_ICmp(Pred, m_Specific(Op1), m_Zero()))) ||
- match(Op1, m_ZExtOrSExt(m_ICmp(Pred, m_Specific(Op0), m_Zero())))) &&
- Pred == ICmpInst::ICMP_EQ;
+ return match(Op0, m_ZExtOrSExt(m_SpecificICmp(ICmpInst::ICMP_EQ,
+ m_Specific(Op1), m_Zero()))) ||
+ match(Op1, m_ZExtOrSExt(m_SpecificICmp(ICmpInst::ICMP_EQ,
+ m_Specific(Op0), m_Zero())));
}
static bool isNonZeroAdd(const APInt &DemandedElts, unsigned Depth,
diff --git a/llvm/lib/Target/AMDGPU/AMDGPULowerKernelAttributes.cpp b/llvm/lib/Target/AMDGPU/AMDGPULowerKernelAttributes.cpp
index e91d05954a1c9..e724c978c44b6 100644
--- a/llvm/lib/Target/AMDGPU/AMDGPULowerKernelAttributes.cpp
+++ b/llvm/lib/Target/AMDGPU/AMDGPULowerKernelAttributes.cpp
@@ -225,10 +225,8 @@ static bool processUse(CallInst *CI, bool IsV5OrAbove) {
: m_Intrinsic<Intrinsic::amdgcn_workgroup_id_z>());
for (User *ICmp : BlockCount->users()) {
- ICmpInst::Predicate Pred;
- if (match(ICmp, m_ICmp(Pred, GroupIDIntrin, m_Specific(BlockCount)))) {
- if (Pred != ICmpInst::ICMP_ULT)
- continue;
+ if (match(ICmp, m_SpecificICmp(ICmpInst::ICMP_ULT, GroupIDIntrin,
+ m_Specific(BlockCount)))) {
ICmp->replaceAllUsesWith(llvm::ConstantInt::getTrue(ICmp->getType()));
MadeChange = true;
}
diff --git a/llvm/lib/Target/X86/X86ISelLowering.cpp b/llvm/lib/Target/X86/X86ISelLowering.cpp
index ad59b13933a6a..b971afda4229a 100644
--- a/llvm/lib/Target/X86/X86ISelLowering.cpp
+++ b/llvm/lib/Target/X86/X86ISelLowering.cpp
@@ -3435,12 +3435,9 @@ X86TargetLowering::getJumpConditionMergingParams(Instruction::BinaryOps Opc,
if (BaseCost >= 0 && Subtarget.hasCCMP())
BaseCost += BrMergingCcmpBias;
// a == b && a == c is a fast pattern on x86.
- ICmpInst::Predicate Pred;
if (BaseCost >= 0 && Opc == Instruction::And &&
- match(Lhs, m_ICmp(Pred, m_Value(), m_Value())) &&
- Pred == ICmpInst::ICMP_EQ &&
- match(Rhs, m_ICmp(Pred, m_Value(), m_Value())) &&
- Pred == ICmpInst::ICMP_EQ)
+ match(Lhs, m_SpecificICmp(ICmpInst::ICMP_EQ, m_Value(), m_Value())) &&
+ match(Rhs, m_SpecificICmp(ICmpInst::ICMP_EQ, m_Value(), m_Value())))
BaseCost += 1;
return {BaseCost, BrMergingLikelyBias.getValue(),
BrMergingUnlikelyBias.getValue()};
@@ -30760,10 +30757,12 @@ static bool shouldExpandCmpArithRMWInIR(AtomicRMWInst *AI) {
if (match(I, m_c_ICmp(Pred, m_Sub(m_ZeroInt(), m_Specific(Op)), m_Value())))
return Pred == CmpInst::ICMP_EQ || Pred == CmpInst::ICMP_NE;
if (match(I, m_OneUse(m_c_Add(m_Specific(Op), m_Value())))) {
- if (match(I->user_back(), m_ICmp(Pred, m_Value(), m_ZeroInt())))
- return Pred == CmpInst::ICMP_SLT;
- if (match(I->user_back(), m_ICmp(Pred, m_Value(), m_AllOnes())))
- return Pred == CmpInst::ICMP_SGT;
+ if (match(I->user_back(),
+ m_SpecificICmp(CmpInst::ICMP_SLT, m_Value(), m_ZeroInt())))
+ return true;
+ if (match(I->user_back(),
+ m_SpecificICmp(CmpInst::ICMP_SGT, m_Value(), m_AllOnes())))
+ return true;
}
return false;
}
@@ -30771,10 +30770,12 @@ static bool shouldExpandCmpArithRMWInIR(AtomicRMWInst *AI) {
if (match(I, m_c_ICmp(Pred, m_Specific(Op), m_Value())))
return Pred == CmpInst::ICMP_EQ || Pred == CmpInst::ICMP_NE;
if (match(I, m_OneUse(m_Sub(m_Value(), m_Specific(Op))))) {
- if (match(I->user_back(), m_ICmp(Pred, m_Value(), m_ZeroInt())))
- return Pred == CmpInst::ICMP_SLT;
- if (match(I->user_back(), m_ICmp(Pred, m_Value(), m_AllOnes())))
- return Pred == CmpInst::ICMP_SGT;
+ if (match(I->user_back(),
+ m_SpecificICmp(CmpInst::ICMP_SLT, m_Value(), m_ZeroInt())))
+ return true;
+ if (match(I->user_back(),
+ m_SpecificICmp(CmpInst::ICMP_SGT, m_Value(), m_AllOnes())))
+ return true;
}
return false;
}
@@ -30785,18 +30786,21 @@ static bool shouldExpandCmpArithRMWInIR(AtomicRMWInst *AI) {
if (match(I->user_back(), m_ICmp(Pred, m_Value(), m_ZeroInt())))
return Pred == CmpInst::ICMP_EQ || Pred == CmpInst::ICMP_NE ||
Pred == CmpInst::ICMP_SLT;
- if (match(I->user_back(), m_ICmp(Pred, m_Value(), m_AllOnes())))
- return Pred == CmpInst::ICMP_SGT;
+ if (match(I->user_back(),
+ m_SpecificICmp(CmpInst::ICMP_SGT, m_Value(), m_AllOnes())))
+ return true;
return false;
}
if (Opc == AtomicRMWInst::Xor) {
if (match(I, m_c_ICmp(Pred, m_Specific(Op), m_Value())))
return Pred == CmpInst::ICMP_EQ || Pred == CmpInst::ICMP_NE;
if (match(I, m_OneUse(m_c_Xor(m_Specific(Op), m_Value())))) {
- if (match(I->user_back(), m_ICmp(Pred, m_Value(), m_ZeroInt())))
- return Pred == CmpInst::ICMP_SLT;
- if (match(I->user_back(), m_ICmp(Pred, m_Value(), m_AllOnes())))
- return Pred == CmpInst::ICMP_SGT;
+ if (match(I->user_back(),
+ m_SpecificICmp(CmpInst::ICMP_SLT, m_Value(), m_ZeroInt())))
+ return true;
+ if (match(I->user_back(),
+ m_SpecificICmp(CmpInst::ICMP_SGT, m_Value(), m_AllOnes())))
+ return true;
}
return false;
}
diff --git a/llvm/lib/Transforms/AggressiveInstCombine/AggressiveInstCombine.cpp b/llvm/lib/Transforms/AggressiveInstCombine/AggressiveInstCombine.cpp
index d5a38ec17a2a8..09ffc2d184f18 100644
--- a/llvm/lib/Transforms/AggressiveInstCombine/AggressiveInstCombine.cpp
+++ b/llvm/lib/Transforms/AggressiveInstCombine/AggressiveInstCombine.cpp
@@ -135,15 +135,12 @@ static bool foldGuardedFunnelShift(Instruction &I, const DominatorTree &DT) {
if (!DT.dominates(ShVal0, TermI) || !DT.dominates(ShVal1, TermI))
return false;
- ICmpInst::Predicate Pred;
BasicBlock *PhiBB = Phi.getParent();
- if (!match(TermI, m_Br(m_ICmp(Pred, m_Specific(ShAmt), m_ZeroInt()),
+ if (!match(TermI, m_Br(m_SpecificICmp(CmpInst::ICMP_EQ, m_Specific(ShAmt),
+ m_ZeroInt()),
m_SpecificBB(PhiBB), m_SpecificBB(FunnelBB))))
return false;
- if (Pred != CmpInst::ICMP_EQ)
- return false;
-
IRBuilder<> Builder(PhiBB, PhiBB->getFirstInsertionPt());
if (ShVal0 == ShVal1)
diff --git a/llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp b/llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp
index 0a55f4762fdf0..4341ad99f7175 100644
--- a/llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp
+++ b/llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp
@@ -1697,9 +1697,8 @@ Instruction *InstCombinerImpl::visitAdd(BinaryOperator &I) {
ICmpInst::Predicate Pred;
uint64_t BitWidth = Ty->getScalarSizeInBits();
if (match(LHS, m_AShr(m_Value(A), m_SpecificIntAllowPoison(BitWidth - 1))) &&
- match(RHS, m_OneUse(m_ZExt(
- m_OneUse(m_ICmp(Pred, m_Specific(A), m_ZeroInt()))))) &&
- Pred == CmpInst::ICMP_SGT) {
+ match(RHS, m_OneUse(m_ZExt(m_OneUse(m_SpecificICmp(
+ CmpInst::ICMP_SGT, m_Specific(A), m_ZeroInt())))))) {
Value *NotZero = Builder.CreateIsNotNull(A, "isnotnull");
Value *Zext = Builder.CreateZExt(NotZero, Ty, "isnotnull.zext");
return BinaryOperator::CreateOr(LHS, Zext);
diff --git a/llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp b/llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp
index f9caa4da44931..4ca12d5b92f18 100644
--- a/llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp
+++ b/llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp
@@ -818,11 +818,11 @@ static Value *foldSignedTruncationCheck(ICmpInst *ICmp0, ICmpInst *ICmp1,
// Match icmp ult (add %arg, C01), C1 (C1 == C01 << 1; powers of two)
auto tryToMatchSignedTruncationCheck = [](ICmpInst *ICmp, Value *&X,
APInt &SignBitMask) -> bool {
- CmpInst::Predicate Pred;
const APInt *I01, *I1; // powers of two; I1 == I01 << 1
- if (!(match(ICmp,
- m_ICmp(Pred, m_Add(m_Value(X), m_Power2(I01)), m_Power2(I1))) &&
- Pred == ICmpInst::ICMP_ULT && I1->ugt(*I01) && I01->shl(1) == *I1))
+ if (!(match(ICmp, m_SpecificICmp(ICmpInst::ICMP_ULT,
+ m_Add(m_Value(X), m_Power2(I01)),
+ m_Power2(I1))) &&
+ I1->ugt(*I01) && I01->shl(1) == *I1))
return false;
// Which bit is the new sign bit as per the 'signed truncation' pattern?
SignBitMask = *I01;
@@ -936,20 +936,21 @@ static Value *foldIsPowerOf2(ICmpInst *Cmp0, ICmpInst *Cmp1, bool JoinedByAnd,
std::swap(Cmp0, Cmp1);
// (X != 0) && (ctpop(X) u< 2) --> ctpop(X) == 1
- CmpInst::Predicate Pred0, Pred1;
Value *X;
- if (JoinedByAnd && match(Cmp0, m_ICmp(Pred0, m_Value(X), m_ZeroInt())) &&
- match(Cmp1, m_ICmp(Pred1, m_Intrinsic<Intrinsic::ctpop>(m_Specific(X)),
- m_SpecificInt(2))) &&
- Pred0 == ICmpInst::ICMP_NE && Pred1 == ICmpInst::ICMP_ULT) {
+ if (JoinedByAnd &&
+ match(Cmp0, m_SpecificICmp(ICmpInst::ICMP_NE, m_Value(X), m_ZeroInt())) &&
+ match(Cmp1, m_SpecificICmp(ICmpInst::ICMP_ULT,
+ m_Intrinsic<Intrinsic::ctpop>(m_Specific(X)),
+ m_SpecificInt(2)))) {
Value *CtPop = Cmp1->getOperand(0);
return Builder.CreateICmpEQ(CtPop, ConstantInt::get(CtPop->getType(), 1));
}
// (X == 0) || (ctpop(X) u> 1) --> ctpop(X) != 1
- if (!JoinedByAnd && match(Cmp0, m_ICmp(Pred0, m_Value(X), m_ZeroInt())) &&
- match(Cmp1, m_ICmp(Pred1, m_Intrinsic<Intrinsic::ctpop>(m_Specific(X)),
- m_SpecificInt(1))) &&
- Pred0 == ICmpInst::ICMP_EQ && Pred1 == ICmpInst::ICMP_UGT) {
+ if (!JoinedByAnd &&
+ match(Cmp0, m_SpecificICmp(ICmpInst::ICMP_EQ, m_Value(X), m_ZeroInt())) &&
+ match(Cmp1, m_SpecificICmp(ICmpInst::ICMP_UGT,
+ m_Intrinsic<Intrinsic::ctpop>(m_Specific(X)),
+ m_SpecificInt(1)))) {
Value *CtPop = Cmp1->getOperand(0);
return Builder.CreateICmpNE(CtPop, ConstantInt::get(CtPop->getType(), 1));
}
@@ -1608,31 +1609,30 @@ static Instruction *reassociateFCmps(BinaryOperator &BO,
// There are 4 commuted variants of the pattern. Canonicalize operands of this
// logic op so an fcmp is operand 0 and a matching logic op is operand 1.
Value *Op0 = BO.getOperand(0), *Op1 = BO.getOperand(1), *X;
- FCmpInst::Predicate Pred;
- if (match(Op1, m_FCmp(Pred, m_Value(), m_AnyZeroFP())))
+ if (match(Op1, m_FCmp(m_Value(), m_AnyZeroFP())))
std::swap(Op0, Op1);
// Match inner binop and the predicate for combining 2 NAN checks into 1.
Value *BO10, *BO11;
FCmpInst::Predicate NanPred = Opcode == Instruction::And ? FCmpInst::FCMP_ORD
: FCmpInst::FCMP_UNO;
- if (!match(Op0, m_FCmp(Pred, m_Value(X), m_AnyZeroFP())) || Pred != NanPred ||
+ if (!match(Op0, m_SpecificFCmp(NanPred, m_Value(X), m_AnyZeroFP())) ||
!match(Op1, m_BinOp(Opcode, m_Value(BO10), m_Value(BO11))))
return nullptr;
// The inner logic op must have a matching fcmp operand.
Value *Y;
- if (!match(BO10, m_FCmp(Pred, m_Value(Y), m_AnyZeroFP())) ||
- Pred != NanPred || X->getType() != Y->getType())
+ if (!match(BO10, m_SpecificFCmp(NanPred, m_Value(Y), m_AnyZeroFP())) ||
+ X->getType() != Y->getType())
std::swap(BO10, BO11);
- if (!match(BO10, m_FCmp(Pred, m_Value(Y), m_AnyZeroFP())) ||
- Pred != NanPred || X->getType() != Y->getType())
+ if (!match(BO10, m_SpecificFCmp(NanPred, m_Value(Y), m_AnyZeroFP())) ||
+ X->getType() != Y->getType())
return nullptr;
// and (fcmp ord X, 0), (and (fcmp ord Y, 0), Z) --> and (fcmp ord X, Y), Z
// or (fcmp uno X, 0), (or (fcmp uno Y, 0), Z) --> or (fcmp uno X, Y), Z
- Value *NewFCmp = Builder.CreateFCmp(Pred, X, Y);
+ Value *NewFCmp = Builder.CreateFCmp(NanPred, X, Y);
if (auto *NewFCmpInst = dyn_cast<FCmpInst>(NewFCmp)) {
// Intersect FMF from the 2 source fcmps.
NewFCmpInst->copyIRFlags(Op0);
@@ -1744,14 +1744,13 @@ Instruction *InstCombinerImpl::foldCastedBitwiseLogic(BinaryOperator &I) {
// -> zext(bitwise(A < 0, icmp))
auto FoldBitwiseICmpZeroWithICmp = [&](Value *Op0,
Value *Op1) -> Instruction * {
- ICmpInst::Predicate Pred;
Value *A;
bool IsMatched =
match(Op0,
m_OneUse(m_LShr(
m_Value(A),
m_SpecificInt(Op0->getType()->getScalarSizeInBits() - 1)))) &&
- match(Op1, m_OneUse(m_ZExt(m_ICmp(Pred, m_Value(), m_Value()))));
+ match(Op1, m_OneUse(m_ZExt(m_ICmp(m_Value(), m_Value()))));
if (!IsMatched)
return nullptr;
@@ -3878,14 +3877,14 @@ Instruction *InstCombinerImpl::visitOr(BinaryOperator &I) {
if (match(&I,
m_c_Or(m_CombineAnd(m_ExtractValue<1>(m_Value(UMulWithOv)),
m_Value(Ov)),
- m_CombineAnd(m_ICmp(Pred,
- m_CombineAnd(m_ExtractValue<0>(
- m_Deferred(UMulWithOv)),
- m_Value(Mul)),
- m_ZeroInt()),
- m_Value(MulIsNotZero)))) &&
- (Ov->hasOneUse() || (MulIsNotZero->hasOneUse() && Mul->hasOneUse())) &&
- Pred == CmpInst::ICMP_NE) {
+ m_CombineAnd(
+ m_SpecificICmp(ICmpInst::ICMP_NE,
+ m_CombineAnd(m_ExtractValue<0>(
+ m_Deferred(UMulWithOv)),
+ m_Value(Mul)),
+ m_ZeroInt()),
+ m_Value(MulIsNotZero)))) &&
+ (Ov->hasOneUse() || (MulIsNotZero->hasOneUse() && Mul->hasOneUse()))) {
Value *A, *B;
if (match(UMulWithOv, m_Intrinsic<Intrinsic::umul_with_overflow>(
m_Value(A), m_Value(B)))) {
diff --git a/llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp b/llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp
index f6c4b6e180937..9e690cd2c624f 100644
--- a/llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp
+++ b/llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp
@@ -3031,10 +3031,10 @@ Instruction *InstCombinerImpl::visitCallInst(CallInst &CI) {
// assume( (load addr) != null ) -> add 'nonnull' metadata to load
// (if assume is valid at the load)
- CmpInst::Predicate Pred;
Instruction *LHS;
- if (match(IIOperand, m_ICmp(Pred, m_Instruction(LHS), m_Zero())) &&
- Pred == ICmpInst::ICMP_NE && LHS->getOpcode() == Instruction::Load &&
+ if (match(IIOperand, m_SpecificICmp(ICmpInst::ICMP_NE, m_Instruction(LHS),
+ m_Zero())) &&
+ LHS->getOpcode() == Instruction::Load &&
LHS->getType()->isPointerTy() &&
isValidAssumeForContext(II, LHS, &DT)) {
MDNode *MD = MDNode::get(II->getContext(), std::nullopt);
@@ -3073,8 +3073,9 @@ Instruction *InstCombinerImpl::visitCallInst(CallInst &CI) {
// into
// call void @llvm.assume(i1 true) [ "nonnull"(i32* %PTR) ]
if (EnableKnowledgeRetention &&
- match(IIOperand, m_Cmp(Pred, m_Value(A), m_Zero())) &&
- Pred == CmpInst::ICMP_NE && A->getType()->isPointerTy()) {
+ match(IIOperand,
+ m_SpecificICmp(ICmpInst::ICMP_NE, m_Value(A), m_Zero())) &&
+ A->getType()->isPointerTy()) {
if (auto *Replacement = buildAssumeFromKnowledge(
{RetainedKnowledge{Attribute::NonNull, 0, A}}, Next, &AC, &DT)) {
@@ -3094,9 +3095,9 @@ Instruction *InstCombinerImpl::visitCallInst(CallInst &CI) {
uint64_t AlignMask;
if (EnableKnowledgeRetention &&
match(IIOperand,
- m_Cmp(Pred, m_And(m_Value(A), m_ConstantInt(AlignMask)),
- m_Zero())) &&
- Pred == CmpInst::ICMP_EQ) {
+ m_SpecificICmp(ICmpInst::ICMP_EQ,
+ m_And(m_Value(A), m_ConstantInt(AlignMask)),
+ m_Zero()))) {
if (isPowerOf2_64(AlignMask + 1)) {
uint64_t Offset = 0;
match(A, m_Add(m_Value(A), m_ConstantInt(Offset)));
diff --git a/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp b/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp
index abadf54a96767..3b6df2760ecc2 100644
--- a/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp
+++ b/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp
@@ -5772,8 +5772,7 @@ Instruction *InstCombinerImpl::foldICmpEquality(ICmpInst &I) {
// -> icmp eq/ne X, rotate-left(X)
// We generally try to convert rotate-right -> rotate-left, this just
// canonicalizes another case.
- CmpInst::Predicate PredUnused = Pred;
- if (match(&I, m_c_ICmp(PredUnused, m_Value(A),
+ if (match(&I, m_c_ICmp(m_Value(A),
m_OneUse(m_Intrinsic<Intrinsic::fshr>(
m_Deferred(A), m_Deferred(A), m_Value(B))))))
return new ICmpInst(
@@ -5783,8 +5782,7 @@ Instruction *InstCombinerImpl::foldICmpEquality(ICmpInst &I) {
// Canonicalize:
// icmp eq/ne OneUse(A ^ Cst), B --> icmp eq/ne (A ^ B), Cst
Constant *Cst;
- if (match(&I, m_c_ICmp(PredUnused,
- m_OneUse(m_Xor(m_Value(A), m_ImmConstant(Cst))),
+ if (match(&I, m_c_ICmp(m_OneUse(m_Xor(m_Value(A), m_ImmConstant(Cst))),
m_CombineAnd(m_Value(B), m_Unless(m_ImmConstant())))))
return new ICmpInst(Pred, Builder.CreateXor(A, B), Cst);
@@ -5795,13 +5793,12 @@ Instruction *InstCombinerImpl::foldICmpEquality(ICmpInst &I) {
m_c_Xor(m_Value(B), m_Deferred(A))),
m_Sub(m_Value(B), m_Deferred(A)));
std::optional<bool> IsZero = std::nullopt;
- if (match(&I, m_c_ICmp(PredUnused, m_OneUse(m_c_And(m_Value(A), m_Matcher)),
+ if (match(&I, m_c_ICmp(m_OneUse(m_c_And(m_Value(A), m_Matcher)),
m_Deferred(A))))
IsZero = false;
// (icmp eq/ne (and (add/sub/xor X, P2), P2), 0)
else if (match(&I,
- m_ICmp(PredUnused, m_OneUse(m_c_And(m_Value(A), m_Matcher)),
- m_Zero())))
+ m_ICmp(m_OneUse(m_c_And(m_Value(A), m_Matcher)), m_Zero())))
IsZero = true;
...
[truncated]
|
I don't see how this change can cause any significant compile-time changes (unless it's due to the bug in foldSelectWithBinaryOp). Can you please check what kind of results you get if you run the compile-time test against a no-op change to see what the noise level looks like? |
Can you please check what kind of results you get if you run the compile-time test against a no-op change to see what the noise level looks like? Tested with 803eaf2 Test1 vs Test2
Test1 vs Test3
Test2 vs Test3
|
Okay, so it looks like the top 5 improvements/regressions are very noisy. I did wonder why I wasn't able to reproduce all regressions on previous PRs. To mostly avoid this problem I collect per-benchmark stddev data and only consider differences starting at 3-4 sigma significant. |
Oops, I forgot to disable ASLR after the last power outage in my lab :(
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
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% ``` (cherry picked from commit 62e9f40)
Compile-time improvement: http://llvm-compile-time-tracker.com/compare.php?from=13996378d81c8fa9a364aeaafd7382abbc1db83a&to=861ffa4ec5f7bde5a194a7715593a1b5359eb581&stat=instructions:u
baseline: 803eaf2