From: Chris Lattner Date: Fri, 6 Nov 2009 18:24:32 +0000 (+0000) Subject: remove more code subsumed by r86264 X-Git-Url: http://demsky.eecs.uci.edu/git/?a=commitdiff_plain;h=90b924737750732fca2bd033b1315fd81891a14b;p=oota-llvm.git remove more code subsumed by r86264 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@86270 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Transforms/Scalar/JumpThreading.cpp b/lib/Transforms/Scalar/JumpThreading.cpp index ee9586a0b7f..f52110f8851 100644 --- a/lib/Transforms/Scalar/JumpThreading.cpp +++ b/lib/Transforms/Scalar/JumpThreading.cpp @@ -89,7 +89,6 @@ namespace { bool ProcessSwitchOnDuplicateCond(BasicBlock *PredBB, BasicBlock *DestBB); bool ProcessJumpOnPHI(PHINode *PN); - bool ProcessBranchOnCompare(CmpInst *Cmp, BasicBlock *BB); bool SimplifyPartiallyRedundantLoad(LoadInst *LI); }; @@ -480,34 +479,25 @@ bool JumpThreading::ProcessBlock(BasicBlock *BB) { return ProcessJumpOnPHI(PN); if (CmpInst *CondCmp = dyn_cast(CondInst)) { - if (isa(CondCmp->getOperand(0))) { - // If we have "br (phi != 42)" and the phi node has any constant values - // as operands, we can thread through this block. - // - // If we have "br (cmp phi, x)" and the phi node contains x such that the - // comparison uniquely identifies the branch target, we can thread - // through this block. - - if (ProcessBranchOnCompare(CondCmp, BB)) - return true; - } - - // If we have a comparison, loop over the predecessors to see if there is - // a condition with a lexically identical value. - pred_iterator PI = pred_begin(BB), E = pred_end(BB); - for (; PI != E; ++PI) - if (BranchInst *PBI = dyn_cast((*PI)->getTerminator())) - if (PBI->isConditional() && *PI != BB) { - if (CmpInst *CI = dyn_cast(PBI->getCondition())) { - if (CI->getOperand(0) == CondCmp->getOperand(0) && - CI->getOperand(1) == CondCmp->getOperand(1) && - CI->getPredicate() == CondCmp->getPredicate()) { - // TODO: Could handle things like (x != 4) --> (x == 17) - if (ProcessBranchOnDuplicateCond(*PI, BB)) - return true; + if (!isa(CondCmp->getOperand(0)) || + cast(CondCmp->getOperand(0))->getParent() != BB) { + // If we have a comparison, loop over the predecessors to see if there is + // a condition with a lexically identical value. + pred_iterator PI = pred_begin(BB), E = pred_end(BB); + for (; PI != E; ++PI) + if (BranchInst *PBI = dyn_cast((*PI)->getTerminator())) + if (PBI->isConditional() && *PI != BB) { + if (CmpInst *CI = dyn_cast(PBI->getCondition())) { + if (CI->getOperand(0) == CondCmp->getOperand(0) && + CI->getOperand(1) == CondCmp->getOperand(1) && + CI->getPredicate() == CondCmp->getPredicate()) { + // TODO: Could handle things like (x != 4) --> (x == 17) + if (ProcessBranchOnDuplicateCond(*PI, BB)) + return true; + } } } - } + } } // Check for some cases that are worth simplifying. Right now we want to look @@ -1028,62 +1018,6 @@ bool JumpThreading::ProcessJumpOnPHI(PHINode *PN) { return false; } -/// ProcessBranchOnCompare - We found a branch on a comparison between a phi -/// node and a value. If we can identify when the comparison is true between -/// the phi inputs and the value, we can fold the compare for that edge and -/// thread through it. -bool JumpThreading::ProcessBranchOnCompare(CmpInst *Cmp, BasicBlock *BB) { - PHINode *PN = cast(Cmp->getOperand(0)); - Value *RHS = Cmp->getOperand(1); - - // If the phi isn't in the current block, an incoming edge to this block - // doesn't control the destination. - if (PN->getParent() != BB) - return false; - - // We can do this simplification if any comparisons fold to true or false. - // See if any do. - Value *PredVal = 0; - bool TrueDirection = false; - for (unsigned i = 0, e = PN->getNumIncomingValues(); i != e; ++i) { - PredVal = PN->getIncomingValue(i); - - Constant *Res = GetResultOfComparison(Cmp->getPredicate(), PredVal, RHS); - if (!Res) { - PredVal = 0; - continue; - } - - // If this folded to a constant expr, we can't do anything. - if (ConstantInt *ResC = dyn_cast(Res)) { - TrueDirection = ResC->getZExtValue(); - break; - } - // If this folded to undef, just go the false way. - if (isa(Res)) { - TrueDirection = false; - break; - } - - // Otherwise, we can't fold this input. - PredVal = 0; - } - - // If no match, bail out. - if (PredVal == 0) - return false; - - // If so, we can actually do this threading. Merge any common predecessors - // that will act the same. - BasicBlock *PredBB = FactorCommonPHIPreds(PN, PredVal); - - // Next, get our successor. - BasicBlock *SuccBB = BB->getTerminator()->getSuccessor(!TrueDirection); - - // Ok, try to thread it! - return ThreadEdge(BB, PredBB, SuccBB); -} - /// AddPHINodeEntriesForMappedBlock - We're adding 'NewPred' as a new /// predecessor to the PHIBB block. If it has PHI nodes, add entries for