[llvm-commits] [llvm] r164923 - /llvm/trunk/lib/Transforms/Utils/SimplifyCFG.cpp
Benjamin Kramer
benny.kra at googlemail.com
Sun Sep 30 14:03:56 PDT 2012
Author: d0k
Date: Sun Sep 30 16:03:56 2012
New Revision: 164923
URL: http://llvm.org/viewvc/llvm-project?rev=164923&view=rev
Log:
SimplifyCFG: Enumerating all predecessors of a BB can be expensive (switches), avoid it if possible.
No functionality change.
Modified:
llvm/trunk/lib/Transforms/Utils/SimplifyCFG.cpp
Modified: llvm/trunk/lib/Transforms/Utils/SimplifyCFG.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Utils/SimplifyCFG.cpp?rev=164923&r1=164922&r2=164923&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/Utils/SimplifyCFG.cpp (original)
+++ llvm/trunk/lib/Transforms/Utils/SimplifyCFG.cpp Sun Sep 30 16:03:56 2012
@@ -1173,10 +1173,14 @@
// 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;
More information about the llvm-commits
mailing list