From: Yevgeny Rouban Date: Fri, 12 Jun 2020 04:55:15 +0000 (+0700) Subject: [JumpThreading] Handle zero !prof branch_weights X-Git-Tag: llvmorg-12-init~3298 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=707836ed4edb21e7133007f0200c3fd3a04d3409;p=platform%2Fupstream%2Fllvm.git [JumpThreading] Handle zero !prof branch_weights Avoid division by zero in updatePredecessorProfileMetadata(). Reviewers: yamauchi Tags: #llvm Differential Revision: https://reviews.llvm.org/D81499 --- diff --git a/llvm/lib/Transforms/Scalar/JumpThreading.cpp b/llvm/lib/Transforms/Scalar/JumpThreading.cpp index d2d71dd..9d05004 100644 --- a/llvm/lib/Transforms/Scalar/JumpThreading.cpp +++ b/llvm/lib/Transforms/Scalar/JumpThreading.cpp @@ -214,11 +214,16 @@ static void updatePredecessorProfileMetadata(PHINode *PN, BasicBlock *BB) { if (!CondBr) return; - BranchProbability BP; uint64_t TrueWeight, FalseWeight; if (!CondBr->extractProfMetadata(TrueWeight, FalseWeight)) return; + if (TrueWeight + FalseWeight == 0) + // Zero branch_weights do not give a hint for getting branch probabilities. + // Technically it would result in division by zero denominator, which is + // TrueWeight + FalseWeight. + return; + // Returns the outgoing edge of the dominating predecessor block // that leads to the PhiNode's incoming block: auto GetPredOutEdge = @@ -253,10 +258,11 @@ static void updatePredecessorProfileMetadata(PHINode *PN, BasicBlock *BB) { if (!CI || !CI->getType()->isIntegerTy(1)) continue; - BP = (CI->isOne() ? BranchProbability::getBranchProbability( - TrueWeight, TrueWeight + FalseWeight) - : BranchProbability::getBranchProbability( - FalseWeight, TrueWeight + FalseWeight)); + BranchProbability BP = + (CI->isOne() ? BranchProbability::getBranchProbability( + TrueWeight, TrueWeight + FalseWeight) + : BranchProbability::getBranchProbability( + FalseWeight, TrueWeight + FalseWeight)); auto PredOutEdge = GetPredOutEdge(PN->getIncomingBlock(i), BB); if (!PredOutEdge.first)