[VPlanPatternMatch] Introduce m_ConstantInt#159558
Merged
Merged
Conversation
Member
|
@llvm/pr-subscribers-vectorizers @llvm/pr-subscribers-llvm-transforms Author: Ramkumar Ramachandra (artagnon) ChangesFull diff: https://github.com/llvm/llvm-project/pull/159558.diff 2 Files Affected:
diff --git a/llvm/lib/Transforms/Vectorize/VPlanPatternMatch.h b/llvm/lib/Transforms/Vectorize/VPlanPatternMatch.h
index 8f9ce7a74b58b..7da75473ba00e 100644
--- a/llvm/lib/Transforms/Vectorize/VPlanPatternMatch.h
+++ b/llvm/lib/Transforms/Vectorize/VPlanPatternMatch.h
@@ -176,6 +176,32 @@ 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 apint_match {
+ const APInt *&Res;
+
+ apint_match(const APInt *&Res) : Res(Res) {}
+
+ bool match(VPValue *VPV) const {
+ if (!VPV->isLiveIn())
+ return false;
+ Value *V = VPV->getLiveInIRValue();
+ if (!V)
+ return false;
+ const auto *CI = dyn_cast<ConstantInt>(V);
+ if (!CI && V->getType()->isVectorTy())
+ if (const auto *C = dyn_cast<Constant>(V))
+ CI = dyn_cast_or_null<ConstantInt>(
+ C->getSplatValue(/*AllowPoison=*/false));
+ if (!CI)
+ return false;
+ Res = &CI->getValue();
+ return true;
+ }
+};
+
+/// Match an APInt, capturing it if we match.
+inline apint_match m_APInt(const APInt *&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 9996b0167edcb..c71655f08bf49 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());
+ const APInt *Part;
+ if (match(Index,
+ m_VPInstruction<VPInstruction::CanonicalIVIncrementForPart>(
+ m_VPValue(), m_APInt(Part))))
Phis[Part->getZExtValue()] = Phi;
- } else
+ else
// Anything other than a CanonicalIVIncrementForPart is part 0
Phis[0] = Phi;
}
|
lukel97
reviewed
Sep 18, 2025
lukel97
approved these changes
Sep 18, 2025
lukel97
left a comment
Contributor
There was a problem hiding this comment.
Not sure if we will ever need to match and capture an APInt in VPlan but I guess this mirrors PatternMatch.h.
fhahn
reviewed
Sep 18, 2025
fhahn
left a comment
Contributor
There was a problem hiding this comment.
Seems like it would be simpler to first only have a m_ConstantInt instead of adding the extra indirection
ckoparkar
added a commit
to ckoparkar/llvm-project
that referenced
this pull request
Sep 23, 2025
* main: (1562 commits) Document Policy on supporting newer C++ standard in LLVM codebase (llvm#156823) [MLIR][Transform][SMT] Introduce transform.smt.constrain_params (llvm#159450) Reapply "[compiler-rt] Remove %T from shared object substitutions (llvm#155302)" [NFC] [IndVarSimplify] Add non-overflowing usub test (llvm#159683) [Github] Remove separate tools checkout from pr-code workflows (llvm#159967) [clang] fix using enum redecl in template regression (llvm#159996) [DAG] Skip `mstore` combine for `<1 x ty>` vectors (llvm#159915) [mlir] Expose optional `PatternBenefit` to `func` populate functions (NFC) (llvm#159986) [LV] Set correct costs for interleave group members. [clang] ast-dump: use template pattern for `instantiated_from` (llvm#159952) [ARM] ha-alignstack-call.ll - regenerate test checks (llvm#159988) [LLD][MachO] Silence warning when building with MSVC [llvm][Analysis] Silence warning when building with MSVC [LV] Skip select cost for invariant divisors in legacy cost model. [Clang] Fix an error-recovery crash after d1a80de (llvm#159976) [VPlanPatternMatch] Introduce m_ConstantInt (llvm#159558) [GlobalISel] Add G_ABS computeKnownBits (llvm#154413) [gn build] Port 4cabd1e Reland "[clangd] Add feature modules registry" (llvm#154836) [LV] Also handle non-uniform scalarized loads when processing AddrDefs. ...
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
No description provided.