[llvm] [VPlan] Add VPRegionBlock::getEntryBranchOnMask helper (NFC) (PR #212060)
Florian Hahn via llvm-commits
llvm-commits at lists.llvm.org
Sat Jul 25 13:11:27 PDT 2026
https://github.com/fhahn created https://github.com/llvm/llvm-project/pull/212060
Add an accessor returning the VPBranchOnMaskRecipe guarding a replicate region, i.e. the sole recipe of the region's entry block.
>From 91eb4fadfa52eb43c32fd14eb5798d34503fc55f Mon Sep 17 00:00:00 2001
From: Florian Hahn <flo at fhahn.com>
Date: Fri, 24 Jul 2026 14:52:19 +0100
Subject: [PATCH] [VPlan] Add VPRegionBlock::getEntryBranchOnMask helper (NFC)
Add an accessor returning the VPBranchOnMaskRecipe guarding a replicate
region, i.e. the sole recipe of the region's entry block.
---
llvm/lib/Transforms/Vectorize/VPlan.cpp | 7 +++++++
llvm/lib/Transforms/Vectorize/VPlan.h | 8 ++++++++
llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp | 15 ++-------------
3 files changed, 17 insertions(+), 13 deletions(-)
diff --git a/llvm/lib/Transforms/Vectorize/VPlan.cpp b/llvm/lib/Transforms/Vectorize/VPlan.cpp
index 5f51e7638fa6b..ed3ac2eb41b39 100644
--- a/llvm/lib/Transforms/Vectorize/VPlan.cpp
+++ b/llvm/lib/Transforms/Vectorize/VPlan.cpp
@@ -738,6 +738,13 @@ VPBlockUtils::cloneFrom(VPBlockBase *Entry) {
Exiting ? Old2NewVPBlocks[Exiting] : nullptr);
}
+const VPBranchOnMaskRecipe *VPRegionBlock::getEntryBranchOnMask() const {
+ const auto *EntryBB = cast<VPBasicBlock>(getEntry());
+ assert(isReplicator() && EntryBB && EntryBB->size() == 1 &&
+ "not a valid replicating region");
+ return cast<VPBranchOnMaskRecipe>(&EntryBB->front());
+}
+
VPRegionBlock *VPRegionBlock::clone() {
const auto &[NewEntry, NewExiting] = VPBlockUtils::cloneFrom(getEntry());
VPlan &Plan = *getPlan();
diff --git a/llvm/lib/Transforms/Vectorize/VPlan.h b/llvm/lib/Transforms/Vectorize/VPlan.h
index b0d012e80b403..4cb214ac0a257 100644
--- a/llvm/lib/Transforms/Vectorize/VPlan.h
+++ b/llvm/lib/Transforms/Vectorize/VPlan.h
@@ -4676,6 +4676,14 @@ class LLVM_ABI_FOR_TEST VPRegionBlock : public VPBlockBase {
/// instances of output IR corresponding to its VPBlockBases.
bool isReplicator() const { return !CanIVInfo; }
+ /// Return the VPBranchOnMaskRecipe from the entry block of this replicating
+ /// region.
+ const VPBranchOnMaskRecipe *getEntryBranchOnMask() const;
+ VPBranchOnMaskRecipe *getEntryBranchOnMask() {
+ return const_cast<VPBranchOnMaskRecipe *>(
+ static_cast<const VPRegionBlock *>(this)->getEntryBranchOnMask());
+ }
+
/// The method which generates the output IR instructions that correspond to
/// this VPRegionBlock, thereby "executing" the VPlan.
void execute(VPTransformState *State) override;
diff --git a/llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp b/llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp
index 5921b9e88d9b5..e5035c4e7767f 100644
--- a/llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp
+++ b/llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp
@@ -412,17 +412,6 @@ static bool sinkScalarOperands(VPlan &Plan) {
return Changed;
}
-/// If \p R is a region with a VPBranchOnMaskRecipe in the entry block, return
-/// the mask.
-static VPValue *getPredicatedMask(VPRegionBlock *R) {
- auto *EntryBB = dyn_cast<VPBasicBlock>(R->getEntry());
- if (!EntryBB || EntryBB->size() != 1 ||
- !isa<VPBranchOnMaskRecipe>(EntryBB->begin()))
- return nullptr;
-
- return cast<VPBranchOnMaskRecipe>(&*EntryBB->begin())->getOperand(0);
-}
-
/// If \p R is a triangle region, return the 'then' block of the triangle.
static VPBasicBlock *getPredicatedThenBlock(VPRegionBlock *R) {
auto *EntryBB = cast<VPBasicBlock>(R->getEntry());
@@ -467,8 +456,8 @@ static bool mergeReplicateRegionsIntoSuccessors(VPlan &Plan) {
if (!Region2 || !Region2->isReplicator())
continue;
- VPValue *Mask1 = getPredicatedMask(Region1);
- VPValue *Mask2 = getPredicatedMask(Region2);
+ VPValue *Mask1 = Region1->getEntryBranchOnMask()->getOperand(0);
+ VPValue *Mask2 = Region2->getEntryBranchOnMask()->getOperand(0);
if (!Mask1 || Mask1 != Mask2)
continue;
More information about the llvm-commits
mailing list