@@ -3051,8 +3051,9 @@ PHINode *InnerLoopVectorizer::createInductionResumeValue(
30513051 }
30523052
30533053 // Create phi nodes to merge from the backedge-taken check block.
3054- PHINode *BCResumeVal = PHINode::Create (OrigPhi->getType (), 3 , " bc.resume.val" ,
3055- LoopScalarPreHeader->getFirstNonPHI ());
3054+ PHINode *BCResumeVal =
3055+ PHINode::Create (OrigPhi->getType (), 3 , " bc.resume.val" ,
3056+ LoopScalarPreHeader->getTerminator ()->getIterator ());
30563057 // Copy original phi DL over to the new one.
30573058 BCResumeVal->setDebugLoc (OrigPhi->getDebugLoc ());
30583059
@@ -7450,6 +7451,7 @@ static void createAndCollectMergePhiForReduction(
74507451 auto *PhiR = cast<VPReductionPHIRecipe>(RedResult->getOperand (0 ));
74517452 const RecurrenceDescriptor &RdxDesc = PhiR->getRecurrenceDescriptor ();
74527453
7454+ TrackingVH<Value> ReductionStartValue = RdxDesc.getRecurrenceStartValue ();
74537455 Value *FinalValue =
74547456 State.get (RedResult, VPIteration (State.UF - 1 , VPLane::getFirstLane ()));
74557457 auto *ResumePhi =
@@ -7474,7 +7476,7 @@ static void createAndCollectMergePhiForReduction(
74747476 BCBlockPhi->addIncoming (ResumePhi->getIncomingValueForBlock (Incoming),
74757477 Incoming);
74767478 else
7477- BCBlockPhi->addIncoming (RdxDesc. getRecurrenceStartValue () , Incoming);
7479+ BCBlockPhi->addIncoming (ReductionStartValue , Incoming);
74787480 }
74797481
74807482 auto *OrigPhi = cast<PHINode>(PhiR->getUnderlyingValue ());
@@ -7767,10 +7769,11 @@ EpilogueVectorizerEpilogueLoop::createEpilogueVectorizedLoopSkeleton(
77677769
77687770 // Now, compare the remaining count and if there aren't enough iterations to
77697771 // execute the vectorized epilogue skip to the scalar part.
7770- LoopVectorPreHeader->setName (" vec.epilog.ph" );
7771- BasicBlock *VecEpilogueIterationCountCheck =
7772- SplitBlock (LoopVectorPreHeader, LoopVectorPreHeader->begin (), DT, LI,
7773- nullptr , " vec.epilog.iter.check" , true );
7772+ BasicBlock *VecEpilogueIterationCountCheck = LoopVectorPreHeader;
7773+ VecEpilogueIterationCountCheck->setName (" vec.epilog.iter.check" );
7774+ LoopVectorPreHeader =
7775+ SplitBlock (LoopVectorPreHeader, LoopVectorPreHeader->getTerminator (), DT,
7776+ LI, nullptr , " vec.epilog.ph" );
77747777 emitMinimumVectorEpilogueIterCountCheck (LoopScalarPreHeader,
77757778 VecEpilogueIterationCountCheck);
77767779
@@ -8893,10 +8896,6 @@ VPlanPtr LoopVectorizationPlanner::buildVPlan(VFRange &Range) {
88938896// A ComputeReductionResult recipe is added to the middle block, also for
88948897// in-loop reductions which compute their result in-loop, because generating
88958898// the subsequent bc.merge.rdx phi is driven by ComputeReductionResult recipes.
8896- //
8897- // Adjust AnyOf reductions; replace the reduction phi for the selected value
8898- // with a boolean reduction phi node to check if the condition is true in any
8899- // iteration. The final value is selected by the final ComputeReductionResult.
89008899void LoopVectorizationPlanner::adjustRecipesForReductions (
89018900 VPBasicBlock *LatchVPBB, VPlanPtr &Plan, VPRecipeBuilder &RecipeBuilder,
89028901 ElementCount MinVF) {
@@ -9071,41 +9070,6 @@ void LoopVectorizationPlanner::adjustRecipesForReductions(
90719070 continue ;
90729071
90739072 const RecurrenceDescriptor &RdxDesc = PhiR->getRecurrenceDescriptor ();
9074- // Adjust AnyOf reductions; replace the reduction phi for the selected value
9075- // with a boolean reduction phi node to check if the condition is true in
9076- // any iteration. The final value is selected by the final
9077- // ComputeReductionResult.
9078- if (RecurrenceDescriptor::isAnyOfRecurrenceKind (
9079- RdxDesc.getRecurrenceKind ())) {
9080- auto *Select = cast<VPRecipeBase>(*find_if (PhiR->users (), [](VPUser *U) {
9081- return isa<VPWidenSelectRecipe>(U) ||
9082- (isa<VPReplicateRecipe>(U) &&
9083- cast<VPReplicateRecipe>(U)->getUnderlyingInstr ()->getOpcode () ==
9084- Instruction::Select);
9085- }));
9086- VPValue *Cmp = Select->getOperand (0 );
9087- // If the compare is checking the reduction PHI node, adjust it to check
9088- // the start value.
9089- if (VPRecipeBase *CmpR = Cmp->getDefiningRecipe ()) {
9090- for (unsigned I = 0 ; I != CmpR->getNumOperands (); ++I)
9091- if (CmpR->getOperand (I) == PhiR)
9092- CmpR->setOperand (I, PhiR->getStartValue ());
9093- }
9094- VPBuilder::InsertPointGuard Guard (Builder);
9095- Builder.setInsertPoint (Select);
9096-
9097- // If the true value of the select is the reduction phi, the new value is
9098- // selected if the negated condition is true in any iteration.
9099- if (Select->getOperand (1 ) == PhiR)
9100- Cmp = Builder.createNot (Cmp);
9101- VPValue *Or = Builder.createOr (PhiR, Cmp);
9102- Select->getVPSingleValue ()->replaceAllUsesWith (Or);
9103-
9104- // Convert the reduction phi to operate on bools.
9105- PhiR->setOperand (0 , Plan->getOrAddLiveIn (ConstantInt::getFalse (
9106- OrigLoop->getHeader ()->getContext ())));
9107- }
9108-
91099073 // If tail is folded by masking, introduce selects between the phi
91109074 // and the live-out instruction of each reduction, at the beginning of the
91119075 // dedicated latch block.
@@ -9138,9 +9102,7 @@ void LoopVectorizationPlanner::adjustRecipesForReductions(
91389102 // then extend the loop exit value to enable InstCombine to evaluate the
91399103 // entire expression in the smaller type.
91409104 Type *PhiTy = PhiR->getStartValue ()->getLiveInIRValue ()->getType ();
9141- if (MinVF.isVector () && PhiTy != RdxDesc.getRecurrenceType () &&
9142- !RecurrenceDescriptor::isAnyOfRecurrenceKind (
9143- RdxDesc.getRecurrenceKind ())) {
9105+ if (MinVF.isVector () && PhiTy != RdxDesc.getRecurrenceType ()) {
91449106 assert (!PhiR->isInLoop () && " Unexpected truncated inloop reduction!" );
91459107 Type *RdxTy = RdxDesc.getRecurrenceType ();
91469108 auto *Trunc =
@@ -10181,19 +10143,9 @@ bool LoopVectorizePass::processLoop(Loop *L) {
1018110143 Value *ResumeV = nullptr ;
1018210144 // TODO: Move setting of resume values to prepareToExecute.
1018310145 if (auto *ReductionPhi = dyn_cast<VPReductionPHIRecipe>(&R)) {
10184- const RecurrenceDescriptor &RdxDesc =
10185- ReductionPhi->getRecurrenceDescriptor ();
10186- RecurKind RK = RdxDesc.getRecurrenceKind ();
10187- ResumeV = ReductionResumeValues.find (&RdxDesc)->second ;
10188- if (RecurrenceDescriptor::isAnyOfRecurrenceKind (RK)) {
10189- // VPReductionPHIRecipes for AnyOf reductions expect a boolean as
10190- // start value; compare the final value from the main vector loop
10191- // to the start value.
10192- IRBuilder<> Builder (
10193- cast<Instruction>(ResumeV)->getParent ()->getFirstNonPHI ());
10194- ResumeV = Builder.CreateICmpNE (ResumeV,
10195- RdxDesc.getRecurrenceStartValue ());
10196- }
10146+ ResumeV = ReductionResumeValues
10147+ .find (&ReductionPhi->getRecurrenceDescriptor ())
10148+ ->second ;
1019710149 } else {
1019810150 // Create induction resume values for both widened pointer and
1019910151 // integer/fp inductions and update the start value of the induction
0 commit comments