[Mlir-commits] [mlir] [mlir][Transform] Reuse bbArgs in FuseIntoContainingOp (PR #135066)
Pablo Antonio Martinez
llvmlistbot at llvm.org
Thu Apr 24 01:40:57 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 :
+ cast<DestinationStyleOpInterface>(clone).getDpsInitsMutable()) {
+ Value producerOperand =
+ clone->getOperand(initOperandPtr.getOperandNumber());
+ for (auto containerIterArg : containerLoop.getRegionIterArgs()) {
+ OpOperand *bbArg = containerLoop.getTiedLoopInit(containerIterArg);
----------------
pabloantoniom wrote:
Same as above, not sure how this could be null?
https://github.com/llvm/llvm-project/pull/135066
More information about the Mlir-commits
mailing list