@@ -8845,35 +8845,34 @@ static SetVector<VPIRInstruction *> collectUsersInExitBlocks(
88458845 continue ;
88468846 auto *ExitVPBB = cast<VPIRBasicBlock>(VPB);
88478847 BasicBlock *ExitBB = ExitVPBB->getIRBasicBlock ();
8848- BasicBlock *ExitingBB = find_singleton<BasicBlock>(
8849- to_vector (predecessors (ExitBB)),
8850- [OrigLoop](BasicBlock *Pred, bool AllowRepeats) {
8851- return OrigLoop->contains (Pred) ? Pred : nullptr ;
8852- });
88538848 for (VPRecipeBase &R : *ExitVPBB) {
88548849 auto *ExitIRI = dyn_cast<VPIRInstruction>(&R);
88558850 if (!ExitIRI)
88568851 continue ;
88578852 auto *ExitPhi = dyn_cast<PHINode>(&ExitIRI->getInstruction ());
88588853 if (!ExitPhi)
88598854 break ;
8860- Value *IncomingValue = ExitPhi->getIncomingValueForBlock (ExitingBB);
8861- VPValue *V = Builder.getVPValueOrAddLiveIn (IncomingValue);
8862- // Exit values for inductions are computed and updated outside of VPlan
8863- // and independent of induction recipes.
8864- // TODO: Compute induction exit values in VPlan.
8865- if ((isa<VPWidenIntOrFpInductionRecipe>(V) &&
8866- !cast<VPWidenIntOrFpInductionRecipe>(V)->getTruncInst ()) ||
8867- isa<VPWidenPointerInductionRecipe>(V) ||
8868- (isa<Instruction>(IncomingValue) &&
8869- OrigLoop->contains (cast<Instruction>(IncomingValue)) &&
8870- any_of (IncomingValue->users (), [&Inductions](User *U) {
8871- auto *P = dyn_cast<PHINode>(U);
8872- return P && Inductions.contains (P);
8873- })))
8874- continue ;
8875- ExitUsersToFix.insert (ExitIRI);
8876- ExitIRI->addOperand (V);
8855+ for (BasicBlock *ExitingBB : predecessors (ExitBB)) {
8856+ if (!OrigLoop->contains (ExitingBB))
8857+ continue ;
8858+ Value *IncomingValue = ExitPhi->getIncomingValueForBlock (ExitingBB);
8859+ VPValue *V = Builder.getVPValueOrAddLiveIn (IncomingValue);
8860+ // Exit values for inductions are computed and updated outside of VPlan
8861+ // and independent of induction recipes.
8862+ // TODO: Compute induction exit values in VPlan.
8863+ if ((isa<VPWidenIntOrFpInductionRecipe>(V) &&
8864+ !cast<VPWidenIntOrFpInductionRecipe>(V)->getTruncInst ()) ||
8865+ isa<VPWidenPointerInductionRecipe>(V) ||
8866+ (isa<Instruction>(IncomingValue) &&
8867+ OrigLoop->contains (cast<Instruction>(IncomingValue)) &&
8868+ any_of (IncomingValue->users (), [&Inductions](User *U) {
8869+ auto *P = dyn_cast<PHINode>(U);
8870+ return P && Inductions.contains (P);
8871+ })))
8872+ continue ;
8873+ ExitUsersToFix.insert (ExitIRI);
8874+ ExitIRI->addOperand (V);
8875+ }
88778876 }
88788877 }
88798878 return ExitUsersToFix;
@@ -8887,23 +8886,26 @@ addUsersInExitBlocks(VPlan &Plan,
88878886 if (ExitUsersToFix.empty ())
88888887 return ;
88898888
8890- auto *MiddleVPBB = Plan.getMiddleBlock ();
8891- VPBuilder B (MiddleVPBB, MiddleVPBB->getFirstNonPhi ());
8892-
88938889 // Introduce extract for exiting values and update the VPIRInstructions
88948890 // modeling the corresponding LCSSA phis.
88958891 for (VPIRInstruction *ExitIRI : ExitUsersToFix) {
8892+
88968893 VPValue *V = ExitIRI->getOperand (0 );
88978894 // Pass live-in values used by exit phis directly through to their users in
88988895 // the exit block.
88998896 if (V->isLiveIn ())
89008897 continue ;
89018898
8902- LLVMContext &Ctx = ExitIRI->getInstruction ().getContext ();
8903- VPValue *Ext = B.createNaryOp (VPInstruction::ExtractFromEnd,
8904- {V, Plan.getOrAddLiveIn (ConstantInt::get (
8905- IntegerType::get (Ctx, 32 ), 1 ))});
8906- ExitIRI->setOperand (0 , Ext);
8899+ for (VPBlockBase *PredVPB : ExitIRI->getParent ()->getPredecessors ()) {
8900+ auto *PredVPBB = cast<VPBasicBlock>(PredVPB);
8901+ VPBuilder B (PredVPBB, PredVPBB->getFirstNonPhi ());
8902+
8903+ LLVMContext &Ctx = ExitIRI->getInstruction ().getContext ();
8904+ VPValue *Ext = B.createNaryOp (VPInstruction::ExtractFromEnd,
8905+ {V, Plan.getOrAddLiveIn (ConstantInt::get (
8906+ IntegerType::get (Ctx, 32 ), 1 ))});
8907+ ExitIRI->setOperand (0 , Ext);
8908+ }
89078909 }
89088910}
89098911
0 commit comments