[Mlir-commits] [mlir] [mlir][MemRefToLLVM] fix incorrect `nuw` on `GEP/mul` when lowering `memref.load/store` with negative strides (PR #204309)

Tobias Gysi llvmlistbot at llvm.org
Thu Jun 18 06:22:01 PDT 2026


================
@@ -38,8 +38,20 @@ namespace mlir {
 
 using namespace mlir;
 
-static constexpr LLVM::GEPNoWrapFlags kNoWrapFlags =
-    LLVM::GEPNoWrapFlags::inbounds | LLVM::GEPNoWrapFlags::nuw;
+// Returns GEP no-wrap flags for a memref load/store.
+// inbounds is always valid when indices are in-bounds per the memref spec.
+// nuw requires every index*stride term to not unsigned-wrap, which holds iff
+// all strides are statically non-negative. Negative strides would make the
+// intermediate mul nuw overflow (e.g., idx * (-1 as u64) wraps for idx > 0).
----------------
gysit wrote:

```suggestion
/// Returns GEP no-wrap flags for a memref load/store.
/// inbounds is always valid when indices are in-bounds per the memref spec.
/// nuw requires every index*stride term to not unsigned-wrap, which holds iff
/// all strides are statically non-negative. Negative strides would make the
/// intermediate mul nuw overflow (e.g., idx * (-1 as u64) wraps for idx > 0).
```
ultra nit:

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


More information about the Mlir-commits mailing list