[llvm] 0384f6c - [VPlanPatternMatch] Introduce match functor (NFC) (#159521)
via llvm-commits
llvm-commits at lists.llvm.org
Thu Sep 18 02:36:15 PDT 2025
Author: Ramkumar Ramachandra
Date: 2025-09-18T10:36:12+01:00
New Revision: 0384f6c9dbdcce283088b5207a56b1567590f927
URL: https://github.com/llvm/llvm-project/commit/0384f6c9dbdcce283088b5207a56b1567590f927
DIFF: https://github.com/llvm/llvm-project/commit/0384f6c9dbdcce283088b5207a56b1567590f927.diff
LOG: [VPlanPatternMatch] Introduce match functor (NFC) (#159521)
Follow up on 7fb3a91 ([PatternMatch] Introduce match functor) to
introduce the VPlanPatternMatch version of the match functor to shorten
some idioms.
Co-authored-by: Luke Lau <luke at igalia.com>
Added:
Modified:
llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
llvm/lib/Transforms/Vectorize/VPlanPatternMatch.h
llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp
llvm/lib/Transforms/Vectorize/VPlanVerifier.cpp
Removed:
################################################################################
diff --git a/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp b/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
index fee201ee3523a..8a75fb77f91d6 100644
--- a/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
+++ b/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
@@ -6901,11 +6901,12 @@ static bool planContainsAdditionalSimplifications(VPlan &Plan,
// Unused FOR splices are removed by VPlan transforms, so the VPlan-based
// cost model won't cost it whilst the legacy will.
if (auto *FOR = dyn_cast<VPFirstOrderRecurrencePHIRecipe>(&R)) {
- if (none_of(FOR->users(), [](VPUser *U) {
- auto *VPI = dyn_cast<VPInstruction>(U);
- return VPI && VPI->getOpcode() ==
- VPInstruction::FirstOrderRecurrenceSplice;
- }))
+ using namespace VPlanPatternMatch;
+ if (none_of(
+ FOR->users(),
+ match_fn(
+ m_VPInstruction<VPInstruction::FirstOrderRecurrenceSplice>(
+ m_VPValue(), m_VPValue()))))
return true;
}
// The VPlan-based cost model is more accurate for partial reduction and
diff --git a/llvm/lib/Transforms/Vectorize/VPlanPatternMatch.h b/llvm/lib/Transforms/Vectorize/VPlanPatternMatch.h
index 401a2cbd9a5ca..8f9ce7a74b58b 100644
--- a/llvm/lib/Transforms/Vectorize/VPlanPatternMatch.h
+++ b/llvm/lib/Transforms/Vectorize/VPlanPatternMatch.h
@@ -29,6 +29,19 @@ template <typename Pattern> bool match(VPUser *U, const Pattern &P) {
return R && match(R, P);
}
+template <typename Val, typename Pattern> struct VPMatchFunctor {
+ const Pattern &P;
+ VPMatchFunctor(const Pattern &P) : P(P) {}
+ bool operator()(Val *V) const { return match(V, P); }
+};
+
+/// A match functor that can be used as a UnaryPredicate in functional
+/// algorithms like all_of.
+template <typename Val = VPUser, typename Pattern>
+VPMatchFunctor<Val, Pattern> match_fn(const Pattern &P) {
+ return P;
+}
+
template <typename Class> struct class_match {
template <typename ITy> bool match(ITy *V) const { return isa<Class>(V); }
};
diff --git a/llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp b/llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp
index dcc368933f2a1..9996b0167edcb 100644
--- a/llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp
+++ b/llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp
@@ -1149,11 +1149,10 @@ static void simplifyRecipe(VPRecipeBase &R, VPTypeAnalysis &TypeInfo) {
CmpPredicate Pred;
if (match(A, m_Cmp(Pred, m_VPValue(), m_VPValue()))) {
auto *Cmp = cast<VPRecipeWithIRFlags>(A);
- if (all_of(Cmp->users(), [&Cmp](VPUser *U) {
- return match(U, m_CombineOr(m_Not(m_Specific(Cmp)),
- m_Select(m_Specific(Cmp), m_VPValue(),
- m_VPValue())));
- })) {
+ if (all_of(Cmp->users(),
+ match_fn(m_CombineOr(
+ m_Not(m_Specific(Cmp)),
+ m_Select(m_Specific(Cmp), m_VPValue(), m_VPValue()))))) {
Cmp->setPredicate(CmpInst::getInversePredicate(Pred));
for (VPUser *U : to_vector(Cmp->users())) {
auto *R = cast<VPSingleDefRecipe>(U);
diff --git a/llvm/lib/Transforms/Vectorize/VPlanVerifier.cpp b/llvm/lib/Transforms/Vectorize/VPlanVerifier.cpp
index 99f3bc367a548..92caa0b4e51d5 100644
--- a/llvm/lib/Transforms/Vectorize/VPlanVerifier.cpp
+++ b/llvm/lib/Transforms/Vectorize/VPlanVerifier.cpp
@@ -198,11 +198,11 @@ bool VPlanVerifier::verifyEVLRecipe(const VPInstruction &EVL) const {
}
// EVLIVIncrement is only used by EVLIV & BranchOnCount.
// Having more than two users is unexpected.
+ using namespace llvm::VPlanPatternMatch;
if ((I->getNumUsers() != 1) &&
- (I->getNumUsers() != 2 || none_of(I->users(), [&I](VPUser *U) {
- using namespace llvm::VPlanPatternMatch;
- return match(U, m_BranchOnCount(m_Specific(I), m_VPValue()));
- }))) {
+ (I->getNumUsers() != 2 ||
+ none_of(I->users(), match_fn(m_BranchOnCount(m_Specific(I),
+ m_VPValue()))))) {
errs() << "EVL is used in VPInstruction with multiple users\n";
return false;
}
More information about the llvm-commits
mailing list