[Mlir-commits] [mlir] eaa4b6c - [mlir][bufferization] Clone simplify fails when input and result type not cast compatiable (#71310)
llvmlistbot at llvm.org
llvmlistbot at llvm.org
Fri Jan 12 07:11:04 PST 2024
Author: donald chen
Date: 2024-01-12T16:11:00+01:00
New Revision: eaa4b6cf2914435c7549d5caa09b5f2d87082ed0
URL: https://github.com/llvm/llvm-project/commit/eaa4b6cf2914435c7549d5caa09b5f2d87082ed0
DIFF: https://github.com/llvm/llvm-project/commit/eaa4b6cf2914435c7549d5caa09b5f2d87082ed0.diff
LOG: [mlir][bufferization] Clone simplify fails when input and result type not cast compatiable (#71310)
The simplify of bufferization.clone generates a memref.cast op, but the
checks in simplify do not verify whether the operand types and return
types of clone op is compatiable, leading to errors. This patch
addresses this issue.
Added:
Modified:
mlir/lib/Dialect/Bufferization/IR/BufferizationOps.cpp
mlir/test/Dialect/Bufferization/canonicalize.mlir
Removed:
################################################################################
diff --git a/mlir/lib/Dialect/Bufferization/IR/BufferizationOps.cpp b/mlir/lib/Dialect/Bufferization/IR/BufferizationOps.cpp
index ca0d2f407c2d83..94bc2bcea63be9 100644
--- a/mlir/lib/Dialect/Bufferization/IR/BufferizationOps.cpp
+++ b/mlir/lib/Dialect/Bufferization/IR/BufferizationOps.cpp
@@ -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;
diff --git a/mlir/test/Dialect/Bufferization/canonicalize.mlir b/mlir/test/Dialect/Bufferization/canonicalize.mlir
index 3ba283928a83f0..3edae7827f25f7 100644
--- a/mlir/test/Dialect/Bufferization/canonicalize.mlir
+++ b/mlir/test/Dialect/Bufferization/canonicalize.mlir
@@ -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>
More information about the Mlir-commits
mailing list