[llvm] b716d35 - [VPlanPatternMatch] Introduce m_ConstantInt (#159558)
via llvm-commits
llvm-commits at lists.llvm.org
Sun Sep 21 05:27:50 PDT 2025
Author: Ramkumar Ramachandra
Date: 2025-09-21T13:27:46+01:00
New Revision: b716d353885c9a12bc14a3d42a5018a9833fb03c
URL: https://github.com/llvm/llvm-project/commit/b716d353885c9a12bc14a3d42a5018a9833fb03c
DIFF: https://github.com/llvm/llvm-project/commit/b716d353885c9a12bc14a3d42a5018a9833fb03c.diff
LOG: [VPlanPatternMatch] Introduce m_ConstantInt (#159558)
Added:
Modified:
llvm/lib/Transforms/Vectorize/VPlanPatternMatch.h
llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp
Removed:
################################################################################
diff --git a/llvm/lib/Transforms/Vectorize/VPlanPatternMatch.h b/llvm/lib/Transforms/Vectorize/VPlanPatternMatch.h
index 2a6191e1d7ed4..555efea1ea840 100644
--- a/llvm/lib/Transforms/Vectorize/VPlanPatternMatch.h
+++ b/llvm/lib/Transforms/Vectorize/VPlanPatternMatch.h
@@ -173,6 +173,33 @@ inline int_pred_ty<is_zero_int> m_ZeroInt() {
/// For vectors, this includes constants with undefined elements.
inline int_pred_ty<is_one> m_One() { return int_pred_ty<is_one>(); }
+struct bind_const_int {
+ uint64_t &Res;
+
+ bind_const_int(uint64_t &Res) : Res(Res) {}
+
+ bool match(VPValue *VPV) const {
+ if (!VPV->isLiveIn())
+ return false;
+ Value *V = VPV->getLiveInIRValue();
+ if (!V)
+ return false;
+ assert(!V->getType()->isVectorTy() && "Unexpected vector live-in");
+ const auto *CI = dyn_cast<ConstantInt>(V);
+ if (!CI)
+ return false;
+ if (auto C = CI->getValue().tryZExtValue()) {
+ Res = *C;
+ return true;
+ }
+ return false;
+ }
+};
+
+/// Match a plain integer constant no wider than 64-bits, capturing it if we
+/// match.
+inline bind_const_int m_ConstantInt(uint64_t &C) { return C; }
+
/// Matching combinators
template <typename LTy, typename RTy> struct match_combine_or {
LTy L;
diff --git a/llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp b/llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp
index 1f6b85270607e..3cdbf21524162 100644
--- a/llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp
+++ b/llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp
@@ -1592,11 +1592,12 @@ static bool tryToReplaceALMWithWideALM(VPlan &Plan, ElementCount VF,
m_ActiveLaneMask(m_VPValue(Index), m_VPValue(), m_VPValue()));
assert(Index && "Expected index from ActiveLaneMask instruction");
- auto *II = dyn_cast<VPInstruction>(Index);
- if (II && II->getOpcode() == VPInstruction::CanonicalIVIncrementForPart) {
- auto Part = cast<ConstantInt>(II->getOperand(1)->getLiveInIRValue());
- Phis[Part->getZExtValue()] = Phi;
- } else
+ uint64_t Part;
+ if (match(Index,
+ m_VPInstruction<VPInstruction::CanonicalIVIncrementForPart>(
+ m_VPValue(), m_ConstantInt(Part))))
+ Phis[Part] = Phi;
+ else
// Anything other than a CanonicalIVIncrementForPart is part 0
Phis[0] = Phi;
}
More information about the llvm-commits
mailing list