[PATCH] D74382: [CloneFunction] Update loop headers after cloning all blocks in loop.
Whitney Tsang via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Mon Feb 10 21:13:20 PST 2020
Whitney created this revision.
Whitney added reviewers: jdoerfert, Meinersbur, fhahn, kbarton, hfinkel, bmahjour, etiotto.
Whitney added a project: LLVM.
Herald added subscribers: llvm-commits, hiraditya.
Blocks in a loop can be in any order as long as the loop header is the first block in Blocks.
With some order of Blocks, cloneLoopWithPreheader would trigger the assertion in addBasicBlockToLoop.
Example:
header.i:
br header.j
header.j:
br header.k
header.k:
br latch.k
latch.k:
br header.k, latch.j
latch.j:
br header.j, latch.i
latch.i:
br header.i, exit
If the blocks of loop-i is in the order: header.i, latch.k, header.k, header.j, latch.j, latch.i,
then cloneLoopWithPreheader would trigger the assertion in addBasicBlockToLoop
`assert(contains(SameHeader) && getHeader() == SameHeader->getHeader() && "Incorrect LI specified for this loop!");`
As latch.k is in both loop-j and loop-k, it would be set as the header of both loops after adding latch.k.
If we update loop headers during cloning blocks, then after adding header.k,
the header of loop-k would be updated with header.k,
while the header of loop-j stays as latch.k.
When adding header.j, SameHeader is loop-k, SameHeader->getHeader() is header.k, but getHeader() is latch.k, which trigger the assertion.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D74382
Files:
llvm/lib/Transforms/Utils/CloneFunction.cpp
Index: llvm/lib/Transforms/Utils/CloneFunction.cpp
===================================================================
--- llvm/lib/Transforms/Utils/CloneFunction.cpp
+++ llvm/lib/Transforms/Utils/CloneFunction.cpp
@@ -804,8 +804,6 @@
// Update LoopInfo.
NewLoop->addBasicBlockToLoop(NewBB, *LI);
- if (BB == CurLoop->getHeader())
- NewLoop->moveToHeader(NewBB);
// Add DominatorTree node. After seeing all blocks, update to correct
// IDom.
@@ -815,6 +813,11 @@
}
for (BasicBlock *BB : OrigLoop->getBlocks()) {
+ // Update loop headers.
+ Loop *CurLoop = LI->getLoopFor(BB);
+ if (BB == CurLoop->getHeader())
+ LMap[CurLoop]->moveToHeader(cast<BasicBlock>(VMap[BB]));
+
// Update DominatorTree.
BasicBlock *IDomBB = DT->getNode(BB)->getIDom()->getBlock();
DT->changeImmediateDominator(cast<BasicBlock>(VMap[BB]),
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D74382.243735.patch
Type: text/x-patch
Size: 883 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200211/553cbf16/attachment.bin>
More information about the llvm-commits
mailing list