mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2024-11-02 07:11:49 +00:00
LoopUnroll: Create sub-loops in LoopInfo
`LoopUnrollPass` says that it preserves `LoopInfo` -- make it so. In particular, tell `LoopInfo` about copies of inner loops when unrolling the outer loop. Conservatively, also tell `ScalarEvolution` to forget about the original versions of these loops, since their inputs may have changed. Fixes PR20987. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@219241 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
25cfb5cff5
commit
de7465af34
@ -301,13 +301,41 @@ bool llvm::UnrollLoop(Loop *L, unsigned Count, unsigned TripCount,
|
||||
|
||||
for (unsigned It = 1; It != Count; ++It) {
|
||||
std::vector<BasicBlock*> NewBlocks;
|
||||
SmallDenseMap<const Loop *, Loop *, 4> NewLoops;
|
||||
NewLoops[L] = L;
|
||||
|
||||
for (LoopBlocksDFS::RPOIterator BB = BlockBegin; BB != BlockEnd; ++BB) {
|
||||
ValueToValueMapTy VMap;
|
||||
BasicBlock *New = CloneBasicBlock(*BB, VMap, "." + Twine(It));
|
||||
Header->getParent()->getBasicBlockList().push_back(New);
|
||||
|
||||
L->addBasicBlockToLoop(New, LI->getBase());
|
||||
// Tell LI about New.
|
||||
if (*BB == Header) {
|
||||
assert(LI->getLoopFor(*BB) == L && "Header should not be in a sub-loop");
|
||||
L->addBasicBlockToLoop(New, LI->getBase());
|
||||
} else {
|
||||
// Figure out which loop New is in.
|
||||
const Loop *OldLoop = LI->getLoopFor(*BB);
|
||||
assert(OldLoop && "Should (at least) be in the loop being unrolled!");
|
||||
|
||||
Loop *&NewLoop = NewLoops[OldLoop];
|
||||
if (!NewLoop) {
|
||||
// Found a new sub-loop.
|
||||
assert(*BB == OldLoop->getHeader() &&
|
||||
"Header should be first in RPO");
|
||||
|
||||
Loop *NewLoopParent = NewLoops.lookup(OldLoop->getParentLoop());
|
||||
assert(NewLoopParent &&
|
||||
"Expected parent loop before sub-loop in RPO");
|
||||
NewLoop = new Loop;
|
||||
NewLoopParent->addChildLoop(NewLoop);
|
||||
|
||||
// Forget the old loop, since its inputs may have changed.
|
||||
if (SE)
|
||||
SE->forgetLoop(OldLoop);
|
||||
}
|
||||
NewLoop->addBasicBlockToLoop(New, LI->getBase());
|
||||
}
|
||||
|
||||
if (*BB == Header)
|
||||
// Loop over all of the PHI nodes in the block, changing them to use
|
||||
|
35
test/Transforms/LoopUnroll/update-loop-info-in-subloops.ll
Normal file
35
test/Transforms/LoopUnroll/update-loop-info-in-subloops.ll
Normal file
@ -0,0 +1,35 @@
|
||||
; RUN: opt -S < %s -loop-unroll -block-freq | FileCheck %s
|
||||
; Crasher from PR20987.
|
||||
|
||||
; CHECK: define void @update_loop_info_in_subloops
|
||||
; CHECK: entry:
|
||||
; CHECK: L:
|
||||
; CHECK: L.inner:
|
||||
; CHECK: L.inner.latch:
|
||||
; CHECK: L.latch:
|
||||
; CHECK: L.inner.1:
|
||||
; CHECK: L.inner.latch.1:
|
||||
; CHECK: L.latch.1:
|
||||
|
||||
define void @update_loop_info_in_subloops() {
|
||||
entry:
|
||||
br label %L
|
||||
|
||||
L:
|
||||
%0 = phi i64 [ 1, %entry ], [ %1, %L.latch ]
|
||||
br label %L.inner
|
||||
|
||||
L.inner:
|
||||
br label %L.inner.latch
|
||||
|
||||
L.inner.latch:
|
||||
br i1 false, label %L.latch, label %L.inner
|
||||
|
||||
L.latch:
|
||||
%1 = add i64 %0, 1
|
||||
%2 = icmp eq i64 %1, 3
|
||||
br i1 %2, label %exit, label %L
|
||||
|
||||
exit:
|
||||
ret void
|
||||
}
|
Loading…
Reference in New Issue
Block a user