From: Chris Lattner Date: Sat, 8 Jan 2011 18:06:22 +0000 (+0000) Subject: LoopRotate requires canonical loop form, so it always has preheaders X-Git-Url: http://plrg.eecs.uci.edu/git/?a=commitdiff_plain;h=2aa69082310f48162cb732efdc41613391796cd7;p=oota-llvm.git 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 --- diff --git a/lib/Transforms/Scalar/LoopRotation.cpp b/lib/Transforms/Scalar/LoopRotation.cpp index f3894417826..1af468aa2a9 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(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(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.