From 6b65f47ad5d4da8bab31802a2c3df88379f0c9d9 Mon Sep 17 00:00:00 2001 From: Chris Lattner Date: Sun, 11 Oct 2009 04:40:21 +0000 Subject: [PATCH] restructure some code, no functionality change. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@83756 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Transforms/Scalar/JumpThreading.cpp | 62 ++++++++++++------------- 1 file changed, 29 insertions(+), 33 deletions(-) diff --git a/lib/Transforms/Scalar/JumpThreading.cpp b/lib/Transforms/Scalar/JumpThreading.cpp index 0816f3cb720..8855ddf88e2 100644 --- a/lib/Transforms/Scalar/JumpThreading.cpp +++ b/lib/Transforms/Scalar/JumpThreading.cpp @@ -651,51 +651,47 @@ bool JumpThreading::SimplifyPartiallyRedundantLoad(LoadInst *LI) { /// inputs to the phi node. /// bool JumpThreading::ProcessJumpOnPHI(PHINode *PN) { + BasicBlock *BB = PN->getParent(); + // See if the phi node has any constant integer or undef values. If so, we // can determine where the corresponding predecessor will branch. - Constant *PredCst = 0; for (unsigned i = 0, e = PN->getNumIncomingValues(); i != e; ++i) { Value *PredVal = PN->getIncomingValue(i); + + // Check to see if this input is a constant integer. If so, the direction + // of the branch is predictable. if (ConstantInt *CI = dyn_cast(PredVal)) { - PredCst = CI; - break; + // Merge any common predecessors that will act the same. + BasicBlock *PredBB = FactorCommonPHIPreds(PN, CI); + + BasicBlock *SuccBB; + if (BranchInst *BI = dyn_cast(BB->getTerminator())) + SuccBB = BI->getSuccessor(CI->isZero()); + else { + SwitchInst *SI = cast(BB->getTerminator()); + SuccBB = SI->getSuccessor(SI->findCaseValue(CI)); + } + + // Ok, try to thread it! + return ThreadEdge(BB, PredBB, SuccBB); } + // If the input is an undef, then it doesn't matter which way it will go. + // Pick an arbitrary dest and thread the edge. if (UndefValue *UV = dyn_cast(PredVal)) { - PredCst = UV; - break; + // Merge any common predecessors that will act the same. + BasicBlock *PredBB = FactorCommonPHIPreds(PN, UV); + BasicBlock *SuccBB = + BB->getTerminator()->getSuccessor(GetBestDestForJumpOnUndef(BB)); + + // Ok, try to thread it! + return ThreadEdge(BB, PredBB, SuccBB); } - } + } // If no incoming value has a constant, we don't know the destination of any // predecessors. - if (PredCst == 0) { - return false; - } - - // See if the cost of duplicating this block is low enough. - BasicBlock *BB = PN->getParent(); - - // If so, we can actually do this threading. Merge any common predecessors - // that will act the same. - BasicBlock *PredBB = FactorCommonPHIPreds(PN, PredCst); - - TerminatorInst *BBTerm = BB->getTerminator(); - - // Next, figure out which successor we are threading to. - BasicBlock *SuccBB; - if (isa(PredCst)) { - // If the branch was going off an undef from PredBB, pick an arbitrary dest. - SuccBB = BBTerm->getSuccessor(GetBestDestForJumpOnUndef(BB)); - } else if (BranchInst *BI = dyn_cast(BBTerm)) - SuccBB = BI->getSuccessor(cast(PredCst)->isZero()); - else { - SwitchInst *SI = cast(BBTerm); - SuccBB = SI->getSuccessor(SI->findCaseValue(cast(PredCst))); - } - - // Ok, try to thread it! - return ThreadEdge(BB, PredBB, SuccBB); + return false; } /// ProcessJumpOnLogicalPHI - PN's basic block contains a conditional branch