Skip to content

Commit 22437d5

Browse files
committed
[NFC][LoopVectorize] Clean up some code around getting a context
There are several places in LoopVectorize where we do more work than necessary to obtain a LLVMContext. I've tried to make the code more efficient.
1 parent 66b2820 commit 22437d5

File tree

1 file changed

+13
-15
lines changed

1 file changed

+13
-15
lines changed

llvm/lib/Transforms/Vectorize/LoopVectorize.cpp

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -7513,7 +7513,7 @@ DenseMap<const SCEV *, Value *> LoopVectorizationPlanner::executePlan(
75137513
// TODO: Move to VPlan transform stage once the transition to the VPlan-based
75147514
// cost model is complete for better cost estimates.
75157515
VPlanTransforms::unrollByUF(BestVPlan, BestUF,
7516-
OrigLoop->getHeader()->getModule()->getContext());
7516+
OrigLoop->getHeader()->getContext());
75177517
VPlanTransforms::optimizeForVFAndUF(BestVPlan, BestVF, BestUF, PSE);
75187518

75197519
LLVM_DEBUG(dbgs() << "Executing best plan with VF=" << BestVF
@@ -8344,8 +8344,8 @@ VPWidenCallRecipe *VPRecipeBuilder::tryToWidenCall(CallInst *CI,
83448344
if (Legal->isMaskRequired(CI))
83458345
Mask = getBlockInMask(CI->getParent());
83468346
else
8347-
Mask = Plan.getOrAddLiveIn(ConstantInt::getTrue(
8348-
IntegerType::getInt1Ty(Variant->getFunctionType()->getContext())));
8347+
Mask = Plan.getOrAddLiveIn(
8348+
ConstantInt::getTrue(IntegerType::getInt1Ty(CI->getContext())));
83498349

83508350
Ops.insert(Ops.begin() + *MaskPos, Mask);
83518351
}
@@ -8713,15 +8713,13 @@ static SetVector<VPIRInstruction *> collectUsersInExitBlock(
87138713
// Add exit values to \p Plan. Extracts are added for each entry in \p
87148714
// ExitUsersToFix if needed and their operands are updated.
87158715
static void
8716-
addUsersInExitBlock(VPlan &Plan,
8716+
addUsersInExitBlock(VPlan &Plan, LLVMContext &Ctx,
87178717
const SetVector<VPIRInstruction *> &ExitUsersToFix) {
87188718
if (ExitUsersToFix.empty())
87198719
return;
87208720

87218721
auto *MiddleVPBB =
87228722
cast<VPBasicBlock>(Plan.getVectorLoopRegion()->getSingleSuccessor());
8723-
BasicBlock *ExitBB =
8724-
cast<VPIRBasicBlock>(MiddleVPBB->getSuccessors()[0])->getIRBasicBlock();
87258723
VPBuilder B(MiddleVPBB, MiddleVPBB->getFirstNonPhi());
87268724

87278725
// Introduce extract for exiting values and update the VPIRInstructions
@@ -8732,10 +8730,9 @@ addUsersInExitBlock(VPlan &Plan,
87328730
if (V->isLiveIn())
87338731
continue;
87348732

8735-
VPValue *Ext = B.createNaryOp(
8736-
VPInstruction::ExtractFromEnd,
8737-
{V, Plan.getOrAddLiveIn(ConstantInt::get(
8738-
IntegerType::get(ExitBB->getContext(), 32), 1))});
8733+
VPValue *Ext = B.createNaryOp(VPInstruction::ExtractFromEnd,
8734+
{V, Plan.getOrAddLiveIn(ConstantInt::get(
8735+
IntegerType::get(Ctx, 32), 1))});
87398736
ExitIRI->setOperand(0, Ext);
87408737
}
87418738
}
@@ -8898,9 +8895,10 @@ LoopVectorizationPlanner::tryToBuildVPlanWithVPRecipes(VFRange &Range) {
88988895
return !CM.requiresScalarEpilogue(VF.isVector());
88998896
},
89008897
Range);
8901-
VPlanPtr Plan = VPlan::createInitialVPlan(Legal->getWidestInductionType(),
8902-
PSE, RequiresScalarEpilogueCheck,
8903-
CM.foldTailByMasking(), OrigLoop);
8898+
Type *WidestIndTy = Legal->getWidestInductionType();
8899+
VPlanPtr Plan =
8900+
VPlan::createInitialVPlan(WidestIndTy, PSE, RequiresScalarEpilogueCheck,
8901+
CM.foldTailByMasking(), OrigLoop);
89048902

89058903
// Don't use getDecisionAndClampRange here, because we don't know the UF
89068904
// so this function is better to be conservative, rather than to split
@@ -8915,7 +8913,7 @@ LoopVectorizationPlanner::tryToBuildVPlanWithVPRecipes(VFRange &Range) {
89158913
// When not folding the tail, we know that the induction increment will not
89168914
// overflow.
89178915
bool HasNUW = Style == TailFoldingStyle::None;
8918-
addCanonicalIVRecipes(*Plan, Legal->getWidestInductionType(), HasNUW, DL);
8916+
addCanonicalIVRecipes(*Plan, WidestIndTy, HasNUW, DL);
89198917

89208918
VPRecipeBuilder RecipeBuilder(*Plan, OrigLoop, TLI, Legal, CM, PSE, Builder);
89218919

@@ -9047,7 +9045,7 @@ LoopVectorizationPlanner::tryToBuildVPlanWithVPRecipes(VFRange &Range) {
90479045
SetVector<VPIRInstruction *> ExitUsersToFix = collectUsersInExitBlock(
90489046
OrigLoop, RecipeBuilder, *Plan, Legal->getInductionVars());
90499047
addLiveOutsForFirstOrderRecurrences(*Plan, ExitUsersToFix);
9050-
addUsersInExitBlock(*Plan, ExitUsersToFix);
9048+
addUsersInExitBlock(*Plan, WidestIndTy->getContext(), ExitUsersToFix);
90519049

90529050
// ---------------------------------------------------------------------------
90539051
// Transform initial VPlan: Apply previously taken decisions, in order, to

0 commit comments

Comments
 (0)