summaryrefslogtreecommitdiff
path: root/lib/Transforms/Utils/BreakCriticalEdges.cpp
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2005-08-13 01:38:43 +0000
committerChris Lattner <sabre@nondot.org>2005-08-13 01:38:43 +0000
commit0ae380a8ac48cbf3131f96318a15dc5dae8a6c78 (patch)
tree72643f2a6157bad5e5f853c0f5ab66dbc19b0657 /lib/Transforms/Utils/BreakCriticalEdges.cpp
parent8385393dc897ddba1cd86c5a05dd85df63316d87 (diff)
downloadllvm-0ae380a8ac48cbf3131f96318a15dc5dae8a6c78.tar.gz
llvm-0ae380a8ac48cbf3131f96318a15dc5dae8a6c78.tar.bz2
llvm-0ae380a8ac48cbf3131f96318a15dc5dae8a6c78.tar.xz
Teach SplitCriticalEdge to update LoopInfo if it is alive. This fixes
a problem in LoopStrengthReduction, where it would split critical edges then confused itself with outdated loop information. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@22776 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Transforms/Utils/BreakCriticalEdges.cpp')
-rw-r--r--lib/Transforms/Utils/BreakCriticalEdges.cpp31
1 files changed, 31 insertions, 0 deletions
diff --git a/lib/Transforms/Utils/BreakCriticalEdges.cpp b/lib/Transforms/Utils/BreakCriticalEdges.cpp
index 59ec01c7d5..7e44574a6e 100644
--- a/lib/Transforms/Utils/BreakCriticalEdges.cpp
+++ b/lib/Transforms/Utils/BreakCriticalEdges.cpp
@@ -19,6 +19,7 @@
#include "llvm/Transforms/Scalar.h"
#include "llvm/Transforms/Utils/BasicBlockUtils.h"
#include "llvm/Analysis/Dominators.h"
+#include "llvm/Analysis/LoopInfo.h"
#include "llvm/Function.h"
#include "llvm/Instructions.h"
#include "llvm/Type.h"
@@ -37,6 +38,7 @@ namespace {
AU.addPreserved<ImmediateDominators>();
AU.addPreserved<DominatorTree>();
AU.addPreserved<DominanceFrontier>();
+ AU.addPreserved<LoopInfo>();
// No loop canonicalization guarantees are broken by this pass.
AU.addPreservedID(LoopSimplifyID);
@@ -171,5 +173,34 @@ bool llvm::SplitCriticalEdge(TerminatorInst *TI, unsigned SuccNum, Pass *P) {
NewDFSet.insert(DestBB);
DF->addBasicBlock(NewBB, NewDFSet);
}
+
+ // Update LoopInfo if it is around.
+ if (LoopInfo *LI = P->getAnalysisToUpdate<LoopInfo>()) {
+ // If one or the other blocks were not in a loop, the new block is not
+ // either, and thus LI doesn't need to be updated.
+ if (Loop *TIL = LI->getLoopFor(TIBB))
+ if (Loop *DestLoop = LI->getLoopFor(DestBB)) {
+ if (TIL == DestLoop) {
+ // Both in the same loop, the NewBB joins loop.
+ DestLoop->addBasicBlockToLoop(NewBB, *LI);
+ } else if (TIL->contains(DestLoop->getHeader())) {
+ // Edge from an outer loop to an inner loop. Add to the outer lopo.
+ TIL->addBasicBlockToLoop(NewBB, *LI);
+ } else if (DestLoop->contains(TIL->getHeader())) {
+ // Edge from an inner loop to an outer loop. Add to the outer lopo.
+ DestLoop->addBasicBlockToLoop(NewBB, *LI);
+ } else {
+ // Edge from two loops with no containment relation. Because these
+ // are natural loops, we know that the destination block must be the
+ // header of its loop (adding a branch into a loop elsewhere would
+ // create an irreducible loop).
+ assert(DestLoop->getHeader() == DestBB &&
+ "Should not create irreducible loops!");
+ if (Loop *P = DestLoop->getParentLoop())
+ P->addBasicBlockToLoop(NewBB, *LI);
+ }
+ }
+
+ }
return true;
}