diff options
author | Chris Lattner <sabre@nondot.org> | 2010-12-13 05:15:29 +0000 |
---|---|---|
committer | Chris Lattner <sabre@nondot.org> | 2010-12-13 05:15:29 +0000 |
commit | ef5002ba85121178766edd096818a781fdc2dece (patch) | |
tree | a4eebccded660856e3ce71b08457544ee508efea /lib/Transforms/Utils/SimplifyCFG.cpp | |
parent | ddb97a2bf1f06d7d1b0a1af8e74c67917b43b606 (diff) |
move HoistThenElseCodeToIf up to a more logical and efficient-to-handle place.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@121684 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Transforms/Utils/SimplifyCFG.cpp')
-rw-r--r-- | lib/Transforms/Utils/SimplifyCFG.cpp | 18 |
1 files changed, 11 insertions, 7 deletions
diff --git a/lib/Transforms/Utils/SimplifyCFG.cpp b/lib/Transforms/Utils/SimplifyCFG.cpp index 52ad1ee070..7c80a3dd7a 100644 --- a/lib/Transforms/Utils/SimplifyCFG.cpp +++ b/lib/Transforms/Utils/SimplifyCFG.cpp @@ -2145,6 +2145,16 @@ bool SimplifyCFGOpt::run(BasicBlock *BB) { if (SimplifyBranchOnICmpChain(BI, TD)) return true; + + // We have a conditional branch to two blocks that are only reachable + // from BI. We know that the condbr dominates the two blocks, so see if + // there is any identical code in the "then" and "else" blocks. If so, we + // can hoist it up to the branching block. + if (BI->getSuccessor(0)->getSinglePredecessor() != 0 && + BI->getSuccessor(1)->getSinglePredecessor() != 0) + if (HoistThenElseCodeToIf(BI)) + return SimplifyCFG(BB) | true; + // If this is a branch on a phi node in the current block, thread control // through this block if any PHI node entries are constants. if (PHINode *PN = dyn_cast<PHINode>(BI->getCondition())) @@ -2327,13 +2337,7 @@ bool SimplifyCFGOpt::run(BasicBlock *BB) { pred_iterator PI = pred_begin(OtherBB); ++PI; - if (PI == pred_end(OtherBB)) { - // We have a conditional branch to two blocks that are only reachable - // from the condbr. We know that the condbr dominates the two blocks, - // so see if there is any identical code in the "then" and "else" - // blocks. If so, we can hoist it up to the branching block. - Changed |= HoistThenElseCodeToIf(BI); - } else { + if (PI != pred_end(OtherBB)) { BasicBlock* OnlySucc = NULL; for (succ_iterator SI = succ_begin(BB), SE = succ_end(BB); SI != SE; ++SI) { |