[Mlir-commits] [mlir] [mlir][Linalg]: Optimize linalg generic in transform::PromoteOp to avoid unnecessary copies (PR #68555)

Aviad Cohen llvmlistbot at llvm.org
Wed Oct 11 00:47:02 PDT 2023


================
@@ -174,6 +177,11 @@ LinalgOpInstancePromotionOptions::LinalgOpInstancePromotionOptions(
     Operation *op = opOperand.get().getDefiningOp();
     if (auto sv = dyn_cast_or_null<memref::SubViewOp>(op)) {
       subViews[operandNumber] = sv;
+      // In case of linalg generic, copy in only if subview is used in linalg
+      // payload.
+      if (!isa<linalg::GenericOp>(linalgOp) ||
----------------
AviadCo wrote:

@chelini In case of `linalg.generic`, it is easy to know if an input/output operand are being used by checking if the operand is being used in the payload before except writing to it (which is what I check `payloadUsesValueFromOperand`).
If case of any `LinalgOp`, I am not sure it is triavial since some operations doesn't have a payload (i.e. linalg.copy).

One think we can do it to add an interface for each LinalgOp to implement and check if output operand (init) might be used before assignment.

https://github.com/llvm/llvm-project/pull/68555


More information about the Mlir-commits mailing list