Fix a bug where we'd call SplitBlockPredecessors with a pred in the
authorChris Lattner <sabre@nondot.org>
Fri, 6 Nov 2009 23:19:58 +0000 (23:19 +0000)
committerChris Lattner <sabre@nondot.org>
Fri, 6 Nov 2009 23:19:58 +0000 (23:19 +0000)
set only once even if it has multiple edges to BB.

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

lib/Transforms/Scalar/JumpThreading.cpp

index 62f7d51ff8c8432047acc2687b749a1adaa88e25..4bbde1397c8404b81a27a0013c56a7561694320a 100644 (file)
@@ -940,8 +940,17 @@ bool JumpThreading::ProcessThreadableEdges(Instruction *CondInst,
   // predecessors that will jump to it into a single predecessor.
   SmallVector<BasicBlock*, 16> PredsToFactor;
   for (unsigned i = 0, e = PredToDestList.size(); i != e; ++i)
-    if (PredToDestList[i].second == MostPopularDest)
-      PredsToFactor.push_back(PredToDestList[i].first);
+    if (PredToDestList[i].second == MostPopularDest) {
+      BasicBlock *Pred = PredToDestList[i].first;
+      
+      // This predecessor may be a switch or something else that has multiple
+      // edges to the block.  Factor each of these edges by listing them
+      // according to # occurrences in PredsToFactor.
+      TerminatorInst *PredTI = Pred->getTerminator();
+      for (unsigned i = 0, e = PredTI->getNumSuccessors(); i != e; ++i)
+        if (PredTI->getSuccessor(i) == BB)
+          PredsToFactor.push_back(Pred);
+    }
 
   BasicBlock *PredToThread;
   if (PredsToFactor.size() == 1)