[Mlir-commits] [mlir] bb566b6 - [mlir][linalg] Do not emit FillOp for tensor.pad with zero padding
Matthias Springer
llvmlistbot at llvm.org
Tue Jul 4 23:45:07 PDT 2023
Author: Matthias Springer
Date: 2023-07-05T08:34:46+02:00
New Revision: bb566b652f7da5a96dbc694686bfea9ee54806b3
URL: https://github.com/llvm/llvm-project/commit/bb566b652f7da5a96dbc694686bfea9ee54806b3
DIFF: https://github.com/llvm/llvm-project/commit/bb566b652f7da5a96dbc694686bfea9ee54806b3.diff
LOG: [mlir][linalg] Do not emit FillOp for tensor.pad with zero padding
No need to fill the buffer if no padding is added. I.e., the tensor.pad is packing only.
Differential Revision: https://reviews.llvm.org/D153874
Added:
Modified:
mlir/lib/Dialect/Linalg/Transforms/ConvertToDestinationStyle.cpp
mlir/test/Dialect/Linalg/pad-to-specific-memory-space.mlir
Removed:
################################################################################
diff --git a/mlir/lib/Dialect/Linalg/Transforms/ConvertToDestinationStyle.cpp b/mlir/lib/Dialect/Linalg/Transforms/ConvertToDestinationStyle.cpp
index ea236a94fa81dd..e5f7f6128c17bc 100644
--- a/mlir/lib/Dialect/Linalg/Transforms/ConvertToDestinationStyle.cpp
+++ b/mlir/lib/Dialect/Linalg/Transforms/ConvertToDestinationStyle.cpp
@@ -181,9 +181,12 @@ Value linalg::bufferizeToAllocation(RewriterBase &rewriter, PadOp padOp,
createAllocationForTensor(rewriter, loc, padOp.getResult(), memorySpace);
rewriter.setInsertionPoint(padOp);
- // Create linalg.fill or linalg.generic.
- Operation *fillOp = movePaddingToFillOrGenericOp(rewriter, loc, padOp, alloc);
- rewriter.setInsertionPointAfter(fillOp);
+ if (!padOp.hasZeroLowPad() || !padOp.hasZeroHighPad()) {
+ // Create linalg.fill or linalg.generic. Not needed if there is no padding.
+ Operation *fillOp =
+ movePaddingToFillOrGenericOp(rewriter, loc, padOp, alloc);
+ rewriter.setInsertionPointAfter(fillOp);
+ }
// Create memref.tensor_store.
SmallVector<OpFoldResult> sizes =
diff --git a/mlir/test/Dialect/Linalg/pad-to-specific-memory-space.mlir b/mlir/test/Dialect/Linalg/pad-to-specific-memory-space.mlir
index a7c09a9f17e3c6..55b0ff5016d177 100644
--- a/mlir/test/Dialect/Linalg/pad-to-specific-memory-space.mlir
+++ b/mlir/test/Dialect/Linalg/pad-to-specific-memory-space.mlir
@@ -32,7 +32,7 @@ func.func @pad_to_memory_space(%arg0: tensor<24x12xf32>,
// CHECK: memref.copy %[[s1]], %[[alloc1_view]]
// CHECK: %[[alloc2:.*]] = memref.alloc() : memref<4x5xf32, 3>
- // CHECK: linalg.fill {{.*}} outs(%[[alloc2]]
+ // CHECK-NOT: linalg.fill {{.*}} outs(%[[alloc2]]
// No subview because there is 0 padding
// CHECK: memref.copy %[[s2]], %[[alloc2]]
More information about the Mlir-commits
mailing list