[llvm] [DA] Check monotonicity for subscripts (PR #154527)

Sushant Gokhale via llvm-commits llvm-commits at lists.llvm.org
Tue Aug 26 05:48:38 PDT 2025


sushgokh wrote:

>I don't think that's correct. In the C language, wrapping behavior for unsigned integers is well-defined. In LLVM IR, unsigned wrapping is also permitted unless the add is marked as nuw (see [LangRef](https://llvm.org/docs/LangRef.html#id93)).

Ah, my bad about wrapping behavior for unsigned .

>The inbounds implies nusw

Does it always need to imply nsw ?   I am slightly skeptical. Consider [this](https://godbolt.org/z/4jeE3cavz). Its already accessing UINT64_MAX which is beyond signed representation. Or am I misinterpreting something here?

Anyway, coming back to the example, array dimensions can be expressed as A[d+1][d].
d+1 is nsw from `%stride = add nsw i64 %d, 1 `.
d is nuw from `%i.next = add nuw i64 %i, 1` I assume.
But GEP has nusw. And now  I understand why GEP and individual subscripts may have different wrap behavior.
Just for curiosity: 
1. How did it derive nusw on the `%offset.next = add nsw nuw i64 %offset, %stride`  and on GEP? Basically, compiler has some information about the values?
2. Didnt debug this, but any idea why did it delinearize to 2 dimensions?

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


More information about the llvm-commits mailing list