[Mlir-commits] [mlir] [[mlir][linalg] Infer reduction-neutral padding values in rewriteAsPaddedOp (PR #216517)
Jianhui Li
llvmlistbot at llvm.org
Fri Sep 11 08:55:19 PDT 2026
================
@@ -263,6 +266,142 @@ static Value padOperand(OpBuilder &builder, TilingInterface opToPad,
paddingValue, /*nofold=*/false, dynDims);
}
+/// Returns true if `operand` is indexed along at least one reduction dimension
+/// of `linalgOp`
+static bool isReducedOperand(linalg::LinalgOp linalgOp, OpOperand *operand,
+ ArrayRef<utils::IteratorType> iterTypes) {
+ AffineMap map = linalgOp.getMatchingIndexingMap(operand);
+ return llvm::any_of(llvm::enumerate(iterTypes), [&](auto it) {
+ return it.value() == utils::IteratorType::reduction &&
+ map.isFunctionOfDim(it.index());
+ });
+}
+
+/// Set `paddingValues` with the padding value of every input of `contractOp`
+/// that is indexed along a reduction dimension. Fails if the pair admits no
+/// padding value.
+static LogicalResult
+setContractionPaddingValues(OpBuilder &builder, linalg::LinalgOp contractOp,
+ Operation *mul, Operation *add,
+ ArrayRef<utils::IteratorType> iterTypes,
+ MutableArrayRef<Attribute> paddingValues) {
+ // Identify the padding value, `p`, for which `mul(p, x)` is the neutral
+ // element of `add` for every `x`.
+ // Not every contraction can be zero-padded: a body with `mul` = `addf` and
+ // `add` = `maximumf` (a max-plus contraction) pads with `-inf` instead.
----------------
Jianhui-Li wrote:
Good catch. I changed to elewise + reuduce.
https://github.com/llvm/llvm-project/pull/216517
More information about the Mlir-commits
mailing list