From: Chris Lattner Date: Mon, 13 Dec 2010 05:15:29 +0000 (+0000) Subject: move HoistThenElseCodeToIf up to a more logical and efficient-to-handle place. X-Git-Url: http://plrg.eecs.uci.edu/git/?a=commitdiff_plain;h=ef5002ba85121178766edd096818a781fdc2dece;p=oota-llvm.git 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 --- diff --git a/lib/Transforms/Utils/SimplifyCFG.cpp b/lib/Transforms/Utils/SimplifyCFG.cpp index 52ad1ee0704..7c80a3dd7a4 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(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) {