[llvm] [DAGCombiner] Add DAG combine for PARTIAL_REDUCE_MLA when no mul op (PR #131326)

Nicholas Guy via llvm-commits llvm-commits at lists.llvm.org
Fri May 2 05:04:08 PDT 2025


================
@@ -12669,6 +12679,48 @@ SDValue DAGCombiner::visitPARTIAL_REDUCE_MLA(SDNode *N) {
                      RHSExtOp);
 }
 
+// Makes PARTIAL_REDUCE_*MLA(Acc, ZEXT(UnextOp1), Splat(1)) into
+// PARTIAL_REDUCE_UMLA(Acc, Op, TRUNC(Splat(1)))
+// Makes PARTIAL_REDUCE_*MLA(Acc, SEXT(UnextOp1), Splat(1)) into
+// PARTIAL_REDUCE_SMLA(Acc, Op, TRUNC(Splat(1)))
+SDValue DAGCombiner::foldPartialReduceMLANoMulOp(SDNode *N) {
+  SDLoc DL(N);
+  SDValue Acc = N->getOperand(0);
+  SDValue Op1 = N->getOperand(1);
+  SDValue Op2 = N->getOperand(2);
+
+  APInt ConstantOne;
+  if (!ISD::isConstantSplatVector(Op2.getNode(), ConstantOne) ||
+      !ConstantOne.isOne())
+    return SDValue();
----------------
NickGuy-Arm wrote:

I've looked into this and, as far as I can tell, we can't do this. I guess more specifically there is no value in it, as the only cases where this code path is executed, `Op2` is always a constant `1`.
Trying to manipulate this from IR by making the mul operand also have a constant operand will prevent said mul from being folded into the mla altogether, as it no longer has two extend operands.
The only way I can see to achieve this is to loosen the requirement of both operands of a mul needing to be extended, but that then risks discarding other semantics (such as the no-wrap flags, as you've pointed out offline).

If we do want to loosen the requirements, then I think that would be better suited in a distinct PR. But within the context of this PR, I would say this is not something we can do.

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


More information about the llvm-commits mailing list