@@ -500,10 +500,6 @@ class InnerLoopVectorizer {
500
500
// / Fix the vectorized code, taking care of header phi's, and more.
501
501
void fixVectorizedLoop (VPTransformState &State);
502
502
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
-
507
503
// Return true if any runtime check is added.
508
504
bool areSafetyChecksAdded () { return AddedSafetyChecks; }
509
505
@@ -2943,25 +2939,6 @@ LoopVectorizationCostModel::getVectorIntrinsicCost(CallInst *CI,
2943
2939
TargetTransformInfo::TCK_RecipThroughput);
2944
2940
}
2945
2941
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
-
2965
2942
void InnerLoopVectorizer::fixVectorizedLoop (VPTransformState &State) {
2966
2943
// Fix widened non-induction PHIs by setting up the PHI operands.
2967
2944
if (EnableVPlanNativePath)
@@ -8866,7 +8843,7 @@ static void
8866
8843
addCSAPostprocessRecipes (VPRecipeBuilder &RecipeBuilder,
8867
8844
const LoopVectorizationLegality::CSAList &CSAs,
8868
8845
VPBasicBlock *MiddleVPBB, DebugLoc DL, VFRange &Range,
8869
- VPlan &Plan) {
8846
+ VPlan &Plan, Loop *OrigLoop ) {
8870
8847
// Don't build CSA for VF=ElementCount::getFixed(1)
8871
8848
if (LoopVectorizationPlanner::getDecisionAndClampRange (
8872
8849
[&](ElementCount VF) { return VF.isScalar (); }, Range))
@@ -8918,6 +8895,14 @@ addCSAPostprocessRecipes(VPRecipeBuilder &RecipeBuilder,
8918
8895
// Update CSAState with new recipes
8919
8896
CSAState->setExtractScalarRecipe (ExtractScalarRecipe);
8920
8897
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);
8921
8906
}
8922
8907
}
8923
8908
0 commit comments