[llvm] [LoopUnroll] Fix assert fail on zeroed branch weights (PR #165938)

Danila Malyutin via llvm-commits llvm-commits at lists.llvm.org
Tue Nov 4 11:57:22 PST 2025


danilaml wrote:

After this fix I still get division by zero error (signal, not assert) in `probOfNextInRemainder`. And it seems to be possible for `ProbNotTooMany ` to be zero judging by the comments:
```cpp
static BranchProbability
probOfNextInRemainder(BranchProbability OriginalLoopProb, unsigned N) {
  // Each of these variables holds the original loop's probability that the
  // number of iterations it will execute is some m in the specified range.
  BranchProbability ProbOne = OriginalLoopProb;                // 1 <= m
  BranchProbability ProbTooMany = ProbOne.pow(N + 1);          // N + 1 <= m
  BranchProbability ProbNotTooMany = ProbTooMany.getCompl();   // 0 <= m <= N
  BranchProbability ProbOneNotTooMany = ProbOne - ProbTooMany; // 1 <= m <= N
  return ProbOneNotTooMany / ProbNotTooMany;
}```

https://github.com/llvm/llvm-project/pull/165938


More information about the llvm-commits mailing list