Check the case that the numerator and denominator are both zeros when getting edge...
[oota-llvm.git] / lib / Analysis / BranchProbabilityInfo.cpp
index 9ab357b62cffeaffa142aec5d02e0dcfc04f9072..f483946986992c212a2e5ab58c48232a00f248ad 100644 (file)
@@ -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);
 }