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

Ryotaro Kasuga via llvm-commits llvm-commits at lists.llvm.org
Tue Aug 26 03:54:38 PDT 2025


kasuga-fj wrote:

> Firstly, this entire program is UB since d+1 wraps around. So, I am not much concerned about this specific example.

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` doesn't have `nuw` (see [LangRef](https://llvm.org/docs/LangRef.html#id93)).

> Secondly, the array dimensions should be A[d+1][d]. It has deduced the delinearized dimensions as
> `ArrayRef[{0,+,1}<nuw><nsw><%loop>][{0,+,1}<nuw><nsw><%loop>]`

The deduced dimensions are `ArrayDecl`. The `ArrayRef` shows inferred subscripts.

> 3\. GEP doesnt have any wrap flags. I dont know how nuw/nsw was derived on `AccessFunction: {0,+,(1 + %d)}<nuw><nsw><%loop>`. But basically this says that even gep access value may wrap

The `inbounds` implies `nusw` (again, see [LangRef](https://llvm.org/docs/LangRef.html#id239)). 

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


More information about the llvm-commits mailing list