SimplifyCFG: Enumerating all predecessors of a BB can be expensive (switches), avoid...
authorBenjamin Kramer <benny.kra@googlemail.com>
Sun, 30 Sep 2012 21:03:56 +0000 (21:03 +0000)
committerBenjamin Kramer <benny.kra@googlemail.com>
Sun, 30 Sep 2012 21:03:56 +0000 (21:03 +0000)
No functionality change.

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

lib/Transforms/Utils/SimplifyCFG.cpp

index 065325b7c25e889f4ebb15c2e0ab5870be29aa98..a5e4d44b85ee73312cf808447eb5603cd906b40b 100644 (file)
@@ -1173,10 +1173,14 @@ static bool SinkThenElseCodeToEnd(BranchInst *BI1) {
 
   // Check that BBEnd has two predecessors and the other predecessor ends with
   // an unconditional branch.
-  SmallVector<BasicBlock*, 16> Preds(pred_begin(BBEnd), pred_end(BBEnd));
-  if (Preds.size() != 2)
+  pred_iterator PI = pred_begin(BBEnd), PE = pred_end(BBEnd);
+  BasicBlock *Pred0 = *PI++;
+  if (PI == PE) // Only one predecessor.
     return false;
-  BasicBlock *BB2 = (Preds[0] == BB1) ? Preds[1] : Preds[0];
+  BasicBlock *Pred1 = *PI++;
+  if (PI != PE) // More than two predecessors.
+    return false;
+  BasicBlock *BB2 = (Pred0 == BB1) ? Pred1 : Pred0;
   BranchInst *BI2 = dyn_cast<BranchInst>(BB2->getTerminator());
   if (!BI2 || !BI2->isUnconditional())
     return false;