[llvm] [SCEVDivision] Prevent propagation of incorrect no-wrap flags (PR #154745)
Ryotaro Kasuga via llvm-commits
llvm-commits at lists.llvm.org
Fri Aug 22 04:10:15 PDT 2025
kasuga-fj wrote:
@nikic Thanks for the comments!
> The only user of SCEVDivision is Delinearization -- maybe it has some additional checks or assumptions that make it safe? But I suspect that it's broken.
Yes, the only user of SCEVDivision is Delinearization, and the primary user of Delinearization is DA, which doesn't pay attention to nuw/nsw flags (and therefore I'm really struggling now...). So, it's just my personal impression, but I don't think there are such additional checks or assumptions, and I agree that it's likely broken. Even if Delinearization has such checks, considering that SCEVDivision is exposed and it could potentially be used in other passes, it's concerning that the required preconditions are not clearly specified.
> From a quick test, requiring mul nsw in SCEVDivision breaks lots of tests. But it also looks like many places in Delinearization fail to preserve nowrap flags on multiplies, so maybe some of this can be recovered?
I was able to reproduce the test failures. I tried preserving the flags for the `getMulExpr`s in Delinearization for now, but it didn't affect the test results. Seems like I need to investigate further.
In conclusion, I think it would be better to implement something like `PrintSCEVDivision` and add dedicated tests for SCEVDivision itself, rather than relying solely on Delinearization tests. At the very least, I believe it won’t make things worse. So let me mark this PR as a draft for now. (totally unrelated, but I just realized that Alive2 is an absolutely amazing tool.)
https://github.com/llvm/llvm-project/pull/154745
More information about the llvm-commits
mailing list