[llvm] ff94721 - [VPlan] Add VPBuilder methods to create (First|Last)ActiveLane (NFC). (#195479)
via llvm-commits
llvm-commits at lists.llvm.org
Sat May 2 14:00:18 PDT 2026
Author: Florian Hahn
Date: 2026-05-02T21:00:13Z
New Revision: ff94721733442acfa1ee9d818747ed8b90d92672
URL: https://github.com/llvm/llvm-project/commit/ff94721733442acfa1ee9d818747ed8b90d92672
DIFF: https://github.com/llvm/llvm-project/commit/ff94721733442acfa1ee9d818747ed8b90d92672.diff
LOG: [VPlan] Add VPBuilder methods to create (First|Last)ActiveLane (NFC). (#195479)
Add dedicaed helpers to builder to slightly simplify code a use-sites.
Added:
Modified:
llvm/lib/Transforms/Vectorize/LoopVectorizationPlanner.h
llvm/lib/Transforms/Vectorize/VPlanConstruction.cpp
llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp
Removed:
################################################################################
diff --git a/llvm/lib/Transforms/Vectorize/LoopVectorizationPlanner.h b/llvm/lib/Transforms/Vectorize/LoopVectorizationPlanner.h
index 7bdd5a3b34e8e..814a414a52ac8 100644
--- a/llvm/lib/Transforms/Vectorize/LoopVectorizationPlanner.h
+++ b/llvm/lib/Transforms/Vectorize/LoopVectorizationPlanner.h
@@ -201,6 +201,20 @@ class VPBuilder {
Opcode, Operands, ResultTy, Flags, {}, DL, Name));
}
+ VPInstruction *createFirstActiveLane(ArrayRef<VPValue *> Masks,
+ DebugLoc DL = DebugLoc::getUnknown(),
+ const Twine &Name = "") {
+ return tryInsertInstruction(new VPInstruction(
+ VPInstruction::FirstActiveLane, Masks, {}, {}, DL, Name));
+ }
+
+ VPInstruction *createLastActiveLane(ArrayRef<VPValue *> Masks,
+ DebugLoc DL = DebugLoc::getUnknown(),
+ const Twine &Name = "") {
+ return tryInsertInstruction(new VPInstruction(VPInstruction::LastActiveLane,
+ Masks, {}, {}, DL, Name));
+ }
+
VPInstruction *createOverflowingOp(
unsigned Opcode, ArrayRef<VPValue *> Operands,
VPRecipeWithIRFlags::WrapFlagsTy WrapFlags = {false, false},
diff --git a/llvm/lib/Transforms/Vectorize/VPlanConstruction.cpp b/llvm/lib/Transforms/Vectorize/VPlanConstruction.cpp
index e4f2ae41fd468..e20d5d947ac54 100644
--- a/llvm/lib/Transforms/Vectorize/VPlanConstruction.cpp
+++ b/llvm/lib/Transforms/Vectorize/VPlanConstruction.cpp
@@ -1384,8 +1384,7 @@ void VPlanTransforms::foldTailByMasking(VPlan &Plan) {
continue;
// Compute the index of the last active lane.
- VPValue *LastActiveLane =
- Builder.createNaryOp(VPInstruction::LastActiveLane, HeaderMask);
+ VPValue *LastActiveLane = Builder.createLastActiveLane(HeaderMask);
auto *Ext =
Builder.createNaryOp(VPInstruction::ExtractLane, {LastActiveLane, Op});
R.getVPSingleValue()->replaceAllUsesWith(Ext);
diff --git a/llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp b/llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp
index 9b34bd1f092a0..6f349a96a92d3 100644
--- a/llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp
+++ b/llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp
@@ -1057,8 +1057,7 @@ static VPValue *optimizeEarlyExitInductionUser(VPlan &Plan,
VPBuilder B(cast<VPBasicBlock>(PredVPBB));
DebugLoc DL = cast<VPInstruction>(Op)->getDebugLoc();
- VPValue *FirstActiveLane =
- B.createNaryOp(VPInstruction::FirstActiveLane, Mask, DL);
+ VPValue *FirstActiveLane = B.createFirstActiveLane(Mask, DL);
Type *FirstActiveLaneType = TypeInfo.inferScalarType(FirstActiveLane);
FirstActiveLane = B.createScalarZExtOrTrunc(FirstActiveLane, CanonicalIVType,
FirstActiveLaneType, DL);
@@ -3968,9 +3967,8 @@ void VPlanTransforms::convertToConcreteRecipes(VPlan &Plan) {
}
// Create FirstActiveLane on the inverted masks.
- VPValue *FirstInactiveLane = Builder.createNaryOp(
- VPInstruction::FirstActiveLane, NotMasks,
- LastActiveL->getDebugLoc(), "first.inactive.lane");
+ VPValue *FirstInactiveLane = Builder.createFirstActiveLane(
+ NotMasks, LastActiveL->getDebugLoc(), "first.inactive.lane");
// Subtract 1 to get the last active lane.
VPValue *One =
@@ -4165,9 +4163,8 @@ void VPlanTransforms::handleUncountableEarlyExits(VPlan &Plan,
Exits.size() == 1 ? VectorEarlyExitVPBBs[0]
: Plan.createVPBasicBlock("vector.early.exit.check");
VPBuilder DispatchBuilder(DispatchVPBB, DispatchVPBB->begin());
- VPValue *FirstActiveLane =
- DispatchBuilder.createNaryOp(VPInstruction::FirstActiveLane, {Combined},
- DebugLoc::getUnknown(), "first.active.lane");
+ VPValue *FirstActiveLane = DispatchBuilder.createFirstActiveLane(
+ {Combined}, DebugLoc::getUnknown(), "first.active.lane");
// For each early exit, disconnect the original exiting block
// (early.exiting.I) from the exit block (ir-bb<exit.I>) and route through a
More information about the llvm-commits
mailing list