Skip to content

[mlir][bufferization] Fix SimplifyClones with dealloc before cloneOp #79098

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jan 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions mlir/lib/Dialect/Bufferization/IR/BufferizationOps.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -505,6 +505,9 @@ struct SimplifyClones : public OpRewritePattern<CloneOp> {
// of the source.
for (Operation *pos = cloneOp->getNextNode(); pos != redundantDealloc;
pos = pos->getNextNode()) {
// Bail if we run out of operations while looking for a deallocation op.
if (!pos)
return failure();
auto effectInterface = dyn_cast<MemoryEffectOpInterface>(pos);
if (!effectInterface)
continue;
Expand Down
12 changes: 12 additions & 0 deletions mlir/test/Dialect/Bufferization/canonicalize.mlir
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,18 @@ func.func @clone_and_realloc(%arg0: memref<?xf32>) {

// -----

// Verify SimplifyClones skips clones with preceding deallocation.
// CHECK-LABEL: @clone_and_preceding_dealloc
func.func @clone_and_preceding_dealloc(%arg0: memref<?xf32>) -> memref<32xf32> {
memref.dealloc %arg0 : memref<?xf32>
%0 = bufferization.clone %arg0 : memref<?xf32> to memref<32xf32>
return %0 : memref<32xf32>
}
// CHECK-SAME: %[[ARG:.*]]: memref<?xf32>
// CHECK-NOT: %cast = memref.cast %[[ARG]]

// -----

// CHECK-LABEL: func @tensor_cast_to_memref
// CHECK-SAME: %[[ARG0:.+]]: tensor<4x6x16x32xi8>
func.func @tensor_cast_to_memref(%arg0 : tensor<4x6x16x32xi8>) ->
Expand Down