[llvm] [AArch64] Combine vector FNEG+FMA into `FNML[A|S]` (PR #167900)
Benjamin Maxwell via llvm-commits
llvm-commits at lists.llvm.org
Wed Nov 19 09:42:08 PST 2025
================
@@ -20444,6 +20446,47 @@ static SDValue performFADDCombine(SDNode *N,
return SDValue();
}
+static SDValue performFMACombine(SDNode *N,
+ TargetLowering::DAGCombinerInfo &DCI,
+ const AArch64Subtarget *Subtarget) {
+ SelectionDAG &DAG = DCI.DAG;
+ SDValue OpA = N->getOperand(0);
+ SDValue OpB = N->getOperand(1);
+ SDValue OpC = N->getOperand(2);
+ EVT VT = N->getValueType(0);
+ SDLoc DL(N);
+
+ // fma(a, b, neg(c)) -> fnmls(a, b, c)
+ // fma(neg(a), b, neg(c)) -> fnmla(a, b, c)
+ // fma(a, neg(b), neg(c)) -> fnmla(a, b, c)
+ if (!VT.isVector() || !DAG.getTargetLoweringInfo().isTypeLegal(VT) ||
+ !Subtarget->isSVEorStreamingSVEAvailable() ||
+ OpC.getOpcode() != ISD::FNEG) {
+ return SDValue();
+ }
+ unsigned int Opcode;
+ if (OpA.getOpcode() == ISD::FNEG) {
+ OpA = OpA.getOperand(0);
+ Opcode = AArch64ISD::FNMLA_PRED;
+ } else if (OpB.getOpcode() == ISD::FNEG) {
+ OpB = OpB.getOperand(0);
+ Opcode = AArch64ISD::FNMLA_PRED;
+ } else {
+ Opcode = AArch64ISD::FNMLS_PRED;
----------------
MacDue wrote:
Do we need these new ISD nodes? These ISEL patterns exist for scalable vectors (as shown by: https://godbolt.org/z/1Pn78GKox). So maybe you can promote the `FNEG` and `FMA` to scalable vectors, and rely on the existing patterns to lower them?
https://github.com/llvm/llvm-project/pull/167900
More information about the llvm-commits
mailing list