[llvm] [SCEVDivision] Prevent propagation of incorrect no-wrap flags (PR #154745)
Nikita Popov via llvm-commits
llvm-commits at lists.llvm.org
Thu Aug 21 07:04:54 PDT 2025
nikic wrote:
> > For the nowrap flags, I think you can justify preserving `nuw` because division should make everything strictly smaller in an unsigned sense. So if it did not wrap with larger values, it should not wrap with smaller ones. The caveat here is that this is not correct for division by zero. We can't preserve flags for a possible division by zero.
>
> (I'm probably wrong about this, but) Even in unsigned division, what happens `{0,+,(%m * %n)}<nuw><%loop>` dividing by `%m` and `(%m * %n)` is wrapping? Or does SCEV guarantee that `%m * %n` does't wrap?
SCEV does not guarantee that `%m * %n` does not wrap. I think the current code is incorrect in reporting that the result of dividing `%m * %n` by `%n` is `q = %m, r = 0`. This is only valid if we have appropriate nowrap flags.
https://github.com/llvm/llvm-project/pull/154745
More information about the llvm-commits
mailing list