diff --git a/llvm/lib/Transforms/Vectorize/VPlan.h b/llvm/lib/Transforms/Vectorize/VPlan.h --- a/llvm/lib/Transforms/Vectorize/VPlan.h +++ b/llvm/lib/Transforms/Vectorize/VPlan.h @@ -352,6 +352,9 @@ /// Holds recipes that may generate a poison value that is used after /// vectorization, even when their operands are not poison. SmallPtrSet MayGeneratePoisonRecipes; + + /// The loop object for the current parent region, or nullptr. + Loop *CurrentVectorLoop = nullptr; }; /// VPUsers instance used by VPBlockBase to manage CondBit and the block diff --git a/llvm/lib/Transforms/Vectorize/VPlan.cpp b/llvm/lib/Transforms/Vectorize/VPlan.cpp --- a/llvm/lib/Transforms/Vectorize/VPlan.cpp +++ b/llvm/lib/Transforms/Vectorize/VPlan.cpp @@ -319,8 +319,7 @@ UnreachableInst *Terminator = State->Builder.CreateUnreachable(); State->Builder.SetInsertPoint(Terminator); // Register NewBB in its loop. In innermost loops its the same for all BB's. - Loop *L = State->LI->getLoopFor(State->CFG.PrevBB); - L->addBasicBlockToLoop(NewBB, *State->LI); + State->CurrentVectorLoop->addBasicBlockToLoop(NewBB, *State->LI); State->CFG.PrevBB = NewBB; } @@ -909,6 +908,7 @@ assert(VectorHeaderBB && "Loop preheader does not have a single successor."); Loop *L = State->LI->getLoopFor(VectorHeaderBB); + State->CurrentVectorLoop = L; State->CFG.ExitBB = L->getExitBlock(); // Remove the edge between Header and Latch to allow other connections. @@ -1543,7 +1543,7 @@ ScalarPHI ? PN->getType() : VectorType::get(PN->getType(), State.VF); BasicBlock *HeaderBB = State.CFG.PrevBB; - assert(State.LI->getLoopFor(HeaderBB)->getHeader() == HeaderBB && + assert(State.CurrentVectorLoop->getHeader() == HeaderBB && "recipe must be in the vector loop header"); unsigned LastPartForNewPhi = isOrdered() ? 1 : State.UF; for (unsigned Part = 0; Part < LastPartForNewPhi; ++Part) {