mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-06-15 05:24:01 +00:00
LoopVectorize fix: LoopInfo must be valid when invoking utils like SCEVExpander.
In general, one should always complete CFG modifications first, update CFG-based analyses, like Dominatores and LoopInfo, then generate instruction sequences. LoopVectorizer was creating a new loop, calling SCEVExpander to generate checks, then updating LoopInfo. I just changed the order. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@186241 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
@ -1476,6 +1476,22 @@ InnerLoopVectorizer::createEmptyLoop(LoopVectorizationLegality *Legal) {
|
||||
BasicBlock *ScalarPH =
|
||||
MiddleBlock->splitBasicBlock(MiddleBlock->getTerminator(), "scalar.ph");
|
||||
|
||||
// Create and register the new vector loop.
|
||||
Loop* Lp = new Loop();
|
||||
Loop *ParentLoop = OrigLoop->getParentLoop();
|
||||
|
||||
// Insert the new loop into the loop nest and register the new basic blocks
|
||||
// before calling any utilities such as SCEV that require valid LoopInfo.
|
||||
if (ParentLoop) {
|
||||
ParentLoop->addChildLoop(Lp);
|
||||
ParentLoop->addBasicBlockToLoop(ScalarPH, LI->getBase());
|
||||
ParentLoop->addBasicBlockToLoop(VectorPH, LI->getBase());
|
||||
ParentLoop->addBasicBlockToLoop(MiddleBlock, LI->getBase());
|
||||
} else {
|
||||
LI->addTopLevelLoop(Lp);
|
||||
}
|
||||
Lp->addBasicBlockToLoop(VecBody, LI->getBase());
|
||||
|
||||
// Use this IR builder to create the loop instructions (Phi, Br, Cmp)
|
||||
// inside the loop.
|
||||
Builder.SetInsertPoint(VecBody->getFirstInsertionPt());
|
||||
@ -1530,6 +1546,8 @@ InnerLoopVectorizer::createEmptyLoop(LoopVectorizationLegality *Legal) {
|
||||
// Create a new block containing the memory check.
|
||||
BasicBlock *CheckBlock = BypassBlock->splitBasicBlock(MemRuntimeCheck,
|
||||
"vector.memcheck");
|
||||
if (ParentLoop)
|
||||
ParentLoop->addBasicBlockToLoop(CheckBlock, LI->getBase());
|
||||
LoopBypassBlocks.push_back(CheckBlock);
|
||||
|
||||
// Replace the branch into the memory check block with a conditional branch
|
||||
@ -1697,24 +1715,6 @@ InnerLoopVectorizer::createEmptyLoop(LoopVectorizationLegality *Legal) {
|
||||
// Get ready to start creating new instructions into the vectorized body.
|
||||
Builder.SetInsertPoint(VecBody->getFirstInsertionPt());
|
||||
|
||||
// Create and register the new vector loop.
|
||||
Loop* Lp = new Loop();
|
||||
Loop *ParentLoop = OrigLoop->getParentLoop();
|
||||
|
||||
// Insert the new loop into the loop nest and register the new basic blocks.
|
||||
if (ParentLoop) {
|
||||
ParentLoop->addChildLoop(Lp);
|
||||
for (unsigned I = 1, E = LoopBypassBlocks.size(); I != E; ++I)
|
||||
ParentLoop->addBasicBlockToLoop(LoopBypassBlocks[I], LI->getBase());
|
||||
ParentLoop->addBasicBlockToLoop(ScalarPH, LI->getBase());
|
||||
ParentLoop->addBasicBlockToLoop(VectorPH, LI->getBase());
|
||||
ParentLoop->addBasicBlockToLoop(MiddleBlock, LI->getBase());
|
||||
} else {
|
||||
LI->addTopLevelLoop(Lp);
|
||||
}
|
||||
|
||||
Lp->addBasicBlockToLoop(VecBody, LI->getBase());
|
||||
|
||||
// Save the state.
|
||||
LoopVectorPreHeader = VectorPH;
|
||||
LoopScalarPreHeader = ScalarPH;
|
||||
|
Reference in New Issue
Block a user