@@ -4526,12 +4526,13 @@ void VPlanTransforms::addBranchWeightToMiddleTerminator(
45264526 MiddleTerm->setMetadata (LLVMContext::MD_prof, BranchWeights);
45274527}
45284528
4529- // / Create and return a ResumePhi for \p WideIV, unless it is truncated. If the
4530- // / induction recipe is not canonical, creates a VPDerivedIVRecipe to compute
4531- // / the end value of the induction.
4532- static VPInstruction *addResumePhiRecipeForInduction (
4533- VPWidenInductionRecipe *WideIV, VPBuilder &VectorPHBuilder,
4534- VPBuilder &ScalarPHBuilder, VPTypeAnalysis &TypeInfo, VPValue *VectorTC) {
4529+ // / Compute and return the end value for \p WideIV, unless it is truncated. If
4530+ // / the induction recipe is not canonical, creates a VPDerivedIVRecipe to
4531+ // / compute the end value of the induction.
4532+ static VPValue *tryToComputeEndValueForInduction (VPWidenInductionRecipe *WideIV,
4533+ VPBuilder &VectorPHBuilder,
4534+ VPTypeAnalysis &TypeInfo,
4535+ VPValue *VectorTC) {
45354536 auto *WideIntOrFp = dyn_cast<VPWidenIntOrFpInductionRecipe>(WideIV);
45364537 // Truncated wide inductions resume from the last lane of their vector value
45374538 // in the last vector iteration which is handled elsewhere.
@@ -4557,36 +4558,30 @@ static VPInstruction *addResumePhiRecipeForInduction(
45574558 WideIV->getDebugLoc ());
45584559 }
45594560
4560- auto *ResumePhiRecipe = ScalarPHBuilder.createScalarPhi (
4561- {EndValue, Start}, WideIV->getDebugLoc (), " bc.resume.val" );
4562- return ResumePhiRecipe;
4561+ return EndValue;
45634562}
45644563
4565- void VPlanTransforms::addScalarResumePhis (
4566- VPlan &Plan, VPRecipeBuilder &Builder,
4567- DenseMap<VPValue *, VPValue *> &IVEndValues) {
4564+ void VPlanTransforms::updateScalarResumePhis (
4565+ VPlan &Plan, DenseMap<VPValue *, VPValue *> &IVEndValues) {
45684566 VPTypeAnalysis TypeInfo (Plan);
45694567 auto *ScalarPH = Plan.getScalarPreheader ();
45704568 auto *MiddleVPBB = cast<VPBasicBlock>(ScalarPH->getPredecessors ()[0 ]);
45714569 VPRegionBlock *VectorRegion = Plan.getVectorLoopRegion ();
45724570 VPBuilder VectorPHBuilder (
45734571 cast<VPBasicBlock>(VectorRegion->getSinglePredecessor ()));
45744572 VPBuilder MiddleBuilder (MiddleVPBB, MiddleVPBB->getFirstNonPhi ());
4575- VPBuilder ScalarPHBuilder (ScalarPH);
4576- for (VPRecipeBase &ScalarPhiR : Plan.getScalarHeader ()->phis ()) {
4577- auto *ScalarPhiIRI = cast<VPIRPhi>(&ScalarPhiR);
4573+ for (VPRecipeBase &PhiR : Plan.getScalarPreheader ()->phis ()) {
4574+ auto *ResumePhiR = cast<VPPhi>(&PhiR);
45784575
45794576 // TODO: Extract final value from induction recipe initially, optimize to
45804577 // pre-computed end value together in optimizeInductionExitUsers.
4581- auto *VectorPhiR =
4582- cast<VPHeaderPHIRecipe>(Builder.getRecipe (&ScalarPhiIRI->getIRPhi ()));
4578+ auto *VectorPhiR = cast<VPHeaderPHIRecipe>(ResumePhiR->getOperand (0 ));
45834579 if (auto *WideIVR = dyn_cast<VPWidenInductionRecipe>(VectorPhiR)) {
4584- if (VPInstruction *ResumePhi = addResumePhiRecipeForInduction (
4585- WideIVR, VectorPHBuilder, ScalarPHBuilder, TypeInfo,
4586- &Plan.getVectorTripCount ())) {
4587- assert (isa<VPPhi>(ResumePhi) && " Expected a phi" );
4588- IVEndValues[WideIVR] = ResumePhi->getOperand (0 );
4589- ScalarPhiIRI->addOperand (ResumePhi);
4580+ if (VPValue *EndValue = tryToComputeEndValueForInduction (
4581+ WideIVR, VectorPHBuilder, TypeInfo, &Plan.getVectorTripCount ())) {
4582+ IVEndValues[WideIVR] = EndValue;
4583+ ResumePhiR->setOperand (0 , EndValue);
4584+ ResumePhiR->setName (" bc.resume.val" );
45904585 continue ;
45914586 }
45924587 // TODO: Also handle truncated inductions here. Computing end-values
@@ -4608,10 +4603,8 @@ void VPlanTransforms::addScalarResumePhis(
46084603 ResumeFromVectorLoop = MiddleBuilder.createNaryOp (
46094604 VPInstruction::ExtractLastElement, {ResumeFromVectorLoop}, {},
46104605 " vector.recur.extract" );
4611- StringRef Name = IsFOR ? " scalar.recur.init" : " bc.merge.rdx" ;
4612- auto *ResumePhiR = ScalarPHBuilder.createScalarPhi (
4613- {ResumeFromVectorLoop, VectorPhiR->getStartValue ()}, {}, Name);
4614- ScalarPhiIRI->addOperand (ResumePhiR);
4606+ ResumePhiR->setName (IsFOR ? " scalar.recur.init" : " bc.merge.rdx" );
4607+ ResumePhiR->setOperand (0 , ResumeFromVectorLoop);
46154608 }
46164609}
46174610
0 commit comments