[Mlir-commits] [mlir] [mlir][Transform] Reuse bbArgs in FuseIntoContainingOp (PR #135066)
Oleksandr Alex Zinenko
llvmlistbot at llvm.org
Wed Apr 16 08:06:36 PDT 2025
================
@@ -755,6 +791,39 @@ tileAndFuseFirstExtractUse(RewriterBase &rewriter, Diagnostic &diag,
OpBuilder::InsertionGuard guard(rewriter);
rewriter.setInsertionPoint(sliceOpToTile);
+ // Clone the producer inside the consumer and try to update the producer init
+ // operands using the loop bbArgs if applicable. More precisely, if the bbArg
+ // of the container loop points to a value that it is used by the consumer op,
+ // then, instead of using such value on the consumer, use the value coming
+ // from the bbArg instead. This allows to reuse the output tensor (instead of
+ // creating a new one) of the container when both producer and container write
+ // to the same output.
+ if (LoopLikeOpInterface containerLoop =
+ dyn_cast<LoopLikeOpInterface>(sliceOpToTile->getParentOp())) {
+ Operation *clone = rewriter.clone(*producerOp);
+ rewriter.modifyOpInPlace(clone, [&]() {
+ // Iterate over the outputs of the producer and over the loop bbArgs and
+ // check if any bbArg points to the same value as the producer output. In
+ // such case, make the producer output point to the bbArg directly.
+ for (auto &initOperandPtr :
----------------
ftynse wrote:
https://llvm.org/docs/CodingStandards.html#use-auto-type-deduction-to-make-code-more-readable
It's unclear what is the type of `initOperandPtr` here and whether it has to be a reference. Same below.
https://github.com/llvm/llvm-project/pull/135066
More information about the Mlir-commits
mailing list