summaryrefslogtreecommitdiff
path: root/lib/Transforms/Utils/LoopSimplify.cpp
diff options
context:
space:
mode:
authorDuncan Sands <baldrick@free.fr>2010-11-18 19:59:41 +0000
committerDuncan Sands <baldrick@free.fr>2010-11-18 19:59:41 +0000
commitd0c6f3dafd7c3e9137d4e6415014c94137fcd3fc (patch)
tree99b6f88540f7b3c4a552911c4020f9e8a42ab9eb /lib/Transforms/Utils/LoopSimplify.cpp
parent707120047e0107cb15dd4bbb31613df129b13c7a (diff)
downloadllvm-d0c6f3dafd7c3e9137d4e6415014c94137fcd3fc.tar.gz
llvm-d0c6f3dafd7c3e9137d4e6415014c94137fcd3fc.tar.bz2
llvm-d0c6f3dafd7c3e9137d4e6415014c94137fcd3fc.tar.xz
Factor code for testing whether replacing one value with another
preserves LCSSA form out of ScalarEvolution and into the LoopInfo class. Use it to check that SimplifyInstruction simplifications are not breaking LCSSA form. Fixes PR8622. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@119727 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Transforms/Utils/LoopSimplify.cpp')
-rw-r--r--lib/Transforms/Utils/LoopSimplify.cpp30
1 files changed, 16 insertions, 14 deletions
diff --git a/lib/Transforms/Utils/LoopSimplify.cpp b/lib/Transforms/Utils/LoopSimplify.cpp
index 320223c247..f77a58300f 100644
--- a/lib/Transforms/Utils/LoopSimplify.cpp
+++ b/lib/Transforms/Utils/LoopSimplify.cpp
@@ -269,11 +269,12 @@ ReprocessLoop:
PHINode *PN;
for (BasicBlock::iterator I = L->getHeader()->begin();
(PN = dyn_cast<PHINode>(I++)); )
- if (Value *V = SimplifyInstruction(PN, 0, DT)) {
- if (AA) AA->deleteValue(PN);
- PN->replaceAllUsesWith(V);
- PN->eraseFromParent();
- }
+ if (Value *V = SimplifyInstruction(PN, 0, DT))
+ if (LI->replacementPreservesLCSSAForm(PN, V)) {
+ if (AA) AA->deleteValue(PN);
+ PN->replaceAllUsesWith(V);
+ PN->eraseFromParent();
+ }
// If this loop has multiple exits and the exits all go to the same
// block, attempt to merge the exits. This helps several passes, such
@@ -445,17 +446,18 @@ static void AddBlockAndPredsToSet(BasicBlock *InputBB, BasicBlock *StopBlock,
/// FindPHIToPartitionLoops - The first part of loop-nestification is to find a
/// PHI node that tells us how to partition the loops.
static PHINode *FindPHIToPartitionLoops(Loop *L, DominatorTree *DT,
- AliasAnalysis *AA) {
+ AliasAnalysis *AA, LoopInfo *LI) {
for (BasicBlock::iterator I = L->getHeader()->begin(); isa<PHINode>(I); ) {
PHINode *PN = cast<PHINode>(I);
++I;
- if (Value *V = SimplifyInstruction(PN, 0, DT)) {
- // This is a degenerate PHI already, don't modify it!
- PN->replaceAllUsesWith(V);
- if (AA) AA->deleteValue(PN);
- PN->eraseFromParent();
- continue;
- }
+ if (Value *V = SimplifyInstruction(PN, 0, DT))
+ if (LI->replacementPreservesLCSSAForm(PN, V)) {
+ // This is a degenerate PHI already, don't modify it!
+ PN->replaceAllUsesWith(V);
+ if (AA) AA->deleteValue(PN);
+ PN->eraseFromParent();
+ continue;
+ }
// Scan this PHI node looking for a use of the PHI node by itself.
for (unsigned i = 0, e = PN->getNumIncomingValues(); i != e; ++i)
@@ -523,7 +525,7 @@ void LoopSimplify::PlaceSplitBlockCarefully(BasicBlock *NewBB,
/// created.
///
Loop *LoopSimplify::SeparateNestedLoop(Loop *L, LPPassManager &LPM) {
- PHINode *PN = FindPHIToPartitionLoops(L, DT, AA);
+ PHINode *PN = FindPHIToPartitionLoops(L, DT, AA, LI);
if (PN == 0) return 0; // No known way to partition.
// Pull out all predecessors that have varying values in the loop. This