[PATCH] D101722: [SCEV] Don't require ControlsExit for gt/lt NoWrap

Nikita Popov via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Jun 9 10:11:35 PDT 2021


nikic added a comment.

In D101722#2806912 <https://reviews.llvm.org/D101722#2806912>, @efriedma wrote:

> If I'm understanding correctly, the issue you're describing is that if %len is ULONG_MAX in the following loop, on trunk LLVM, the backedge-taken count comes out to zero.

Yes, exactly.

> This is because of the math in ScalarEvolution::computeBECount: we try to compute `ceil(a/b)` by converting it to `floor((a + b - 1) / b)`, which doesn't work.  There are different ways we could address this.  For example, we could change around the computation: we can compute `ceil(a/b)` by instead expanding it to `floor(a/b) + umin(a % b, 1)`.

Right. However, I'd expect alternative encodings to be a pessimization in practice. We only really get in this situation if `a` is non-constant, so this won't be folding away.

> I guess in the meantime, we should add the missing loopHasNoAbnormalExits() check.

Yeah, we should.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D101722/new/

https://reviews.llvm.org/D101722



More information about the llvm-commits mailing list