@@ -499,10 +499,6 @@ class InnerLoopVectorizer {
499
499
// / Fix the vectorized code, taking care of header phi's, and more.
500
500
void fixVectorizedLoop (VPTransformState &State);
501
501
502
- // / For all vectorized CSAs, replace uses of live-out scalar from the orignal
503
- // / loop with the extracted scalar from the vector loop for.
504
- void fixCSALiveOuts (VPTransformState &State, VPlan &Plan);
505
-
506
502
// Return true if any runtime check is added.
507
503
bool areSafetyChecksAdded () { return AddedSafetyChecks; }
508
504
@@ -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)
@@ -2997,7 +2974,7 @@ void InnerLoopVectorizer::fixVectorizedLoop(VPTransformState &State) {
2997
2974
fixupIVUsers (Entry.first , Entry.second ,
2998
2975
getOrCreateVectorTripCount (nullptr ),
2999
2976
IVEndValues[Entry.first ], LoopMiddleBlock, State);
3000
- fixCSALiveOuts (State, Plan);
2977
+ IVEndValues[Entry. first ], LoopMiddleBlock, Plan, State );
3001
2978
}
3002
2979
3003
2980
for (Instruction *PI : PredicatedInstructions)
@@ -8845,7 +8822,7 @@ static void
8845
8822
addCSAPostprocessRecipes (VPRecipeBuilder &RecipeBuilder,
8846
8823
const LoopVectorizationLegality::CSAList &CSAs,
8847
8824
VPBasicBlock *MiddleVPBB, DebugLoc DL, VFRange &Range,
8848
- VPlan &Plan) {
8825
+ VPlan &Plan, Loop *OrigLoop ) {
8849
8826
// Don't build CSA for VF=ElementCount::getFixed(1)
8850
8827
if (LoopVectorizationPlanner::getDecisionAndClampRange (
8851
8828
[&](ElementCount VF) { return VF.isScalar (); }, Range))
@@ -8897,6 +8874,14 @@ addCSAPostprocessRecipes(VPRecipeBuilder &RecipeBuilder,
8897
8874
// Update CSAState with new recipes
8898
8875
CSAState->setExtractScalarRecipe (ExtractScalarRecipe);
8899
8876
CSAState->setVPAnyActive (VPAnyActive);
8877
+
8878
+ // Add live out for the CSA. We should be in LCSSA, so we are looking for
8879
+ // Phi users in the unique exit block of the original updated value.
8880
+ BasicBlock *OrigExit = OrigLoop->getUniqueExitBlock ();
8881
+ assert (OrigExit && " Expected a single exit block" );
8882
+ for (User *U :VPDataUpdate->getUnderlyingValue ()->users ())
8883
+ if (auto *Phi = dyn_cast<PHINode>(U); Phi && Phi->getParent () == OrigExit)
8884
+ Plan.addLiveOut (Phi, ExtractScalarRecipe);
8900
8885
}
8901
8886
}
8902
8887
0 commit comments