[Mlir-commits] [mlir] emit inbounds and nuw attributes in memref. (PR #138984)

Peiyong Lin llvmlistbot at llvm.org
Thu May 15 14:40:44 PDT 2025


lpy wrote:

> > It is guaranteed that memref.load and memref.store must be inbounds: 0 <= idx < dim_size.
> 
> I don't quite follow this statement - is it really guaranteed? Looking at one of the tests that has been updated:
> 
> ```mlir
> func.func @static_store(%static : memref<10x42xf32>, %i : index, %j : index, %val : f32) {
>   memref.store %val, %static[%i, %j] : memref<10x42xf32>
>   return
> }
> ```
> 
> How can we be sure that `i` and `j` are in bounds? I appreciate that the docs ( [memref.store](https://mlir.llvm.org/docs/Dialects/MemRef/#memrefstore-memrefstoreop)) state that:
> 
> > The indices must be in-bounds: 0 <= idx < dim_size
> 
> but there's just nothing to enforce that, is there? It would be good to somehow document that this assumption is used when lowering to `llvm.getelemptr`.

Thanks for pointing this out. I checked a bit and if I understand correctly this is not enforced in the code. I can update the `memref.load` and `memref.store` doc to capture this information. @krzysz00 wdyt?
> 
> Also, why `nuw` instead of `nsuw`?

If I understand correctly `inbounds` already implies `nusw`.

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


More information about the Mlir-commits mailing list