diff options
author | Benjamin Kramer <benny.kra@googlemail.com> | 2012-09-30 21:03:56 +0000 |
---|---|---|
committer | Benjamin Kramer <benny.kra@googlemail.com> | 2012-09-30 21:03:56 +0000 |
commit | f064b65a94df4b43024961f550c887d5a35162a5 (patch) | |
tree | 31037620664037eeab1d1605c5c1f3fbb9c2666c /llvm/lib/Transforms/Utils/SimplifyCFG.cpp | |
parent | 37f92c74d24fdb483bdcdf38e8935bba4e6b143e (diff) | |
download | bcm5719-llvm-f064b65a94df4b43024961f550c887d5a35162a5.tar.gz bcm5719-llvm-f064b65a94df4b43024961f550c887d5a35162a5.zip |
SimplifyCFG: Enumerating all predecessors of a BB can be expensive (switches), avoid it if possible.
No functionality change.
llvm-svn: 164923
Diffstat (limited to 'llvm/lib/Transforms/Utils/SimplifyCFG.cpp')
-rw-r--r-- | llvm/lib/Transforms/Utils/SimplifyCFG.cpp | 10 |
1 files changed, 7 insertions, 3 deletions
diff --git a/llvm/lib/Transforms/Utils/SimplifyCFG.cpp b/llvm/lib/Transforms/Utils/SimplifyCFG.cpp index 065325b7c25..a5e4d44b85e 100644 --- a/llvm/lib/Transforms/Utils/SimplifyCFG.cpp +++ b/llvm/lib/Transforms/Utils/SimplifyCFG.cpp @@ -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; |