[mlir][linalg] PadTensorOp vectorization: Avoid redundant FillOps

Do not generate FillOps when these would be entirely overwritten.

Differential Revision: https://reviews.llvm.org/D109741
This commit is contained in:
Matthias Springer 2021-09-15 08:57:55 +09:00
parent 88146230e1
commit 9adc0114bf
1 changed files with 7 additions and 0 deletions

View File

@ -751,6 +751,13 @@ struct GenericPadTensorOpVectorizationPattern
padOp.getLoc(), vecType, padOp.source(), readIndices, padValue,
readInBounds);
// If `dest` is a FillOp and the TransferWriteOp would overwrite the entire
// tensor, write directly to the FillOp's operand.
if (llvm::equal(vecShape, resultType.getShape())
&& llvm::all_of(writeInBounds, [](bool b) { return b; }))
if (auto fill = dest.getDefiningOp<FillOp>())
dest = fill.output();
// Generate TransferWriteOp.
auto writeIndices = ofrToIndexValues(
rewriter, padOp.getLoc(), padOp.getMixedLowPad());