summaryrefslogtreecommitdiff
path: root/lib/Transforms/Utils/LoopSimplify.cpp
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2005-08-10 02:07:32 +0000
committerChris Lattner <sabre@nondot.org>2005-08-10 02:07:32 +0000
commit94f40324481c04ae8718967b4b5a3d7ca22370e6 (patch)
tree608f79469f26e0a0346794b34f28d3fb792af2be /lib/Transforms/Utils/LoopSimplify.cpp
parent8d56cdd0d1e51aebe25015ca92dde296a0709424 (diff)
downloadllvm-94f40324481c04ae8718967b4b5a3d7ca22370e6.tar.gz
llvm-94f40324481c04ae8718967b4b5a3d7ca22370e6.tar.bz2
llvm-94f40324481c04ae8718967b4b5a3d7ca22370e6.tar.xz
Make loop-simplify produce better loops by turning PHI nodes like X = phi [X, Y]
into just Y. This often occurs when it seperates loops that have collapsed loop headers. This implements LoopSimplify/phi-node-simplify.ll git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@22746 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Transforms/Utils/LoopSimplify.cpp')
-rw-r--r--lib/Transforms/Utils/LoopSimplify.cpp17
1 files changed, 16 insertions, 1 deletions
diff --git a/lib/Transforms/Utils/LoopSimplify.cpp b/lib/Transforms/Utils/LoopSimplify.cpp
index da1a6550a4..69b2ec4447 100644
--- a/lib/Transforms/Utils/LoopSimplify.cpp
+++ b/lib/Transforms/Utils/LoopSimplify.cpp
@@ -71,7 +71,7 @@ namespace {
AU.addPreserved<ImmediateDominators>();
AU.addPreserved<DominatorTree>();
AU.addPreserved<DominanceFrontier>();
- AU.addPreservedID(BreakCriticalEdgesID); // No crit edges added....
+ AU.addPreservedID(BreakCriticalEdgesID); // No critical edges added.
}
private:
bool ProcessLoop(Loop *L);
@@ -190,8 +190,23 @@ bool LoopSimplify::ProcessLoop(Loop *L) {
Changed = true;
}
+ // Scan over the PHI nodes in the loop header. Since they now have only two
+ // incoming values (the loop is canonicalized), we may have simplified the PHI
+ // down to 'X = phi [X, Y]', which should be replaced with 'Y'.
+ PHINode *PN;
+ DominatorSet &DS = getAnalysis<DominatorSet>();
+ for (BasicBlock::iterator I = L->getHeader()->begin();
+ (PN = dyn_cast<PHINode>(I++)); )
+ if (Value *V = PN->hasConstantValue(true))
+ if (!isa<Instruction>(V) ||
+ DS.dominates(cast<Instruction>(V)->getParent(), L->getHeader())) {
+ PN->replaceAllUsesWith(V);
+ PN->eraseFromParent();
+ }
+
for (Loop::iterator I = L->begin(), E = L->end(); I != E; ++I)
Changed |= ProcessLoop(*I);
+
return Changed;
}