aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2011-01-08 18:06:22 +0000
committerChris Lattner <sabre@nondot.org>2011-01-08 18:06:22 +0000
commit2aa69082310f48162cb732efdc41613391796cd7 (patch)
treeebc77fbb890b91e5942d5ac4ea93b38a03b24fdb
parent66fe0ded050a826c3c13bcece64f607f667e4845 (diff)
LoopRotate requires canonical loop form, so it always has preheaders
and latch blocks. Reorder entry conditions to make hte pass faster and more logical. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@123069 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--lib/Transforms/Scalar/LoopRotation.cpp26
1 files changed, 11 insertions, 15 deletions
diff --git a/lib/Transforms/Scalar/LoopRotation.cpp b/lib/Transforms/Scalar/LoopRotation.cpp
index f389441782..1af468aa2a 100644
--- a/lib/Transforms/Scalar/LoopRotation.cpp
+++ b/lib/Transforms/Scalar/LoopRotation.cpp
@@ -98,29 +98,22 @@ bool LoopRotate::runOnLoop(Loop *L, LPPassManager &LPM) {
/// Rotate loop LP. Return true if the loop is rotated.
bool LoopRotate::rotateLoop(Loop *L) {
- BasicBlock *OrigPreHeader = L->getLoopPreheader();
- if (!OrigPreHeader) return false;
-
- BasicBlock *OrigLatch = L->getLoopLatch();
- if (!OrigLatch) return false;
-
- BasicBlock *OrigHeader = L->getHeader();
-
// If the loop has only one block then there is not much to rotate.
if (L->getBlocks().size() == 1)
return false;
-
+
+ BasicBlock *OrigHeader = L->getHeader();
+
+ BranchInst *BI = dyn_cast<BranchInst>(OrigHeader->getTerminator());
+ if (BI == 0 || BI->isUnconditional())
+ return false;
+
// If the loop header is not one of the loop exiting blocks then
// either this loop is already rotated or it is not
// suitable for loop rotation transformations.
if (!L->isLoopExiting(OrigHeader))
return false;
- BranchInst *BI = dyn_cast<BranchInst>(OrigHeader->getTerminator());
- if (!BI)
- return false;
- assert(BI->isConditional() && "Branch Instruction is not conditional");
-
// Updating PHInodes in loops with multiple exits adds complexity.
// Keep it simple, and restrict loop rotation to loops with one exit only.
// In future, lift this restriction and support for multiple exits if
@@ -139,6 +132,9 @@ bool LoopRotate::rotateLoop(Loop *L) {
}
// Now, this loop is suitable for rotation.
+ BasicBlock *OrigPreHeader = L->getLoopPreheader();
+ BasicBlock *OrigLatch = L->getLoopLatch();
+ assert(OrigPreHeader && OrigLatch && "Loop not in canonical form?");
// Anything ScalarEvolution may know about this loop or the PHI nodes
// in its header will soon be invalidated.
@@ -300,7 +296,7 @@ bool LoopRotate::rotateLoop(Loop *L) {
// Also, since this original header only has one predecessor, zap its
// PHI nodes, which are now trivial.
FoldSingleEntryPHINodes(OrigHeader);
-
+
// TODO: We could just go ahead and merge OrigHeader into its predecessor
// at this point, if we don't mind updating dominator info.