[llvm] r251317 - Check the case that the numerator and denominator are both zeros when getting edge probabilities in BPI and return 100% in this case.

Cong Hou via llvm-commits llvm-commits at lists.llvm.org
Mon Oct 26 11:00:17 PDT 2015


Author: conghou
Date: Mon Oct 26 13:00:17 2015
New Revision: 251317

URL: http://llvm.org/viewvc/llvm-project?rev=251317&view=rev
Log:
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.


Modified:
    llvm/trunk/lib/Analysis/BranchProbabilityInfo.cpp

Modified: llvm/trunk/lib/Analysis/BranchProbabilityInfo.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Analysis/BranchProbabilityInfo.cpp?rev=251317&r1=251316&r2=251317&view=diff
==============================================================================
--- llvm/trunk/lib/Analysis/BranchProbabilityInfo.cpp (original)
+++ llvm/trunk/lib/Analysis/BranchProbabilityInfo.cpp Mon Oct 26 13:00:17 2015
@@ -623,6 +623,11 @@ getEdgeProbability(const BasicBlock *Src
   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
   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);
 }
 




More information about the llvm-commits mailing list