[Mlir-commits] [mlir] [mlir][Linalg] Preserve init in tiled in-place update patterns (PR #195912)

Matthias Springer llvmlistbot at llvm.org
Wed May 6 02:34:06 PDT 2026


================
@@ -92,6 +92,22 @@ struct MoveInitOperandsToInput : public OpRewritePattern<GenericOp> {
     for (OpOperand &op : outputOperands) {
       if (genericOp.getMatchingBlockArgument(&op).use_empty())
         continue;
+      // When DropUnitDims folds a unit reduction dim, the generic becomes
+      // all-parallel but the former accumulator remains in outs. Moving it
+      // to ins is correct in general, but NOT when the init participates in
+      // an extract_slice -> generic -> insert_slice chain which is the
+      // canonical in-place update pattern that one-shot bufferize relies on.
----------------
matthias-springer wrote:

I think there's a better way: if you care about bufferization and like to preserve the DPS chain, just don't run `MoveInitOperandsToInput`. extract/insert_slice is not the only problem. `MoveInitOperandsToInput` will always result in a new `tensor.empty` and thus a new allocation (unless you clean up the `tensor.empty` ops).


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


More information about the Mlir-commits mailing list