aboutsummaryrefslogtreecommitdiffstats
path: root/lib/Transforms
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2010-12-13 05:10:48 +0000
committerChris Lattner <sabre@nondot.org>2010-12-13 05:10:48 +0000
commitddb97a2bf1f06d7d1b0a1af8e74c67917b43b606 (patch)
treea2949bc8c14ddf51ed3d8637c8419511d0d424ce /lib/Transforms
parentc232a2e559d50f2aa2cb2bfc5b895d07fd8ee3d0 (diff)
downloadexternal_llvm-ddb97a2bf1f06d7d1b0a1af8e74c67917b43b606.zip
external_llvm-ddb97a2bf1f06d7d1b0a1af8e74c67917b43b606.tar.gz
external_llvm-ddb97a2bf1f06d7d1b0a1af8e74c67917b43b606.tar.bz2
move 'MergeBlocksIntoPredecessor' call earlier. Use
getSinglePredecessor to simplify code. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@121683 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Transforms')
-rw-r--r--lib/Transforms/Utils/SimplifyCFG.cpp29
1 files changed, 9 insertions, 20 deletions
diff --git a/lib/Transforms/Utils/SimplifyCFG.cpp b/lib/Transforms/Utils/SimplifyCFG.cpp
index 4e58e49..52ad1ee 100644
--- a/lib/Transforms/Utils/SimplifyCFG.cpp
+++ b/lib/Transforms/Utils/SimplifyCFG.cpp
@@ -1957,6 +1957,13 @@ bool SimplifyCFGOpt::run(BasicBlock *BB) {
// Check for and eliminate duplicate PHI nodes in this block.
Changed |= EliminateDuplicatePHINodes(BB);
+ // Merge basic blocks into their predecessor if there is only one distinct
+ // pred, and if there is only one distinct successor of the predecessor, and
+ // if there are no PHI nodes.
+ //
+ if (MergeBlockIntoPredecessor(BB))
+ return true;
+
// If there is a trivial two-entry PHI node in this basic block, and we can
// eliminate it, do so now.
if (PHINode *PN = dyn_cast<PHINode>(BB->begin()))
@@ -2309,33 +2316,15 @@ bool SimplifyCFGOpt::run(BasicBlock *BB) {
}
}
- // Merge basic blocks into their predecessor if there is only one distinct
- // pred, and if there is only one distinct successor of the predecessor, and
- // if there are no PHI nodes.
- //
- if (MergeBlockIntoPredecessor(BB))
- return true;
-
// Otherwise, if this block only has a single predecessor, and if that block
// is a conditional branch, see if we can hoist any code from this block up
// into our predecessor.
- pred_iterator PI(pred_begin(BB)), PE(pred_end(BB));
- BasicBlock *OnlyPred = 0;
- for (; PI != PE; ++PI) { // Search all predecessors, see if they are all same
- if (!OnlyPred)
- OnlyPred = *PI;
- else if (*PI != OnlyPred) {
- OnlyPred = 0; // There are multiple different predecessors...
- break;
- }
- }
-
- if (OnlyPred) {
+ if (BasicBlock *OnlyPred = BB->getSinglePredecessor()) {
BranchInst *BI = dyn_cast<BranchInst>(OnlyPred->getTerminator());
if (BI && BI->isConditional()) {
// Get the other block.
BasicBlock *OtherBB = BI->getSuccessor(BI->getSuccessor(0) == BB);
- PI = pred_begin(OtherBB);
+ pred_iterator PI = pred_begin(OtherBB);
++PI;
if (PI == pred_end(OtherBB)) {