summaryrefslogtreecommitdiffstats
path: root/llvm/lib
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2011-01-08 19:10:28 +0000
committerChris Lattner <sabre@nondot.org>2011-01-08 19:10:28 +0000
commit2615130e1d1f6ab3e7d315715e31ee4d3c7d1465 (patch)
treedb5f1d2ff8748b77287d05d8345b80d6b6141e8f /llvm/lib
parent930b716e1badd7751f7f76ab90aea5d4b26d5f03 (diff)
downloadbcm5719-llvm-2615130e1d1f6ab3e7d315715e31ee4d3c7d1465.tar.gz
bcm5719-llvm-2615130e1d1f6ab3e7d315715e31ee4d3c7d1465.zip
Implement a TODO: Enhance loopinfo to merge away the unconditional branch
that it was leaving in loops after rotation (between the original latch block and the original header. With this change, it is possible for rotated loops to have just a single basic block, which is useful. llvm-svn: 123075
Diffstat (limited to 'llvm/lib')
-rw-r--r--llvm/lib/Transforms/Scalar/LoopRotation.cpp18
1 files changed, 7 insertions, 11 deletions
diff --git a/llvm/lib/Transforms/Scalar/LoopRotation.cpp b/llvm/lib/Transforms/Scalar/LoopRotation.cpp
index 079ff92d454..3bc2011a47f 100644
--- a/llvm/lib/Transforms/Scalar/LoopRotation.cpp
+++ b/llvm/lib/Transforms/Scalar/LoopRotation.cpp
@@ -264,6 +264,7 @@ bool LoopRotate::rotateLoop(Loop *L) {
// NewHeader is now the header of the loop.
L->moveToHeader(NewHeader);
+ assert(L->getHeader() == NewHeader && "Latch block is our new header");
// Move the original header to the bottom of the loop, where it now more
// naturally belongs. This isn't necessary for correctness, and CodeGen can
@@ -277,16 +278,9 @@ bool LoopRotate::rotateLoop(Loop *L) {
"Original loop header has too many predecessors after loop rotation!");
OrigHeader->moveAfter(OrigHeader->getSinglePredecessor());
- // Also, since this original header only has one predecessor, zap its
- // PHI nodes, which are now trivial.
- FoldSingleEntryPHINodes(OrigHeader);
-
-
// Update DominatorTree to reflect the CFG change we just made. Then split
// edges as necessary to preserve LoopSimplify form.
- assert(L->getHeader() == NewHeader && "Latch block is our new header");
-
if (DominatorTree *DT = getAnalysisIfAvailable<DominatorTree>()) {
// Since OrigPreheader now has the conditional branch to Exit block, it is
// the dominator of Exit.
@@ -310,12 +304,14 @@ bool LoopRotate::rotateLoop(Loop *L) {
"Invalid loop preheader after loop rotation");
assert(L->getLoopLatch() && "Invalid loop latch after loop rotation");
-
- // TODO: We could just go ahead and merge OrigHeader into its predecessor
- // at this point, if we don't mind updating dominator info.
+ // Now that the CFG and DomTree are in a consistent state again, merge the
+ // OrigHeader block into OrigLatch. We know that they are joined by an
+ // unconditional branch. This is just a cleanup so the emitted code isn't
+ // too gross.
+ bool DidIt = MergeBlockIntoPredecessor(OrigHeader, this);
+ assert(DidIt && "Block merge failed??"); (void)DidIt;
++NumRotated;
return true;
}
-
OpenPOWER on IntegriCloud