[Mlir-commits] [mlir] [MLIR][Bufferization] Fix IdentityLayoutMap allocation at function boundaries (PR #227253)

Aaditya Agarwal llvmlistbot at llvm.org
Wed Sep 30 02:15:23 PDT 2026


aaditya8979 wrote:

@matthias-springer You're absolutely right — thank you for the architectural correction. After examining castOrReallocMemRefValue, I can confirm that isGuaranteedCastCompatible was the root cause. It correctly guards against dynamic→static offset/stride transitions, but it did not guard against non-identity→identity transitions where the source has a non-zero or dynamic offset. In that case, areCastCompatible would return true (the element type and rank match), isGuaranteedCastCompatible would also return true (no dynamic-to-static change), and a memref.cast would be emitted — silently stripping the offset metadata.

I've reworked the fix: the workaround from FuncBufferizableOpInterfaceImpl.cpp has been removed, and isGuaranteedCastCompatible now includes an additional check: if the source has a non-identity layout and the destination requires identity layout, it returns false, causing the function to fall through to the existing alloc + copy path. This correctly covers both the func.call boundary case and the to_buffer(to_tensor(x)) folding path.

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


More information about the Mlir-commits mailing list