[llvm] d27d75e - [VPlan] Use createHeaderPHIRecipes in native path (NFCI).
Florian Hahn via llvm-commits
llvm-commits at lists.llvm.org
Tue Jan 13 12:12:30 PST 2026
Author: Florian Hahn
Date: 2026-01-13T20:12:21Z
New Revision: d27d75ee945943698b247393a7f7449f76efafe4
URL: https://github.com/llvm/llvm-project/commit/d27d75ee945943698b247393a7f7449f76efafe4
DIFF: https://github.com/llvm/llvm-project/commit/d27d75ee945943698b247393a7f7449f76efafe4.diff
LOG: [VPlan] Use createHeaderPHIRecipes in native path (NFCI).
Simplify tryToBuildVPlan by using createHeaderPHIRecipes in the native
path as well.
Added:
Modified:
llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp
llvm/lib/Transforms/Vectorize/VPlanTransforms.h
llvm/unittests/Transforms/Vectorize/VPlanHCFGTest.cpp
llvm/unittests/Transforms/Vectorize/VPlanUncountableExitTest.cpp
Removed:
################################################################################
diff --git a/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp b/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
index cdc6ecfa21bcb..f77e35038b84e 100644
--- a/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
+++ b/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
@@ -8647,6 +8647,12 @@ VPlanPtr LoopVectorizationPlanner::tryToBuildVPlan(VFRange &Range) {
auto Plan = VPlanTransforms::buildVPlan0(
OrigLoop, *LI, Legal->getWidestInductionType(),
getDebugLocFromInstOrOperands(Legal->getPrimaryInduction()), PSE);
+
+ VPlanTransforms::createHeaderPhiRecipes(
+ *Plan, PSE, *OrigLoop, Legal->getInductionVars(),
+ MapVector<PHINode *, RecurrenceDescriptor>(),
+ SmallPtrSet<const PHINode *, 1>(), SmallPtrSet<PHINode *, 1>(),
+ /*AllowReordering=*/false);
VPlanTransforms::handleEarlyExits(*Plan,
/*HasUncountableExit*/ false);
VPlanTransforms::addMiddleCheck(*Plan, /*RequiresScalarEpilogue*/ true,
@@ -8657,12 +8663,7 @@ VPlanPtr LoopVectorizationPlanner::tryToBuildVPlan(VFRange &Range) {
for (ElementCount VF : Range)
Plan->addVF(VF);
- if (!VPlanTransforms::tryToConvertVPInstructionsToVPRecipes(
- *Plan,
- [this](PHINode *P) {
- return Legal->getIntOrFpInductionDescriptor(P);
- },
- *TLI))
+ if (!VPlanTransforms::tryToConvertVPInstructionsToVPRecipes(*Plan, *TLI))
return nullptr;
// TODO: IVEndValues are not used yet in the native path, to optimize exit
diff --git a/llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp b/llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp
index b41e04cff6d83..27ebbe9c45ce9 100644
--- a/llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp
+++ b/llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp
@@ -47,10 +47,7 @@ using namespace VPlanPatternMatch;
using namespace SCEVPatternMatch;
bool VPlanTransforms::tryToConvertVPInstructionsToVPRecipes(
- VPlan &Plan,
- function_ref<const InductionDescriptor *(PHINode *)>
- GetIntOrFpInductionDescriptor,
- const TargetLibraryInfo &TLI) {
+ VPlan &Plan, const TargetLibraryInfo &TLI) {
ReversePostOrderTraversal<VPBlockDeepTraversalWrapper<VPBlockBase *>> RPOT(
Plan.getVectorLoopRegion());
@@ -73,25 +70,10 @@ bool VPlanTransforms::tryToConvertVPInstructionsToVPRecipes(
VPRecipeBase *NewRecipe = nullptr;
if (auto *PhiR = dyn_cast<VPPhi>(&Ingredient)) {
auto *Phi = cast<PHINode>(PhiR->getUnderlyingValue());
- const auto *II = GetIntOrFpInductionDescriptor(Phi);
- if (!II) {
- NewRecipe = new VPWidenPHIRecipe(Phi, nullptr, PhiR->getDebugLoc());
- for (VPValue *Op : PhiR->operands())
- NewRecipe->addOperand(Op);
- } else {
- VPIRValue *Start = Plan.getOrAddLiveIn(II->getStartValue());
- VPValue *Step =
- vputils::getOrCreateVPValueForSCEVExpr(Plan, II->getStep());
- // It is always safe to copy over the NoWrap and FastMath flags. In
- // particular, when folding tail by masking, the masked-off lanes are
- // never used, so it is safe.
- VPIRFlags Flags = vputils::getFlagsFromIndDesc(*II);
- NewRecipe = new VPWidenIntOrFpInductionRecipe(
- Phi, Start, Step, &Plan.getVF(), *II, Flags,
- Ingredient.getDebugLoc());
- }
- } else {
- auto *VPI = cast<VPInstruction>(&Ingredient);
+ NewRecipe = new VPWidenPHIRecipe(Phi, nullptr, PhiR->getDebugLoc());
+ for (VPValue *Op : PhiR->operands())
+ NewRecipe->addOperand(Op);
+ } else if (auto *VPI = dyn_cast<VPInstruction>(&Ingredient)) {
assert(!isa<PHINode>(Inst) && "phis should be handled above");
// Create VPWidenMemoryRecipe for loads and stores.
if (LoadInst *Load = dyn_cast<LoadInst>(Inst)) {
@@ -123,6 +105,10 @@ bool VPlanTransforms::tryToConvertVPInstructionsToVPRecipes(
NewRecipe = new VPWidenRecipe(*Inst, Ingredient.operands(), *VPI,
*VPI, Ingredient.getDebugLoc());
}
+ } else {
+ assert(isa<VPWidenIntOrFpInductionRecipe>(&Ingredient) &&
+ "inductions must be created earlier");
+ continue;
}
NewRecipe->insertBefore(&Ingredient);
diff --git a/llvm/lib/Transforms/Vectorize/VPlanTransforms.h b/llvm/lib/Transforms/Vectorize/VPlanTransforms.h
index f4ecee4e7f04f..6088252c4cf91 100644
--- a/llvm/lib/Transforms/Vectorize/VPlanTransforms.h
+++ b/llvm/lib/Transforms/Vectorize/VPlanTransforms.h
@@ -161,11 +161,9 @@ struct VPlanTransforms {
/// Replaces the VPInstructions in \p Plan with corresponding
/// widen recipes. Returns false if any VPInstructions could not be converted
/// to a wide recipe if needed.
- LLVM_ABI_FOR_TEST static bool tryToConvertVPInstructionsToVPRecipes(
- VPlan &Plan,
- function_ref<const InductionDescriptor *(PHINode *)>
- GetIntOrFpInductionDescriptor,
- const TargetLibraryInfo &TLI);
+ LLVM_ABI_FOR_TEST static bool
+ tryToConvertVPInstructionsToVPRecipes(VPlan &Plan,
+ const TargetLibraryInfo &TLI);
/// Try to legalize reductions with multiple in-loop uses. Currently only
/// min/max reductions used by FindLastIV reductions are supported. Otherwise
diff --git a/llvm/unittests/Transforms/Vectorize/VPlanHCFGTest.cpp b/llvm/unittests/Transforms/Vectorize/VPlanHCFGTest.cpp
index 127e830b1bc14..f5634bfa97402 100644
--- a/llvm/unittests/Transforms/Vectorize/VPlanHCFGTest.cpp
+++ b/llvm/unittests/Transforms/Vectorize/VPlanHCFGTest.cpp
@@ -203,8 +203,7 @@ TEST_F(VPlanHCFGTest, testVPInstructionToVPRecipesInner) {
->appendRecipe(new VPInstruction(
VPInstruction::BranchOnCond,
{Plan->getOrAddLiveIn(ConstantInt::getTrue(F->getContext()))}));
- VPlanTransforms::tryToConvertVPInstructionsToVPRecipes(
- *Plan, [](PHINode *P) { return nullptr; }, TLI);
+ VPlanTransforms::tryToConvertVPInstructionsToVPRecipes(*Plan, TLI);
VPBlockBase *Entry = Plan->getEntry()->getEntryBasicBlock();
EXPECT_EQ(0u, Entry->getNumPredecessors());
diff --git a/llvm/unittests/Transforms/Vectorize/VPlanUncountableExitTest.cpp b/llvm/unittests/Transforms/Vectorize/VPlanUncountableExitTest.cpp
index b89d378c02660..270537a333b8e 100644
--- a/llvm/unittests/Transforms/Vectorize/VPlanUncountableExitTest.cpp
+++ b/llvm/unittests/Transforms/Vectorize/VPlanUncountableExitTest.cpp
@@ -47,8 +47,7 @@ TEST_F(VPUncountableExitTest, FindUncountableExitRecipes) {
Function *F = M.getFunction("f");
BasicBlock *LoopHeader = F->getEntryBlock().getSingleSuccessor();
auto Plan = buildVPlan(LoopHeader, /*HasUncountableExit=*/true);
- VPlanTransforms::tryToConvertVPInstructionsToVPRecipes(
- *Plan, [](PHINode *P) { return nullptr; }, *TLI);
+ VPlanTransforms::tryToConvertVPInstructionsToVPRecipes(*Plan, *TLI);
VPlanTransforms::runPass(VPlanTransforms::optimize, *Plan);
SmallVector<VPRecipeBase *> Recipes;
@@ -84,8 +83,7 @@ TEST_F(VPUncountableExitTest, NoUncountableExit) {
Function *F = M.getFunction("f");
BasicBlock *LoopHeader = F->getEntryBlock().getSingleSuccessor();
auto Plan = buildVPlan(LoopHeader);
- VPlanTransforms::tryToConvertVPInstructionsToVPRecipes(
- *Plan, [](PHINode *P) { return nullptr; }, *TLI);
+ VPlanTransforms::tryToConvertVPInstructionsToVPRecipes(*Plan, *TLI);
VPlanTransforms::runPass(VPlanTransforms::optimize, *Plan);
SmallVector<VPRecipeBase *> Recipes;
More information about the llvm-commits
mailing list