Skip to content

Commit e4543af

Browse files
committed
[VPlan] Track current vector loop in VPTransformState (NFC).
Instead of looking up the vector loop using the header, keep track of the current vector loop in VPTransformState. This removes the requirement for the vector header block being part of the loop up front. A follow-up patch will move the code to generate the Loop object for the vector loop to VPRegionBlock. Depends on D121619. Reviewed By: Ayal Differential Revision: https://reviews.llvm.org/D121621
1 parent 5fbce8b commit e4543af

File tree

2 files changed

+6
-3
lines changed

2 files changed

+6
-3
lines changed

llvm/lib/Transforms/Vectorize/VPlan.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -319,8 +319,7 @@ void VPBasicBlock::execute(VPTransformState *State) {
319319
UnreachableInst *Terminator = State->Builder.CreateUnreachable();
320320
State->Builder.SetInsertPoint(Terminator);
321321
// Register NewBB in its loop. In innermost loops its the same for all BB's.
322-
Loop *L = State->LI->getLoopFor(State->CFG.PrevBB);
323-
L->addBasicBlockToLoop(NewBB, *State->LI);
322+
State->CurrentVectorLoop->addBasicBlockToLoop(NewBB, *State->LI);
324323
State->CFG.PrevBB = NewBB;
325324
}
326325

@@ -909,6 +908,7 @@ void VPlan::execute(VPTransformState *State) {
909908
assert(VectorHeaderBB && "Loop preheader does not have a single successor.");
910909

911910
Loop *L = State->LI->getLoopFor(VectorHeaderBB);
911+
State->CurrentVectorLoop = L;
912912
State->CFG.ExitBB = L->getExitBlock();
913913

914914
// Remove the edge between Header and Latch to allow other connections.
@@ -1543,7 +1543,7 @@ void VPReductionPHIRecipe::execute(VPTransformState &State) {
15431543
ScalarPHI ? PN->getType() : VectorType::get(PN->getType(), State.VF);
15441544

15451545
BasicBlock *HeaderBB = State.CFG.PrevBB;
1546-
assert(State.LI->getLoopFor(HeaderBB)->getHeader() == HeaderBB &&
1546+
assert(State.CurrentVectorLoop->getHeader() == HeaderBB &&
15471547
"recipe must be in the vector loop header");
15481548
unsigned LastPartForNewPhi = isOrdered() ? 1 : State.UF;
15491549
for (unsigned Part = 0; Part < LastPartForNewPhi; ++Part) {

llvm/lib/Transforms/Vectorize/VPlan.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -352,6 +352,9 @@ struct VPTransformState {
352352
/// Holds recipes that may generate a poison value that is used after
353353
/// vectorization, even when their operands are not poison.
354354
SmallPtrSet<VPRecipeBase *, 16> MayGeneratePoisonRecipes;
355+
356+
/// The loop object for the current parent region, or nullptr.
357+
Loop *CurrentVectorLoop = nullptr;
355358
};
356359

357360
/// VPUsers instance used by VPBlockBase to manage CondBit and the block

0 commit comments

Comments
 (0)