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

Ryotaro Kasuga via llvm-commits llvm-commits at lists.llvm.org
Wed Aug 27 05:02:27 PDT 2025


kasuga-fj wrote:

@sushgokh 

> 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?

Sorry, I didn't catch what you meant. As far as I can tell, LLVM IR uses two's complement representation for integers. `UINT64_MAX` is `2^64 - 1` when interpreted as unsigned, and `-1` when interpreted as signed. Also, I don't know whether the array access like `a[UINT64_MAX]` is well-defined in the C language.

> * 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?

The IR I presented was handwritten. I don't know whether the actual compiler infers those flags.
 
> * Didnt debug this, but any idea why did it delinearize to 2 dimensions?

Please refer to the [delinearization function](https://github.com/llvm/llvm-project/blob/7b3e77f8d94c9abda1675c62f70caf12e3d7d5ce/llvm/lib/Analysis/DependenceAnalysis.cpp#L3449). Just to clarify, this is a heuristic based on the input IR and does not reflect how the original program accesses the array.

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


More information about the llvm-commits mailing list