[llvm] [DAGCombiner] Add DAG combine for PARTIAL_REDUCE_MLA when no mul op (PR #131326)
Sander de Smalen via llvm-commits
llvm-commits at lists.llvm.org
Thu Apr 24 01:55:06 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();
----------------
sdesmalen-arm wrote:
We can do this for all values that fit in the smaller type, not just the constant `1`. i.e. if we know that `zext(trunc(op2)) == op2` if op1 is zero-extended or `sext(trunc(op2)) == op2` if op1 is sign-extended, then we can do this transform. We could use `ComputeNumSignBits` to determine if we can truncate the sign bits.
https://github.com/llvm/llvm-project/pull/131326
More information about the llvm-commits
mailing list