[llvm] [VPlan] Allow VPValue in match_fn without needing explicit template arguments. NFC (PR #205748)

Luke Lau via llvm-commits llvm-commits at lists.llvm.org
Thu Jun 25 01:42:15 PDT 2026


https://github.com/lukel97 created https://github.com/llvm/llvm-project/pull/205748

Currently if you want to use match_fn over a range of VPValues, you have to explicitly write match_fn<VPValue> otherwise it will resolve to the VPUser overload.

This changes the functor to be a lambda with an auto argument so match_fn(...) works for both VPValues and VPUsers without explicit templates. The lambda is inlined so there's no indirect function call. vputils::getGEPFlagsForPtr is updated to use the new form.


>From 2c0bb3dce3c5bd9188a1d6ddf8a971e923550a70 Mon Sep 17 00:00:00 2001
From: Luke Lau <luke at igalia.com>
Date: Thu, 25 Jun 2026 16:31:30 +0800
Subject: [PATCH] [VPlan] Allow VPValue in match_fn without needing explicit
 template arguments. NFC

Currently if you want to use match_fn over a range of VPValues, you have to explicitly write match_fn<VPValue> otherwise it will resolve to the VPUser overload.

This changes the functor to be a lambda with an auto argument so match_fn(...) works for both VPValues and VPUsers without explicit templates. The lambda is inlined so there's no indirect function call. vputils::getGEPFlagsForPtr is updated to use the new form.
---
 llvm/lib/Transforms/Vectorize/VPlanPatternMatch.h | 11 +++--------
 llvm/lib/Transforms/Vectorize/VPlanUtils.cpp      |  3 +--
 2 files changed, 4 insertions(+), 10 deletions(-)

diff --git a/llvm/lib/Transforms/Vectorize/VPlanPatternMatch.h b/llvm/lib/Transforms/Vectorize/VPlanPatternMatch.h
index 1f133cbaa95bb..2d2af09b74be1 100644
--- a/llvm/lib/Transforms/Vectorize/VPlanPatternMatch.h
+++ b/llvm/lib/Transforms/Vectorize/VPlanPatternMatch.h
@@ -27,20 +27,15 @@ template <typename Val, typename Pattern> bool match(Val *V, const Pattern &P) {
   return P.match(V);
 }
 
-/// A match functor that can be used as a UnaryPredicate in functional
-/// algorithms like all_of.
-template <typename Val, typename Pattern> auto match_fn(const Pattern &P) {
-  return bind_back<match<Val, Pattern>>(P);
-}
-
 template <typename Pattern> bool match(VPUser *U, const Pattern &P) {
   auto *R = dyn_cast<VPRecipeBase>(U);
   return R && match(R, P);
 }
 
-/// Match functor for VPUser.
+/// A match functor that can be used as a UnaryPredicate in functional
+/// algorithms like all_of.
 template <typename Pattern> auto match_fn(const Pattern &P) {
-  return bind_back<match<Pattern>>(P);
+  return [&P](auto *V) { return match(V, P); };
 }
 
 template <typename Pattern> bool match(VPSingleDefRecipe *R, const Pattern &P) {
diff --git a/llvm/lib/Transforms/Vectorize/VPlanUtils.cpp b/llvm/lib/Transforms/Vectorize/VPlanUtils.cpp
index 7e0f536a63a83..327fdf2332312 100644
--- a/llvm/lib/Transforms/Vectorize/VPlanUtils.cpp
+++ b/llvm/lib/Transforms/Vectorize/VPlanUtils.cpp
@@ -155,8 +155,7 @@ GEPNoWrapFlags vputils::getGEPFlagsForPtr(VPValue *Ptr) {
   while (auto *PtrVPI = dyn_cast<VPInstruction>(Ptr)) {
     unsigned Opcode = PtrVPI->getOpcode();
     if (Opcode == Instruction::GetElementPtr) {
-      if (any_of(drop_begin(PtrVPI->operands()),
-                 [](VPValue *Op) { return !match(Op, m_ZeroInt()); }))
+      if (!all_of(drop_begin(PtrVPI->operands()), match_fn(m_ZeroInt())))
         return PtrVPI->getGEPNoWrapFlags();
       Ptr = PtrVPI->getOperand(0);
       continue;



More information about the llvm-commits mailing list