[llvm-commits] [llvm] r86299 - /llvm/trunk/lib/Transforms/Scalar/JumpThreading.cpp

Chris Lattner sabre at nondot.org
Fri Nov 6 15:19:58 PST 2009


Author: lattner
Date: Fri Nov  6 17:19:58 2009
New Revision: 86299

URL: http://llvm.org/viewvc/llvm-project?rev=86299&view=rev
Log:
Fix a bug where we'd call SplitBlockPredecessors with a pred in the 
set only once even if it has multiple edges to BB.

Modified:
    llvm/trunk/lib/Transforms/Scalar/JumpThreading.cpp

Modified: llvm/trunk/lib/Transforms/Scalar/JumpThreading.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Scalar/JumpThreading.cpp?rev=86299&r1=86298&r2=86299&view=diff

==============================================================================
--- llvm/trunk/lib/Transforms/Scalar/JumpThreading.cpp (original)
+++ llvm/trunk/lib/Transforms/Scalar/JumpThreading.cpp Fri Nov  6 17:19:58 2009
@@ -940,8 +940,17 @@
   // 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)





More information about the llvm-commits mailing list