From 2d382f246b34e9ca6228cf4aedd314570e1f1246 Mon Sep 17 00:00:00 2001 From: Cong Hou Date: Mon, 26 Oct 2015 18:00:17 +0000 Subject: [PATCH] Check the case that the numerator and denominator are both zeros when getting edge probabilities in BPI and return 100% in this case. This issue is triggered in PGO mode when bootstrapping LLVM. It seems that it is not guaranteed that edge weights are always greater than zero which are read from profile data. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@251317 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Analysis/BranchProbabilityInfo.cpp | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/lib/Analysis/BranchProbabilityInfo.cpp b/lib/Analysis/BranchProbabilityInfo.cpp index 9ab357b62cf..f4839469869 100644 --- a/lib/Analysis/BranchProbabilityInfo.cpp +++ b/lib/Analysis/BranchProbabilityInfo.cpp @@ -623,6 +623,11 @@ getEdgeProbability(const BasicBlock *Src, unsigned IndexInSuccessors) const { uint32_t N = getEdgeWeight(Src, IndexInSuccessors); uint32_t D = getSumForBlock(Src); + // It is possible that the edge weight on the only successor edge of Src is + // zero, in which case we return 100%. + if (N == 0 && D == 0) + return BranchProbability::getOne(); + return BranchProbability(N, D); } @@ -634,6 +639,11 @@ getEdgeProbability(const BasicBlock *Src, const BasicBlock *Dst) const { uint32_t N = getEdgeWeight(Src, Dst); uint32_t D = getSumForBlock(Src); + // It is possible that the edge weight on the only successor edge of Src is + // zero, in which case we return 100%. + if (N == 0 && D == 0) + return BranchProbability::getOne(); + return BranchProbability(N, D); }