[all-commits] [llvm/llvm-project] 77489c: [MLIR][Bufferization] Fix IdentityLayoutMap alloca...
Aaditya Agarwal via All-commits
all-commits at lists.llvm.org
Wed Sep 30 17:15:37 PDT 2026
Branch: refs/heads/main
Home: https://github.com/llvm/llvm-project
Commit: 77489c05e1c327e4acc7047fb7b3eebf114e02b0
https://github.com/llvm/llvm-project/commit/77489c05e1c327e4acc7047fb7b3eebf114e02b0
Author: Aaditya Agarwal <aadityaagarwal894 at gmail.com>
Date: 2026-10-01 (Thu, 01 Oct 2026)
Changed paths:
M mlir/lib/Dialect/Bufferization/IR/BufferizationOps.cpp
M mlir/lib/Dialect/Bufferization/Transforms/FuncBufferizableOpInterfaceImpl.cpp
M mlir/test/Dialect/Bufferization/Transforms/one-shot-module-bufferize.mlir
M mlir/test/Dialect/Bufferization/canonicalize.mlir
Log Message:
-----------
[MLIR][Bufferization] Fix IdentityLayoutMap allocation at function boundaries (#227253)
Resolves silent data corruption when passing subviews across function
boundaries under `LayoutMapOption::IdentityLayoutMap`.
### The Problem
When the `IdentityLayoutMap` option is specified for function boundary
bufferization, all function parameters are expected to have a fully
contiguous, zero-offset layout. However, if a caller passes a non-unit
stride or offset view (e.g. the result of `tensor.extract_slice`), the
bufferization pass incorrectly lowered this to a `memref.cast`.
Since `memref.cast` strips layout metadata but leaves the base pointer
unchanged, this caused silent wrong-value loads in the callee (reading
from offset 0 regardless of the actual dynamic offset).
### The Solution
This patch intercepts the operand materialization logic in
`FuncBufferizableOpInterfaceImpl.cpp` (specifically during `CallOp`
bufferization). It introduces an explicit layout compatibility check:
- If the source buffer type has a non-identity layout, **AND**
- The destination buffer type requires an identity layout (due to
`IdentityLayoutMap`),
The pass now forces a deep copy instead of a cast. It actively extracts
the dynamic extents from the destination shape, uses the user-defined
`BufferizationOptions::allocationFn` to materialize a fresh contiguous
buffer, and then invokes `BufferizationOptions::memCpyFn` to copy the
data safely.
### Testing
- Added a minimal reproducer to
`mlir/test/Dialect/Bufferization/Transforms/one-shot-module-bufferize.mlir`
that validates an allocation and copy are emitted rather than an illegal
`memref.cast`.
Fixes #83276
Co-authored-by: openhands <openhands at all-hands.dev>
To unsubscribe from these emails, change your notification settings at https://github.com/llvm/llvm-project/settings/notifications
More information about the All-commits
mailing list