Skip to content

[mlir][bufferization] Clone simplify fails when input and result type not cast compatiable #71310

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 1 commit into from
Jan 12, 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
5 changes: 5 additions & 0 deletions mlir/lib/Dialect/Bufferization/IR/BufferizationOps.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -457,6 +457,11 @@ struct SimplifyClones : public OpRewritePattern<CloneOp> {
}

Value source = cloneOp.getInput();
if (source.getType() != cloneOp.getType() &&
!memref::CastOp::areCastCompatible({source.getType()},
{cloneOp.getType()}))
return failure();

// Aims to find the dealloc op for the canonical source
// which otherwise could prevent removal of unnecessary allocs.
Value canonicalSource = source;
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 @@ -156,6 +156,18 @@ func.func @clone_and_cast(%arg0: memref<?xf32>) -> memref<32xf32> {

// -----

// CHECK-LABEL: @clone_incompatible
func.func @clone_incompatible(%arg0: memref<32xf32, strided<[2]>>) -> memref<32xf32> {
%0 = bufferization.clone %arg0 : memref<32xf32, strided<[2]>> to memref<32xf32>
memref.dealloc %arg0 : memref<32xf32, strided<[2]>>
return %0 : memref<32xf32>
}
// CHECK-SAME: %[[ARG:.*]]: memref<32xf32, strided<[2]>>
// CHECK-NEXT: bufferization.clone %[[ARG]] : memref<32xf32, strided<[2]>> to memref<32xf32>
// CHECK-NOT: memref.cast

// -----

// CHECK-LABEL: @alias_is_freed
func.func @alias_is_freed(%arg0 : memref<?xf32>) {
%0 = memref.cast %arg0 : memref<?xf32> to memref<32xf32>
Expand Down