[Mlir-commits] [mlir] [mlir][memref] Canonicalize memref.reinterpret_cast when offset/sizes/strides are constants. (PR #163505)

Krzysztof Drewniak llvmlistbot at llvm.org
Mon Oct 20 10:25:24 PDT 2025


krzysz00 wrote:

> What about this IR?
```
%sz = ...  // could be negative
scf.if (%sz >= 0) {
  %0 = memref.reinterpret_cast %m to offset: [%off], sizes: [%sz], strides: [%str] : memref<f32> to memref<?xf32, strided<[?], offset: ?>>
  ...
}
```

That's valid, but not checkable at compile time.

> I think the issue here is that memref is probably not designed currently to support this Fortran use case.

Yeah, memref doesn't allow negative sizes and there's a decent amount of code that - for example - assumes that you can take the product of all `memref.dim`s and get a meaningful value at runtime.

What I'd use is some value like `fir.unknown.size` which isn't `-1` but lowers to it when you're rewriting out of memref.

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


More information about the Mlir-commits mailing list