Skip to content

Commit 8c37880

Browse files
fixup! add live outs to vplan instead of manual fixup
1 parent 3337483 commit 8c37880

File tree

1 file changed

+9
-24
lines changed

1 file changed

+9
-24
lines changed

llvm/lib/Transforms/Vectorize/LoopVectorize.cpp

Lines changed: 9 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -500,10 +500,6 @@ class InnerLoopVectorizer {
500500
/// Fix the vectorized code, taking care of header phi's, and more.
501501
void fixVectorizedLoop(VPTransformState &State);
502502

503-
/// For all vectorized CSAs, replace uses of live-out scalar from the orignal
504-
/// loop with the extracted scalar from the vector loop for.
505-
void fixCSALiveOuts(VPTransformState &State, VPlan &Plan);
506-
507503
// Return true if any runtime check is added.
508504
bool areSafetyChecksAdded() { return AddedSafetyChecks; }
509505

@@ -2943,25 +2939,6 @@ LoopVectorizationCostModel::getVectorIntrinsicCost(CallInst *CI,
29432939
TargetTransformInfo::TCK_RecipThroughput);
29442940
}
29452941

2946-
void InnerLoopVectorizer::fixCSALiveOuts(VPTransformState &State, VPlan &Plan) {
2947-
for (const auto &CSA : Plan.getCSAStates()) {
2948-
VPCSADataUpdateRecipe *VPDataUpdate = CSA.second->getDataUpdate();
2949-
assert(VPDataUpdate &&
2950-
"VPDataUpdate must have been introduced prior to fixing live outs");
2951-
Value *V = VPDataUpdate->getUnderlyingValue();
2952-
Value *ExtractedScalar =
2953-
State.get(CSA.second->getExtractScalarRecipe(), /*NeedsScalar=*/true);
2954-
// Fix LCSSAPhis
2955-
llvm::SmallPtrSet<PHINode *, 2> ToFix;
2956-
for (User *U : V->users())
2957-
if (auto *Phi = dyn_cast<PHINode>(U);
2958-
Phi && Phi->getParent() == LoopExitBlock)
2959-
ToFix.insert(Phi);
2960-
for (PHINode *Phi : ToFix)
2961-
Phi->addIncoming(ExtractedScalar, LoopMiddleBlock);
2962-
}
2963-
}
2964-
29652942
void InnerLoopVectorizer::fixVectorizedLoop(VPTransformState &State) {
29662943
// Fix widened non-induction PHIs by setting up the PHI operands.
29672944
if (EnableVPlanNativePath)
@@ -8866,7 +8843,7 @@ static void
88668843
addCSAPostprocessRecipes(VPRecipeBuilder &RecipeBuilder,
88678844
const LoopVectorizationLegality::CSAList &CSAs,
88688845
VPBasicBlock *MiddleVPBB, DebugLoc DL, VFRange &Range,
8869-
VPlan &Plan) {
8846+
VPlan &Plan, Loop *OrigLoop) {
88708847
// Don't build CSA for VF=ElementCount::getFixed(1)
88718848
if (LoopVectorizationPlanner::getDecisionAndClampRange(
88728849
[&](ElementCount VF) { return VF.isScalar(); }, Range))
@@ -8918,6 +8895,14 @@ addCSAPostprocessRecipes(VPRecipeBuilder &RecipeBuilder,
89188895
// Update CSAState with new recipes
89198896
CSAState->setExtractScalarRecipe(ExtractScalarRecipe);
89208897
CSAState->setVPAnyActive(VPAnyActive);
8898+
8899+
// Add live out for the CSA. We should be in LCSSA, so we are looking for
8900+
// Phi users in the unique exit block of the original updated value.
8901+
BasicBlock *OrigExit = OrigLoop->getUniqueExitBlock();
8902+
assert(OrigExit && "Expected a single exit block");
8903+
for (User *U :VPDataUpdate->getUnderlyingValue()->users())
8904+
if (auto *Phi = dyn_cast<PHINode>(U); Phi && Phi->getParent() == OrigExit)
8905+
Plan.addLiveOut(Phi, ExtractScalarRecipe);
89218906
}
89228907
}
89238908

0 commit comments

Comments
 (0)