diff options
author | Chris Lattner <sabre@nondot.org> | 2005-03-06 20:57:32 +0000 |
---|---|---|
committer | Chris Lattner <sabre@nondot.org> | 2005-03-06 20:57:32 +0000 |
commit | 238f6df546ef8097ff2ee6ada4f334b4f4e9818a (patch) | |
tree | a6f2bccacff31277d07248f3d2415c693ee0606a /llvm/lib/Transforms | |
parent | 1c69aab68bba37f643bcab90a8069c578ac7fa34 (diff) | |
download | bcm5719-llvm-238f6df546ef8097ff2ee6ada4f334b4f4e9818a.tar.gz bcm5719-llvm-238f6df546ef8097ff2ee6ada4f334b4f4e9818a.zip |
Fix a bug where we could corrupt a parent loop's header info if we unrolled
a nested loop. This fixes Transforms/LoopUnroll/2005-03-06-BadLoopInfoUpdate.ll
and PR532
llvm-svn: 20493
Diffstat (limited to 'llvm/lib/Transforms')
-rw-r--r-- | llvm/lib/Transforms/Scalar/LoopUnroll.cpp | 23 |
1 files changed, 17 insertions, 6 deletions
diff --git a/llvm/lib/Transforms/Scalar/LoopUnroll.cpp b/llvm/lib/Transforms/Scalar/LoopUnroll.cpp index 8e625202455..da80ee342b9 100644 --- a/llvm/lib/Transforms/Scalar/LoopUnroll.cpp +++ b/llvm/lib/Transforms/Scalar/LoopUnroll.cpp @@ -283,16 +283,27 @@ bool LoopUnroll::visitLoop(Loop *L) { // Preheader. Preheader->replaceAllUsesWith(LoopExit); + Function *F = LoopExit->getParent(); + if (Parent) { + // Otherwise, if this is a sub-loop, and the preheader was the loop header + // of the parent loop, move the exit block to be the new parent loop header. + if (Parent->getHeader() == Preheader) { + assert(Parent->contains(LoopExit) && + "Exit block isn't contained in parent?"); + Parent->moveToHeader(LoopExit); + } + } else { + // If the preheader was the entry block of this function, move the exit + // block to be the new entry of the function. + if (Preheader == &F->front()) + F->getBasicBlockList().splice(F->begin(), + F->getBasicBlockList(), LoopExit); + } + // Remove BB and LoopExit from our analyses. LI->removeBlock(Preheader); LI->removeBlock(BB); - // If the preheader was the entry block of this function, move the exit block - // to be the new entry of the loop. - Function *F = LoopExit->getParent(); - if (Preheader == &F->front()) - F->getBasicBlockList().splice(F->begin(), F->getBasicBlockList(), LoopExit); - // Actually delete the blocks now. F->getBasicBlockList().erase(Preheader); F->getBasicBlockList().erase(BB); |