@@ -487,17 +487,17 @@ void VPBasicBlock::execute(VPTransformState *State) {
487
487
488
488
if (isHeader ()) {
489
489
// Create and register the new vector loop.
490
- State->CurrentVectorLoop = State->LI ->AllocateLoop ();
490
+ State->CurrentParentLoop = State->LI ->AllocateLoop ();
491
491
BasicBlock *VectorPH =
492
492
State->CFG .VPBB2IRBB [cast<VPBasicBlock>(getPredecessors ()[0 ])];
493
493
Loop *ParentLoop = State->LI ->getLoopFor (VectorPH);
494
494
495
495
// Insert the new loop into the loop nest and register the new basic blocks
496
496
// before calling any utilities such as SCEV that require valid LoopInfo.
497
497
if (ParentLoop)
498
- ParentLoop->addChildLoop (State->CurrentVectorLoop );
498
+ ParentLoop->addChildLoop (State->CurrentParentLoop );
499
499
else
500
- State->LI ->addTopLevelLoop (State->CurrentVectorLoop );
500
+ State->LI ->addTopLevelLoop (State->CurrentParentLoop );
501
501
}
502
502
503
503
auto IsReplicateRegion = [](VPBlockBase *BB) {
@@ -823,10 +823,6 @@ void VPRegionBlock::removeRegion() {
823
823
824
824
VPBlockUtils::connectBlocks (Preheader, Header);
825
825
VPBlockUtils::connectBlocks (Exiting, Middle);
826
-
827
- // Set LoopRegion's Entry to nullptr, as the CFG from LoopRegion shouldn't
828
- // be deleted when the region is deleted.
829
- Entry = nullptr ;
830
826
}
831
827
832
828
VPlan::VPlan (Loop *L) {
@@ -1029,13 +1025,17 @@ void VPlan::execute(VPTransformState *State) {
1029
1025
Phi = cast<PHINode>(GEP->getPointerOperand ());
1030
1026
}
1031
1027
1032
- auto *PhiR = cast<VPHeaderPHIRecipe>(&R);
1033
- bool NeedsScalar = isa<VPScalarPHIRecipe>(PhiR) ||
1034
- (isa<VPReductionPHIRecipe>(PhiR) &&
1035
- cast<VPReductionPHIRecipe>(PhiR)->isInLoop ());
1036
- Value *Phi = State->get (PhiR, NeedsScalar);
1037
- Value *Val = State->get (PhiR->getBackedgeValue (), NeedsScalar);
1038
- cast<PHINode>(Phi)->addIncoming (Val, VectorLatchBB);
1028
+ Phi->setIncomingBlock (1 , VectorLatchBB);
1029
+
1030
+ // Move the last step to the end of the latch block. This ensures
1031
+ // consistent placement of all induction updates.
1032
+ Instruction *Inc = cast<Instruction>(Phi->getIncomingValue (1 ));
1033
+ Inc->moveBefore (VectorLatchBB->getTerminator ()->getPrevNode ());
1034
+
1035
+ // Use the steps for the last part as backedge value for the induction.
1036
+ if (auto *IV = dyn_cast<VPWidenIntOrFpInductionRecipe>(&R))
1037
+ Inc->setOperand (0 , State->get (IV->getLastUnrolledPartOperand ()));
1038
+ continue ;
1039
1039
}
1040
1040
1041
1041
auto *PhiR = cast<VPHeaderPHIRecipe>(&R);
@@ -1045,6 +1045,7 @@ void VPlan::execute(VPTransformState *State) {
1045
1045
Value *Phi = State->get (PhiR, NeedsScalar);
1046
1046
Value *Val = State->get (PhiR->getBackedgeValue (), NeedsScalar);
1047
1047
cast<PHINode>(Phi)->addIncoming (Val, VectorLatchBB);
1048
+ }
1048
1049
}
1049
1050
}
1050
1051
@@ -1419,7 +1420,9 @@ bool VPValue::isDefinedOutsideLoopRegions() const {
1419
1420
1420
1421
const VPBasicBlock *DefVPBB = DefR->getParent ();
1421
1422
auto *Plan = DefVPBB->getPlan ();
1422
- return DefVPBB == Plan->getPreheader () || DefVPBB == Plan->getEntry ();
1423
+ if (Plan->getVectorLoopRegion ())
1424
+ return !DefR->getParent ()->getEnclosingLoopRegion ();
1425
+ return DefVPBB == Plan->getEntry ();
1423
1426
}
1424
1427
void VPValue::replaceAllUsesWith (VPValue *New) {
1425
1428
replaceUsesWithIf (New, [](VPUser &, unsigned ) { return true ; });
0 commit comments