[llvm] [AArch64] Combine vector FNEG+FMA into `FNML[A|S]` (PR #167900)
Benjamin Maxwell via llvm-commits
llvm-commits at lists.llvm.org
Thu Nov 13 09:03:19 PST 2025
================
@@ -20435,6 +20437,52 @@ static SDValue performFADDCombine(SDNode *N,
return SDValue();
}
+static SDValue performFMACombine(SDNode *N,
+ TargetLowering::DAGCombinerInfo &DCI,
+ const AArch64Subtarget *Subtarget) {
+ SelectionDAG &DAG = DCI.DAG;
+ SDValue Op1 = N->getOperand(0);
+ SDValue Op2 = N->getOperand(1);
+ SDValue Op3 = 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->hasSVE() || Subtarget->hasSME())) {
+ if (Op3.getOpcode() == ISD::FNEG) {
+ unsigned int Opcode;
+ if (Op1.getOpcode() == ISD::FNEG) {
+ Op1 = Op1.getOperand(0);
+ Opcode = AArch64ISD::FNMLA_PRED;
+ } else if (Op2.getOpcode() == ISD::FNEG) {
+ Op2 = Op2.getOperand(0);
+ Opcode = AArch64ISD::FNMLA_PRED;
+ } else {
+ Opcode = AArch64ISD::FNMLS_PRED;
+ }
+ Op3 = Op3.getOperand(0);
+ auto Pg = getPredicateForVector(DAG, DL, VT);
+ if (VT.isFixedLengthVector()) {
+ assert(DAG.getTargetLoweringInfo().isTypeLegal(VT) &&
+ "Expected only legal fixed-width types");
----------------
MacDue wrote:
nit: This is already checked in the main `if`, so we probably can remove the assert.
https://github.com/llvm/llvm-project/pull/167900
More information about the llvm-commits
mailing list