strengthen an assumption: RevectorBlockTo knows that PredBB
authorChris Lattner <sabre@nondot.org>
Sun, 1 Nov 2009 04:23:20 +0000 (04:23 +0000)
committerChris Lattner <sabre@nondot.org>
Sun, 1 Nov 2009 04:23:20 +0000 (04:23 +0000)
ended in an uncond branch because the pass requires BreakCriticalEdges.

However, BCE doesn't eliminate critical adges from indbrs.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@85707 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Transforms/Scalar/CondPropagate.cpp

index 5b573f492cdc47734ed011cbfaf50462fbde2b51..8a6c5562eb9eaf5855650073aa953e9fbfeeedbf 100644 (file)
@@ -196,18 +196,20 @@ void CondProp::SimplifyPredecessors(SwitchInst *SI) {
   // possible, and to avoid invalidating "i".
   for (unsigned i = PN->getNumIncomingValues(); i != 0; --i)
     if (ConstantInt *CI = dyn_cast<ConstantInt>(PN->getIncomingValue(i-1))) {
-      // If we have a constant, forward the edge from its current to its
-      // ultimate destination.
-      unsigned DestCase = SI->findCaseValue(CI);
-      RevectorBlockTo(PN->getIncomingBlock(i-1),
-                      SI->getSuccessor(DestCase));
-      ++NumSwThread;
-
-      // If there were two predecessors before this simplification, or if the
-      // PHI node contained all the same value except for the one we just
-      // substituted, the PHI node may be deleted.  Don't iterate through it the
-      // last time.
-      if (SI->getCondition() != PN) return;
+      BasicBlock *PredBB = PN->getIncomingBlock(i-1);
+      if (isa<BranchInst>(PredBB->getTerminator())) {
+        // If we have a constant, forward the edge from its current to its
+        // ultimate destination.
+        unsigned DestCase = SI->findCaseValue(CI);
+        RevectorBlockTo(PredBB, SI->getSuccessor(DestCase));
+        ++NumSwThread;
+
+        // If there were two predecessors before this simplification, or if the
+        // PHI node contained all the same value except for the one we just
+        // substituted, the PHI node may be deleted.  Don't iterate through it the
+        // last time.
+        if (SI->getCondition() != PN) return;
+      }
     }
 }