aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatthias Springer <me@m-sp.org>2023-07-05 08:34:03 +0200
committerMatthias Springer <me@m-sp.org>2023-07-05 08:34:46 +0200
commitbb566b652f7da5a96dbc694686bfea9ee54806b3 (patch)
tree8d8dc6714700b3b5e1b514cd29ba5c19641e5b80
parent2d74cf1f247068d93a8ef7f19a40b73c61132af0 (diff)
downloadllvm-bb566b652f7da5a96dbc694686bfea9ee54806b3.zip
llvm-bb566b652f7da5a96dbc694686bfea9ee54806b3.tar.gz
llvm-bb566b652f7da5a96dbc694686bfea9ee54806b3.tar.bz2
[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
-rw-r--r--mlir/lib/Dialect/Linalg/Transforms/ConvertToDestinationStyle.cpp9
-rw-r--r--mlir/test/Dialect/Linalg/pad-to-specific-memory-space.mlir2
2 files changed, 7 insertions, 4 deletions
diff --git a/mlir/lib/Dialect/Linalg/Transforms/ConvertToDestinationStyle.cpp b/mlir/lib/Dialect/Linalg/Transforms/ConvertToDestinationStyle.cpp
index ea236a9..e5f7f61 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 a7c09a9..55b0ff5 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]]