[Mlir-commits] [mlir] [[mlir][linalg] Infer reduction-neutral padding values in rewriteAsPaddedOp (PR #216517)

Andrzej WarzyƄski llvmlistbot at llvm.org
Wed Sep 9 02:05:02 PDT 2026


================
@@ -263,6 +266,101 @@ static Value padOperand(OpBuilder &builder, TilingInterface opToPad,
                                paddingValue, /*nofold=*/false, dynDims);
 }
 
+/// Returns true if `mul` and `add` are a pair for which `0 * x = 0` and
+/// `0 + x = x`. Zero is then a valid padding value for the operands of a
+/// contraction with such a body: `mul` turns a padded zero into a zero, and
+/// adding that zero leaves the accumulated value unchanged.
+///
+/// Do not grow this list just to match `isaContractionOpInterface`, since not
+/// every contraction can be zero-padded: a `max`/`+` body needs `-inf`.
----------------
banach-space wrote:

This comment is quite convoluted - it's not clear to me what it says. Isn't this simply checking that `mul` and `add` are indeed a multiplication and an addition? 

How about:
```cpp
/// Returns true if `first` and `second` form a compatible multiply-add pair.
///
/// This can be used in hooks such as `isContractionBody` to check whether the
/// body of a contraction is matmul-like (i.e. mul -> add).
static bool isCompatibleMulAndAdd(Operation *first, Operation *second) {
```

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


More information about the Mlir-commits mailing list