@@ -7218,12 +7218,15 @@ static Value *getStartValueFromReductionResult(VPInstruction *RdxResult) {
7218
7218
return StartVPV->getLiveInIRValue ();
7219
7219
}
7220
7220
7221
- // If \p R is a Compute{Reduction,AnyOf,FindLastIV}Result when vectorizing the
7221
+ // If \p EpiResumePhiR is resume VPPhi for a reduction when vectorizing the
7222
7222
// epilog loop, fix the reduction's scalar PHI node by adding the incoming value
7223
7223
// from the main vector loop.
7224
7224
static void fixReductionScalarResumeWhenVectorizingEpilog (
7225
- VPRecipeBase *R, VPTransformState &State, BasicBlock *BypassBlock) {
7226
- auto *EpiRedResult = dyn_cast<VPInstruction>(R);
7225
+ VPPhi *EpiResumePhiR, VPTransformState &State, BasicBlock *BypassBlock) {
7226
+ // Get the VPInstruction computing the reduction result in the middle block.
7227
+ // The first operand may not be from the middle block if it is not connected
7228
+ // to the scalar preheader. In that case, there's nothing to fix.
7229
+ auto *EpiRedResult = dyn_cast<VPInstruction>(EpiResumePhiR->getOperand (0 ));
7227
7230
if (!EpiRedResult ||
7228
7231
(EpiRedResult->getOpcode () != VPInstruction::ComputeAnyOfResult &&
7229
7232
EpiRedResult->getOpcode () != VPInstruction::ComputeReductionResult &&
@@ -7274,12 +7277,7 @@ static void fixReductionScalarResumeWhenVectorizingEpilog(
7274
7277
// When fixing reductions in the epilogue loop we should already have
7275
7278
// created a bc.merge.rdx Phi after the main vector body. Ensure that we carry
7276
7279
// over the incoming values correctly.
7277
- using namespace VPlanPatternMatch ;
7278
- assert (count_if (EpiRedResult->users (), IsaPred<VPPhi>) == 1 &&
7279
- " ResumePhi must have a single user" );
7280
- auto *EpiResumePhiVPI =
7281
- cast<VPInstruction>(*find_if (EpiRedResult->users (), IsaPred<VPPhi>));
7282
- auto *EpiResumePhi = cast<PHINode>(State.get (EpiResumePhiVPI, true ));
7280
+ auto *EpiResumePhi = cast<PHINode>(State.get (EpiResumePhiR, true ));
7283
7281
EpiResumePhi->setIncomingValueForBlock (
7284
7282
BypassBlock, MainResumePhi->getIncomingValueForBlock (BypassBlock));
7285
7283
}
@@ -7388,17 +7386,13 @@ DenseMap<const SCEV *, Value *> LoopVectorizationPlanner::executePlan(
7388
7386
}
7389
7387
}
7390
7388
VPBasicBlock *ScalarPH = BestVPlan.getScalarPreheader ();
7391
- ArrayRef<VPBlockBase *> ScalarPreds = ScalarPH->getPredecessors ();
7392
- if (!ScalarPreds.empty ()) {
7389
+ if (ScalarPH->getNumPredecessors () > 0 ) {
7393
7390
// If ScalarPH has predecessors, we may need to update its reduction
7394
- // resume values. If there is a middle block, it must be the first
7395
- // predecessor. Note that the first predecessor may not be the middle
7396
- // block, if the middle block doesn't branch to the scalar preheader. In
7397
- // that case, fixReductionScalarResumeWhenVectorizingEpilog will be a
7398
- // no-op.
7399
- auto *MiddleVPBB = cast<VPBasicBlock>(ScalarPreds[0 ]);
7400
- for (VPRecipeBase &R : *MiddleVPBB)
7401
- fixReductionScalarResumeWhenVectorizingEpilog (&R, State, BypassBlock);
7391
+ // resume values.
7392
+ for (VPRecipeBase &R : ScalarPH->phis ()) {
7393
+ fixReductionScalarResumeWhenVectorizingEpilog (cast<VPPhi>(&R), State,
7394
+ BypassBlock);
7395
+ }
7402
7396
}
7403
7397
}
7404
7398
0 commit comments