In mem2reg, for all alloca/stores that get promoted where the alloca has an associate...
[oota-llvm.git] / lib / Transforms / Utils / LoopSimplify.cpp
index 44a2c1f851819c19c385ef41c764af659e10ff3a..e81b77974abb8a91b29ac2eb24b5634a414c2840 100644 (file)
@@ -109,7 +109,7 @@ X("loopsimplify", "Canonicalize natural loops", true);
 const PassInfo *const llvm::LoopSimplifyID = &X;
 Pass *llvm::createLoopSimplifyPass() { return new LoopSimplify(); }
 
-/// runOnFunction - Run down all loops in the CFG (recursively, but we could do
+/// runOnLoop - Run down all loops in the CFG (recursively, but we could do
 /// it in any convenient order) inserting preheaders...
 ///
 bool LoopSimplify::runOnLoop(Loop *l, LPPassManager &LPM) {
@@ -232,7 +232,7 @@ ReprocessLoop:
       PN->eraseFromParent();
     }
 
-  // If this loop has muliple exits and the exits all go to the same
+  // 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
   // as LoopRotation, which do not support loops with multiple exits.
   // SimplifyCFG also does this (and this code uses the same utility
@@ -305,12 +305,6 @@ ReprocessLoop:
     }
   }
 
-  // If there are duplicate phi nodes (for example, from loop rotation),
-  // get rid of them.
-  for (Loop::block_iterator BB = L->block_begin(), E = L->block_end();
-       BB != E; ++BB)
-    EliminateDuplicatePHINodes(*BB);
-
   return Changed;
 }
 
@@ -477,8 +471,13 @@ Loop *LoopSimplify::SeparateNestedLoop(Loop *L, LPPassManager &LPM) {
   SmallVector<BasicBlock*, 8> OuterLoopPreds;
   for (unsigned i = 0, e = PN->getNumIncomingValues(); i != e; ++i)
     if (PN->getIncomingValue(i) != PN ||
-        !L->contains(PN->getIncomingBlock(i)))
+        !L->contains(PN->getIncomingBlock(i))) {
+      // We can't split indirectbr edges.
+      if (isa<IndirectBrInst>(PN->getIncomingBlock(i)->getTerminator()))
+        return 0;
+
       OuterLoopPreds.push_back(PN->getIncomingBlock(i));
+    }
 
   BasicBlock *Header = L->getHeader();
   BasicBlock *NewBB = SplitBlockPredecessors(Header, &OuterLoopPreds[0],