diff options
-rw-r--r-- | llvm/include/llvm/Support/BranchProbability.h | 10 |
1 files changed, 4 insertions, 6 deletions
diff --git a/llvm/include/llvm/Support/BranchProbability.h b/llvm/include/llvm/Support/BranchProbability.h index 71c0cf9afea..1ca94ca3196 100644 --- a/llvm/include/llvm/Support/BranchProbability.h +++ b/llvm/include/llvm/Support/BranchProbability.h @@ -92,16 +92,14 @@ public: uint64_t scaleByInverse(uint64_t Num) const; BranchProbability &operator+=(BranchProbability RHS) { - assert(N <= D - RHS.N && - "The sum of branch probabilities should not exceed one!"); - N += RHS.N; + // Saturate the result in case of overflow. + N = (uint64_t(N) + RHS.N > D) ? D : N + RHS.N; return *this; } BranchProbability &operator-=(BranchProbability RHS) { - assert(N >= RHS.N && - "Can only subtract a smaller probability from a larger one!"); - N -= RHS.N; + // Saturate the result in case of underflow. + N = N < RHS.N ? 0 : N - RHS.N; return *this; } |