[Mlir-commits] [mlir] [mlir][linalg] Support subtracting accumulation in partial reduction … (PR #214033)

llvmlistbot at llvm.org llvmlistbot at llvm.org
Fri Aug 7 13:46:20 PDT 2026


================
@@ -534,6 +534,28 @@ static InitSliceInfo getInitSliceInfo(MLIRContext *context,
       partialReductionMap, initOperandShape);
 }
 
+/// Returns true if `combinerOp` accumulates into `accumulator` by subtracting
+/// the reduced value from it, i.e. it reduces the negated inputs.
+static bool isSubtractingAccumulation(Operation *combinerOp,
+                                      Value accumulator) {
+  if (!isa<arith::SubFOp, arith::SubIOp>(combinerOp))
+    return false;
+  return combinerOp->getOperand(0) == accumulator;
+}
+
+/// Creates the operation combining two partial results of the subtracting
+/// accumulation performed by `combinerOp`, preserving its fast-math flags and
+/// rounding mode. Integer overflow flags are dropped, since the flags of the
+/// subtraction do not carry over to the addition.
+static Value createSubtractingAccumulationMerge(OpBuilder &b, Location loc,
+                                                Operation *combinerOp,
+                                                Value lhs, Value rhs) {
+  if (auto subFOp = dyn_cast<arith::SubFOp>(combinerOp))
+    return arith::AddFOp::create(b, loc, lhs, rhs, subFOp.getFastmathAttr(),
+                                 subFOp.getRoundingmodeAttr());
+  return arith::AddIOp::create(b, loc, lhs, rhs);
----------------
pstarkcdpr wrote:

Yes. Addressed in 53ff75b70a12111d4a9e77cd1146666c9bf5cbb1.

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


More information about the Mlir-commits mailing list