@@ -7494,12 +7494,12 @@ static void addRuntimeUnrollDisableMetaData(Loop *L) {
74947494 }
74957495}
74967496
7497- // Check if \p RedResult is a ComputeReductionResult instruction, and if it is
7498- // create a merge phi node for it and add incoming values from the main vector
7499- // loop.
7500- static void updateAndCollectMergePhiForReductionForEpilogueVectorization (
7497+ // If \p RedResult is a ComputeReductionResult when vectorizing the epilog loop,
7498+ // update the reduction's scalar PHI node by adding the incoming value from the
7499+ // main vector loop.
7500+ static void updateMergePhiForReductionForEpilogueVectorization (
75017501 VPInstruction *RedResult, VPTransformState &State, Loop *OrigLoop,
7502- BasicBlock *LoopMiddleBlock, bool VectorizingEpilogue ) {
7502+ BasicBlock *LoopMiddleBlock) {
75037503 if (!RedResult ||
75047504 RedResult->getOpcode () != VPInstruction::ComputeReductionResult)
75057505 return ;
@@ -7510,12 +7510,11 @@ static void updateAndCollectMergePhiForReductionForEpilogueVectorization(
75107510 return match (U, m_VPInstruction<VPInstruction::ResumePhi>(m_VPValue (),
75117511 m_VPValue ()));
75127512 }));
7513+ assert (ResumePhiVPV->getNumUsers () == 1 &&
7514+ " ResumePhi must have a single user" );
75137515 auto *BCBlockPhi = cast<PHINode>(State.get (ResumePhiVPV, true ));
75147516 auto *PhiR = cast<VPReductionPHIRecipe>(RedResult->getOperand (0 ));
75157517 const RecurrenceDescriptor &RdxDesc = PhiR->getRecurrenceDescriptor ();
7516- if (!VectorizingEpilogue)
7517- return ;
7518-
75197518 auto *ResumePhi =
75207519 dyn_cast<PHINode>(PhiR->getStartValue ()->getUnderlyingValue ());
75217520 if (RecurrenceDescriptor::isAnyOfRecurrenceKind (
@@ -7525,16 +7524,16 @@ static void updateAndCollectMergePhiForReductionForEpilogueVectorization(
75257524 assert (Cmp->getOperand (1 ) == RdxDesc.getRecurrenceStartValue ());
75267525 ResumePhi = cast<PHINode>(Cmp->getOperand (0 ));
75277526 }
7528- assert ((!VectorizingEpilogue || ResumePhi) &&
7527+ assert (ResumePhi &&
75297528 " when vectorizing the epilogue loop, we need a resume phi from main "
75307529 " vector loop" );
75317530
75327531 BasicBlock *LoopScalarPreHeader = OrigLoop->getLoopPreheader ();
7533- // If we are fixing reductions in the epilogue loop then we should already
7534- // have created a bc.merge.rdx Phi after the main vector body. Ensure that
7535- // we carry over the incoming values correctly.
7532+ // When fixing reductions in the epilogue loop then we should already have
7533+ // created a bc.merge.rdx Phi after the main vector body. Ensure that we carry
7534+ // over the incoming values correctly.
75367535 for (auto *Incoming : predecessors (LoopScalarPreHeader)) {
7537- if (ResumePhi && is_contained (ResumePhi->blocks (), Incoming))
7536+ if (is_contained (ResumePhi->blocks (), Incoming))
75387537 BCBlockPhi->setIncomingValueForBlock (
75397538 Incoming, ResumePhi->getIncomingValueForBlock (Incoming));
75407539 }
@@ -7628,11 +7627,11 @@ DenseMap<const SCEV *, Value *> LoopVectorizationPlanner::executePlan(
76287627 // 2.5 Collect reduction resume values.
76297628 auto *ExitVPBB =
76307629 cast<VPBasicBlock>(BestVPlan.getVectorLoopRegion ()->getSingleSuccessor ());
7631- if (IsEpilogueVectorization)
7630+ if (IsEpilogueVectorization && ExpandedSCEVs )
76327631 for (VPRecipeBase &R : *ExitVPBB) {
7633- updateAndCollectMergePhiForReductionForEpilogueVectorization (
7632+ updateMergePhiForReductionForEpilogueVectorization (
76347633 dyn_cast<VPInstruction>(&R), State, OrigLoop,
7635- State.CFG .VPBB2IRBB [ExitVPBB], ExpandedSCEVs );
7634+ State.CFG .VPBB2IRBB [ExitVPBB]);
76367635 }
76377636
76387637 // 2.6. Maintain Loop Hints
0 commit comments