[Mlir-commits] [mlir] e5dc99e - [mlir][tensor][bufferize] Improve bufferization of DimOp/RankOp
Matthias Springer
llvmlistbot at llvm.org
Wed Dec 14 03:49:38 PST 2022
Author: Matthias Springer
Date: 2022-12-14T12:47:46+01:00
New Revision: e5dc99e642d05b1075b6c5480a5b3f0485a25038
URL: https://github.com/llvm/llvm-project/commit/e5dc99e642d05b1075b6c5480a5b3f0485a25038
DIFF: https://github.com/llvm/llvm-project/commit/e5dc99e642d05b1075b6c5480a5b3f0485a25038.diff
LOG: [mlir][tensor][bufferize] Improve bufferization of DimOp/RankOp
The tensor operands do not bufferize to a memory read.
Differential Revision: https://reviews.llvm.org/D140007
Added:
Modified:
mlir/lib/Dialect/Tensor/Transforms/BufferizableOpInterfaceImpl.cpp
mlir/test/Dialect/Tensor/one-shot-bufferize.mlir
Removed:
################################################################################
diff --git a/mlir/lib/Dialect/Tensor/Transforms/BufferizableOpInterfaceImpl.cpp b/mlir/lib/Dialect/Tensor/Transforms/BufferizableOpInterfaceImpl.cpp
index aa5a1d8716f72..3c634e9b0f9ce 100644
--- a/mlir/lib/Dialect/Tensor/Transforms/BufferizableOpInterfaceImpl.cpp
+++ b/mlir/lib/Dialect/Tensor/Transforms/BufferizableOpInterfaceImpl.cpp
@@ -205,7 +205,8 @@ struct DimOpInterface
tensor::DimOp> {
bool bufferizesToMemoryRead(Operation *op, OpOperand &opOperand,
const AnalysisState &state) const {
- return true;
+ // The op reads the tensor's metadata but not its contents.
+ return false;
}
bool bufferizesToMemoryWrite(Operation *op, OpOperand &opOperand,
@@ -927,7 +928,8 @@ struct RankOpInterface
tensor::RankOp> {
bool bufferizesToMemoryRead(Operation *op, OpOperand &opOperand,
const AnalysisState &state) const {
- return true;
+ // The op reads the tensor's metadata but not its contents.
+ return false;
}
bool bufferizesToMemoryWrite(Operation *op, OpOperand &opOperand,
diff --git a/mlir/test/Dialect/Tensor/one-shot-bufferize.mlir b/mlir/test/Dialect/Tensor/one-shot-bufferize.mlir
index e1473c844dfe8..59fde562bd876 100644
--- a/mlir/test/Dialect/Tensor/one-shot-bufferize.mlir
+++ b/mlir/test/Dialect/Tensor/one-shot-bufferize.mlir
@@ -330,3 +330,20 @@ func.func @insert_slice_full_overwrite(%t: tensor<10xf32>, %b: tensor<10xf32>) -
%2 = tensor.insert_slice %b into %t[0][10][1] : tensor<10xf32> into tensor<10xf32>
return %2 : tensor<10xf32>
}
+
+// -----
+
+// CHECK-LABEL: func @dim_not_reading(
+// CHECK-SAME: %[[t:.*]]: memref<?xf32
+func.func @dim_not_reading(%t: tensor<?xf32>, %f: f32, %pos: index)
+ -> (tensor<?xf32>, index)
+{
+ %c0 = arith.constant 0 : index
+ // CHECK-NOT: memref.alloc
+ // CHECK-NOT: memref.copy
+ // CHECK: memref.store %{{.*}}, %[[t]]
+ %0 = tensor.insert %f into %t[%pos] : tensor<?xf32>
+ // CHECK: memref.dim %[[t]]
+ %1 = tensor.dim %t, %c0 : tensor<?xf32>
+ return %0, %1 : tensor<?xf32>, index
+}
More information about the Mlir-commits
mailing list