diff --git a/mlir/lib/Dialect/Linalg/Transforms/ConvertToDestinationStyle.cpp b/mlir/lib/Dialect/Linalg/Transforms/ConvertToDestinationStyle.cpp --- a/mlir/lib/Dialect/Linalg/Transforms/ConvertToDestinationStyle.cpp +++ b/mlir/lib/Dialect/Linalg/Transforms/ConvertToDestinationStyle.cpp @@ -181,9 +181,12 @@ 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 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 --- 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 @@ // 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]]