diff options
author | Xinliang David Li <davidxl@google.com> | 2017-08-21 16:00:38 +0000 |
---|---|---|
committer | Xinliang David Li <davidxl@google.com> | 2017-08-21 16:00:38 +0000 |
commit | d2838fc4b93a79a29d1f6d56b11eec2d30b01b58 (patch) | |
tree | 48570780429abbe74aaae86a81a2370e319f8281 /llvm/lib/Transforms/Scalar/JumpThreading.cpp | |
parent | 707f786cc5c78730bd8009af11a7a7473a699b32 (diff) | |
download | bcm5719-llvm-d2838fc4b93a79a29d1f6d56b11eec2d30b01b58.tar.gz bcm5719-llvm-d2838fc4b93a79a29d1f6d56b11eec2d30b01b58.zip |
Revert 311208, 311209
llvm-svn: 311341
Diffstat (limited to 'llvm/lib/Transforms/Scalar/JumpThreading.cpp')
-rw-r--r-- | llvm/lib/Transforms/Scalar/JumpThreading.cpp | 113 |
1 files changed, 1 insertions, 112 deletions
diff --git a/llvm/lib/Transforms/Scalar/JumpThreading.cpp b/llvm/lib/Transforms/Scalar/JumpThreading.cpp index eb18f1e23cb..1c65c6c5659 100644 --- a/llvm/lib/Transforms/Scalar/JumpThreading.cpp +++ b/llvm/lib/Transforms/Scalar/JumpThreading.cpp @@ -126,113 +126,7 @@ JumpThreadingPass::JumpThreadingPass(int T) { BBDupThreshold = (T == -1) ? BBDuplicateThreshold : unsigned(T); } -// Update branch probability information according to conditional -// branch probablity. This is usually made possible for cloned branches -// in inline instances by the context specific profile in the caller. -// For instance, -// -// [Block PredBB] -// [Branch PredBr] -// if (t) { -// Block A; -// } else { -// Block B; -// } -// -// [Block BB] -// cond = PN([true, %A], [..., %B]); // PHI node -// [Branch CondBr] -// if (cond) { -// ... // P(cond == true) = 1% -// } -// -// Here we know that when block A is taken, cond must be true, which means -// P(cond == true | A) = 1 -// -// Given that P(cond == true) = P(cond == true | A) * P(A) + -// P(cond == true | B) * P(B) -// we get -// P(cond == true ) = P(A) + P(cond == true | B) * P(B) -// -// which gives us: -// P(A) <= P(c == true), i.e. -// P(t == true) <= P(cond == true) -// -// In other words, if we know P(cond == true), we know that P(t == true) -// can not be greater than 1%. -static void updatePredecessorProfileMetadata(PHINode *PN, BasicBlock *BB) { - BranchInst *CondBr = dyn_cast<BranchInst>(BB->getTerminator()); - if (!CondBr) - return; - - BranchProbability BP; - uint64_t TrueWeight, FalseWeight; - if (!CondBr->extractProfMetadata(TrueWeight, FalseWeight)) - return; - - // Returns the outgoing edge of the dominating predecessor block - // that leads to the PhiNode's incoming block: - auto GetPredOutEdge = - [](BasicBlock *IncomingBB, - BasicBlock *PhiBB) -> std::pair<BasicBlock *, BasicBlock *> { - auto *PredBB = IncomingBB; - while (auto *SinglePredBB = PredBB->getSinglePredecessor()) - PredBB = SinglePredBB; - - BranchInst *PredBr = dyn_cast<BranchInst>(IncomingBB->getTerminator()); - if (PredBr && PredBr->isConditional()) - return {IncomingBB, PhiBB}; - - return {nullptr, nullptr}; - }; - - for (unsigned i = 0, e = PN->getNumIncomingValues(); i != e; ++i) { - Value *PhiOpnd = PN->getIncomingValue(i); - ConstantInt *CI = dyn_cast<ConstantInt>(PhiOpnd); - - if (!CI || !CI->getType()->isIntegerTy(1)) - continue; - - BP = (CI->isOne() ? BranchProbability::getBranchProbability( - TrueWeight, TrueWeight + FalseWeight) - : BranchProbability::getBranchProbability( - FalseWeight, TrueWeight + FalseWeight)); - - auto PredOutEdge = GetPredOutEdge(PN->getIncomingBlock(i), BB); - if (!PredOutEdge.first) - return; - - BasicBlock *PredBB = PredOutEdge.first; - BranchInst *PredBr = cast<BranchInst>(PredBB->getTerminator()); - - uint64_t PredTrueWeight, PredFalseWeight; - // FIXME: We currently only set the profile data when it is missing. - // With PGO, this can be used to refine even existing profile data with - // context information. This needs to be done after more performance - // testing. - if (PredBr->extractProfMetadata(PredTrueWeight, PredFalseWeight)) - continue; - - // We can not infer anything useful when BP >= 50%, because BP is the - // upper bound probability value. - if (BP >= BranchProbability(50, 100)) - continue; - - SmallVector<uint32_t, 2> Weights; - if (PredBr->getSuccessor(0) == PredOutEdge.second) { - Weights.push_back(BP.getNumerator()); - Weights.push_back(BP.getCompl().getNumerator()); - } else { - Weights.push_back(BP.getCompl().getNumerator()); - Weights.push_back(BP.getNumerator()); - } - PredBr->setMetadata(LLVMContext::MD_prof, - MDBuilder(PredBr->getParent()->getContext()) - .createBranchWeights(Weights)); - } -} - -/// runOnFunction - Toplevel algorithm. +/// runOnFunction - Top level algorithm. /// bool JumpThreading::runOnFunction(Function &F) { if (skipFunction(F)) @@ -1097,11 +991,6 @@ bool JumpThreadingPass::ProcessBlock(BasicBlock *BB) { if (SimplifyPartiallyRedundantLoad(LI)) return true; - // Before threading, try to propagate profile data backwards: - if (PHINode *PN = dyn_cast<PHINode>(CondInst)) - if (PN->getParent() == BB && isa<BranchInst>(BB->getTerminator())) - updatePredecessorProfileMetadata(PN, BB); - // Handle a variety of cases where we are branching on something derived from // a PHI node in the current block. If we can prove that any predecessors // compute a predictable value based on a PHI node, thread those predecessors. |