aboutsummaryrefslogtreecommitdiffstats
path: root/lib/Transforms/Scalar/LoopRotation.cpp
diff options
context:
space:
mode:
authorDan Gohman <gohman@apple.com>2010-08-17 17:39:21 +0000
committerDan Gohman <gohman@apple.com>2010-08-17 17:39:21 +0000
commita932bae406dcddd6e4e39f8253ca721559a9dffb (patch)
treebb782c7be300cfbfc1d5a8d82b003fb4f7460271 /lib/Transforms/Scalar/LoopRotation.cpp
parentbeaa774c74e92040e81695c71f22b88fea6efb32 (diff)
downloadexternal_llvm-a932bae406dcddd6e4e39f8253ca721559a9dffb.zip
external_llvm-a932bae406dcddd6e4e39f8253ca721559a9dffb.tar.gz
external_llvm-a932bae406dcddd6e4e39f8253ca721559a9dffb.tar.bz2
When rotating loops, put the original header at the bottom of the
loop, making the resulting loop significantly less ugly. Also, zap its trivial PHI nodes, since it's easy. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@111255 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Transforms/Scalar/LoopRotation.cpp')
-rw-r--r--lib/Transforms/Scalar/LoopRotation.cpp20
1 files changed, 20 insertions, 0 deletions
diff --git a/lib/Transforms/Scalar/LoopRotation.cpp b/lib/Transforms/Scalar/LoopRotation.cpp
index 1e4bfa9..31957dd 100644
--- a/lib/Transforms/Scalar/LoopRotation.cpp
+++ b/lib/Transforms/Scalar/LoopRotation.cpp
@@ -261,6 +261,26 @@ bool LoopRotate::rotateLoop(Loop *Lp, LPPassManager &LPM) {
// NewHeader is now the header of the loop.
L->moveToHeader(NewHeader);
+ // 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
+ // usually reorder blocks on its own to fix things like this up, but it's
+ // still nice to keep the IR readable.
+ //
+ // The original header should have only one predecessor at this point, since
+ // we checked that the loop had a proper preheader and unique backedge before
+ // we started.
+ assert(OrigHeader->getSinglePredecessor() &&
+ "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);
+
+ // TODO: We could just go ahead and merge OrigHeader into its predecessor
+ // at this point, if we don't mind updating dominator info.
+
+ // Establish a new preheader, update dominators, etc.
preserveCanonicalLoopForm(LPM);
++NumRotated;