[llvm] [VPlan] Introduce m_Branch matcher (NFC) (PR #207383)
Ramkumar Ramachandra via llvm-commits
llvm-commits at lists.llvm.org
Fri Jul 3 05:59:55 PDT 2026
https://github.com/artagnon updated https://github.com/llvm/llvm-project/pull/207383
>From 3555ce22df0ba4ab6ac2038bfdaff4f95923b7d1 Mon Sep 17 00:00:00 2001
From: Ramkumar Ramachandra <artagnon at tenstorrent.com>
Date: Fri, 3 Jul 2026 13:24:07 +0100
Subject: [PATCH 1/2] [VPlan] Introduce m_BrTerminator matcher (NFC)
---
.../Transforms/Vectorize/VPlanPatternMatch.h | 24 +++++++++++--------
.../Transforms/Vectorize/VPlanVerifier.cpp | 9 ++-----
2 files changed, 16 insertions(+), 17 deletions(-)
diff --git a/llvm/lib/Transforms/Vectorize/VPlanPatternMatch.h b/llvm/lib/Transforms/Vectorize/VPlanPatternMatch.h
index e2e08c50d06e8..5fcbac084979b 100644
--- a/llvm/lib/Transforms/Vectorize/VPlanPatternMatch.h
+++ b/llvm/lib/Transforms/Vectorize/VPlanPatternMatch.h
@@ -377,6 +377,20 @@ m_BranchOnTwoConds(const Op0_t &Op0, const Op1_t &Op1) {
return m_VPInstruction<VPInstruction::BranchOnTwoConds>(Op0, Op1);
}
+inline VPInstruction_match<VPInstruction::BranchOnCount> m_BranchOnCount() {
+ return m_VPInstruction<VPInstruction::BranchOnCount>();
+}
+
+template <typename Op0_t, typename Op1_t>
+inline VPInstruction_match<VPInstruction::BranchOnCount, Op0_t, Op1_t>
+m_BranchOnCount(const Op0_t &Op0, const Op1_t &Op1) {
+ return m_VPInstruction<VPInstruction::BranchOnCount>(Op0, Op1);
+}
+
+inline auto m_BrTerminator() {
+ return m_CombineOr(m_BranchOnCond(), m_BranchOnCount(), m_BranchOnTwoConds());
+}
+
template <typename Op0_t>
inline VPInstruction_match<VPInstruction::Broadcast, Op0_t>
m_Broadcast(const Op0_t &Op0) {
@@ -439,16 +453,6 @@ m_ActiveLaneMask(const Op0_t &Op0, const Op1_t &Op1, const Op2_t &Op2) {
return m_VPInstruction<VPInstruction::ActiveLaneMask>(Op0, Op1, Op2);
}
-inline VPInstruction_match<VPInstruction::BranchOnCount> m_BranchOnCount() {
- return m_VPInstruction<VPInstruction::BranchOnCount>();
-}
-
-template <typename Op0_t, typename Op1_t>
-inline VPInstruction_match<VPInstruction::BranchOnCount, Op0_t, Op1_t>
-m_BranchOnCount(const Op0_t &Op0, const Op1_t &Op1) {
- return m_VPInstruction<VPInstruction::BranchOnCount>(Op0, Op1);
-}
-
inline VPInstruction_match<VPInstruction::AnyOf> m_AnyOf() {
return m_VPInstruction<VPInstruction::AnyOf>();
}
diff --git a/llvm/lib/Transforms/Vectorize/VPlanVerifier.cpp b/llvm/lib/Transforms/Vectorize/VPlanVerifier.cpp
index 362bfe92f573e..6a3df2728bb4a 100644
--- a/llvm/lib/Transforms/Vectorize/VPlanVerifier.cpp
+++ b/llvm/lib/Transforms/Vectorize/VPlanVerifier.cpp
@@ -370,10 +370,7 @@ bool VPlanVerifier::verifyBlock(const VPBlockBase *VPB) {
}
if (VPBlockUtils::isLatch(VPBB, VPDT)) {
- auto BranchTerminator =
- m_CombineOr(m_BranchOnCond(),
- m_CombineOr(m_BranchOnCount(), m_BranchOnTwoConds()));
- if (!match(VPBB->getTerminator(), BranchTerminator)) {
+ if (!match(VPBB->getTerminator(), m_BrTerminator())) {
errs() << "Latch block must have a branch terminator!\n";
return false;
}
@@ -506,9 +503,7 @@ bool VPlanVerifier::verify(const VPlan &Plan) {
}
auto *LastInst = dyn_cast<VPInstruction>(std::prev(Exiting->end()));
- if (!match(LastInst, m_CombineOr(m_BranchOnCond(),
- m_CombineOr(m_BranchOnCount(),
- m_BranchOnTwoConds())))) {
+ if (!match(LastInst, m_BrTerminator())) {
errs() << "VPlan vector loop exit must end with BranchOnCount, "
"BranchOnCond, or BranchOnTwoConds VPInstruction\n";
return false;
>From ef40f5af84d75a712a14f7f3a991ea7a5d02b30a Mon Sep 17 00:00:00 2001
From: Ramkumar Ramachandra <artagnon at tenstorrent.com>
Date: Fri, 3 Jul 2026 13:58:32 +0100
Subject: [PATCH 2/2] [VPlan] Rename to m_Branch
---
llvm/lib/Transforms/Vectorize/VPlanPatternMatch.h | 2 +-
llvm/lib/Transforms/Vectorize/VPlanVerifier.cpp | 4 ++--
2 files changed, 3 insertions(+), 3 deletions(-)
diff --git a/llvm/lib/Transforms/Vectorize/VPlanPatternMatch.h b/llvm/lib/Transforms/Vectorize/VPlanPatternMatch.h
index 5fcbac084979b..78c0e994be17a 100644
--- a/llvm/lib/Transforms/Vectorize/VPlanPatternMatch.h
+++ b/llvm/lib/Transforms/Vectorize/VPlanPatternMatch.h
@@ -387,7 +387,7 @@ m_BranchOnCount(const Op0_t &Op0, const Op1_t &Op1) {
return m_VPInstruction<VPInstruction::BranchOnCount>(Op0, Op1);
}
-inline auto m_BrTerminator() {
+inline auto m_Branch() {
return m_CombineOr(m_BranchOnCond(), m_BranchOnCount(), m_BranchOnTwoConds());
}
diff --git a/llvm/lib/Transforms/Vectorize/VPlanVerifier.cpp b/llvm/lib/Transforms/Vectorize/VPlanVerifier.cpp
index 6a3df2728bb4a..fea0c47c321ed 100644
--- a/llvm/lib/Transforms/Vectorize/VPlanVerifier.cpp
+++ b/llvm/lib/Transforms/Vectorize/VPlanVerifier.cpp
@@ -370,7 +370,7 @@ bool VPlanVerifier::verifyBlock(const VPBlockBase *VPB) {
}
if (VPBlockUtils::isLatch(VPBB, VPDT)) {
- if (!match(VPBB->getTerminator(), m_BrTerminator())) {
+ if (!match(VPBB->getTerminator(), m_Branch())) {
errs() << "Latch block must have a branch terminator!\n";
return false;
}
@@ -503,7 +503,7 @@ bool VPlanVerifier::verify(const VPlan &Plan) {
}
auto *LastInst = dyn_cast<VPInstruction>(std::prev(Exiting->end()));
- if (!match(LastInst, m_BrTerminator())) {
+ if (!match(LastInst, m_Branch())) {
errs() << "VPlan vector loop exit must end with BranchOnCount, "
"BranchOnCond, or BranchOnTwoConds VPInstruction\n";
return false;
More information about the llvm-commits
mailing list