@@ -499,10 +499,6 @@ class InnerLoopVectorizer {
499499 // / Fix the vectorized code, taking care of header phi's, and more.
500500 void fixVectorizedLoop (VPTransformState &State);
501501
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-
506502 // Return true if any runtime check is added.
507503 bool areSafetyChecksAdded () { return AddedSafetyChecks; }
508504
@@ -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-
29652942void InnerLoopVectorizer::fixVectorizedLoop (VPTransformState &State) {
29662943 // Fix widened non-induction PHIs by setting up the PHI operands.
29672944 if (EnableVPlanNativePath)
@@ -2997,7 +2974,7 @@ void InnerLoopVectorizer::fixVectorizedLoop(VPTransformState &State) {
29972974 fixupIVUsers (Entry.first , Entry.second ,
29982975 getOrCreateVectorTripCount (nullptr ),
29992976 IVEndValues[Entry.first ], LoopMiddleBlock, State);
3000- fixCSALiveOuts (State, Plan);
2977+ IVEndValues[Entry. first ], LoopMiddleBlock, Plan, State );
30012978 }
30022979
30032980 for (Instruction *PI : PredicatedInstructions)
@@ -8845,7 +8822,7 @@ static void
88458822addCSAPostprocessRecipes (VPRecipeBuilder &RecipeBuilder,
88468823 const LoopVectorizationLegality::CSAList &CSAs,
88478824 VPBasicBlock *MiddleVPBB, DebugLoc DL, VFRange &Range,
8848- VPlan &Plan) {
8825+ VPlan &Plan, Loop *OrigLoop ) {
88498826 // Don't build CSA for VF=ElementCount::getFixed(1)
88508827 if (LoopVectorizationPlanner::getDecisionAndClampRange (
88518828 [&](ElementCount VF) { return VF.isScalar (); }, Range))
@@ -8897,6 +8874,14 @@ addCSAPostprocessRecipes(VPRecipeBuilder &RecipeBuilder,
88978874 // Update CSAState with new recipes
88988875 CSAState->setExtractScalarRecipe (ExtractScalarRecipe);
88998876 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);
89008885 }
89018886}
89028887
0 commit comments