[llvm] [VPlan] Simplify and strengthen Replicate::execute (NFC) (PR #196055)
Ramkumar Ramachandra via llvm-commits
llvm-commits at lists.llvm.org
Wed May 6 05:32:36 PDT 2026
https://github.com/artagnon created https://github.com/llvm/llvm-project/pull/196055
None
>From fecd494fcdd3de1549a061cdc5e42b44b24dc099 Mon Sep 17 00:00:00 2001
From: Ramkumar Ramachandra <artagnon at tenstorrent.com>
Date: Wed, 6 May 2026 13:22:53 +0100
Subject: [PATCH] [VPlan] Simplify and strengthen Replicate::execute (NFC)
---
.../lib/Transforms/Vectorize/VPlanRecipes.cpp | 61 +++++--------------
1 file changed, 15 insertions(+), 46 deletions(-)
diff --git a/llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp b/llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp
index d04b5edcfc212..1f560fccb71ea 100644
--- a/llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp
+++ b/llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp
@@ -3263,23 +3263,16 @@ void VPReductionEVLRecipe::printRecipe(raw_ostream &O, const Twine &Indent,
#endif
-/// A helper function to scalarize a single Instruction in the innermost loop.
-/// Generates a sequence of scalar instances for lane \p Lane. Uses the VPValue
-/// operands from \p RepRecipe instead of \p Instr's operands.
-static void scalarizeInstruction(const Instruction *Instr,
- VPReplicateRecipe *RepRecipe,
- const VPLane &Lane, VPTransformState &State) {
- assert((!Instr->getType()->isAggregateType() ||
- canVectorizeTy(Instr->getType())) &&
- "Expected vectorizable or non-aggregate type.");
-
- // Does this instruction return a value ?
- bool IsVoidRetTy = Instr->getType()->isVoidTy();
-
+void VPReplicateRecipe::execute(VPTransformState &State) {
+ assert(!State.Lane && !getRegion() && "Replicate regions must be dissolved before ::execute");
+ assert(IsSingleScalar && "VPReplicateRecipes outside replicate regions "
+ "must have already been unrolled");
+ State.setDebugLocFrom(getDebugLoc());
+ auto *Instr = getUnderlyingInstr();
Instruction *Cloned = Instr->clone();
- if (!IsVoidRetTy) {
+ if (!Instr->getType()->isVoidTy()) {
Cloned->setName(Instr->getName() + ".cloned");
- Type *ResultTy = State.TypeAnalysis.inferScalarType(RepRecipe);
+ Type *ResultTy = State.TypeAnalysis.inferScalarType(this);
// The operands of the replicate recipe may have been narrowed, resulting in
// a narrower result type. Update the type of the cloned instruction to the
// correct type.
@@ -3287,49 +3280,25 @@ static void scalarizeInstruction(const Instruction *Instr,
Cloned->mutateType(ResultTy);
}
- RepRecipe->applyFlags(*Cloned);
- RepRecipe->applyMetadata(*Cloned);
-
- if (RepRecipe->hasPredicate())
- cast<CmpInst>(Cloned)->setPredicate(RepRecipe->getPredicate());
+ applyFlags(*Cloned);
+ applyMetadata(*Cloned);
- if (auto DL = RepRecipe->getDebugLoc())
- State.setDebugLocFrom(DL);
+ if (hasPredicate())
+ cast<CmpInst>(Cloned)->setPredicate(getPredicate());
// Replace the operands of the cloned instructions with their scalar
// equivalents in the new loop.
- for (const auto &I : enumerate(RepRecipe->operands())) {
- auto InputLane = Lane;
- VPValue *Operand = I.value();
- if (vputils::isSingleScalar(Operand))
- InputLane = VPLane::getFirstLane();
- Cloned->setOperand(I.index(), State.get(Operand, InputLane));
- }
+ for (const auto &[Idx, V] : enumerate(operands()))
+ Cloned->setOperand(Idx, State.get(V, true));
// Place the cloned scalar in the new loop.
State.Builder.Insert(Cloned);
- State.set(RepRecipe, Cloned, Lane);
+ State.set(this, Cloned, true);
// If we just cloned a new assumption, add it the assumption cache.
if (auto *II = dyn_cast<AssumeInst>(Cloned))
State.AC->registerAssumption(II);
-
- assert(
- (RepRecipe->getRegion() ||
- !RepRecipe->getParent()->getPlan()->getVectorLoopRegion() ||
- all_of(RepRecipe->operands(),
- [](VPValue *Op) { return Op->isDefinedOutsideLoopRegions(); })) &&
- "Expected a recipe is either within a region or all of its operands "
- "are defined outside the vectorized region.");
-}
-
-void VPReplicateRecipe::execute(VPTransformState &State) {
- assert(!State.Lane && "replicate regions must be dissolved before ::execute");
- assert(IsSingleScalar && "VPReplicateRecipes outside replicate regions "
- "must have already been unrolled");
- Instruction *UI = getUnderlyingInstr();
- scalarizeInstruction(UI, this, VPLane(0), State);
}
/// Returns a SCEV expression for \p Ptr if it is a pointer computation for
More information about the llvm-commits
mailing list