Skip to content

Commit 5650485

Browse files
[NFC][SVE] Refactor isel for floating multiply-add operations to use PatFrags.
Differential Revision: https://reviews.llvm.org/D143764
1 parent 72584d9 commit 5650485

File tree

2 files changed

+41
-59
lines changed

2 files changed

+41
-59
lines changed

llvm/lib/Target/AArch64/AArch64SVEInstrInfo.td

Lines changed: 27 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,8 @@ def SDT_AArch64Arith : SDTypeProfile<1, 3, [
171171

172172
def SDT_AArch64FMA : SDTypeProfile<1, 4, [
173173
SDTCisVec<0>, SDTCisVec<1>, SDTCisVec<2>, SDTCisVec<3>, SDTCisVec<4>,
174-
SDTCVecEltisVT<1,i1>, SDTCisSameAs<0,2>, SDTCisSameAs<2,3>, SDTCisSameAs<3,4>
174+
SDTCVecEltisVT<1,i1>, SDTCisSameNumEltsAs<0,1>,
175+
SDTCisSameAs<0,2>, SDTCisSameAs<0,3>, SDTCisSameAs<0,4>
175176
]>;
176177

177178
// Predicated operations with the result of inactive lanes being unspecified.
@@ -244,6 +245,11 @@ def AArch64revh_mt : SDNode<"AArch64ISD::REVH_MERGE_PASSTHRU", SDT_AArch64Arit
244245
def AArch64revw_mt : SDNode<"AArch64ISD::REVW_MERGE_PASSTHRU", SDT_AArch64Arith>;
245246
def AArch64revd_mt : SDNode<"AArch64ISD::REVD_MERGE_PASSTHRU", SDT_AArch64Arith>;
246247

248+
def AArch64fneg_mt_nsz : PatFrag<(ops node:$pred, node:$op, node:$pt),
249+
(AArch64fneg_mt node:$pred, node:$op, node:$pt), [{
250+
return N->getFlags().hasNoSignedZeros();
251+
}]>;
252+
247253
// These are like the above but we don't yet have need for ISD nodes. They allow
248254
// a single pattern to match intrinsic and ISD operand layouts.
249255
def AArch64cls_mt : PatFrags<(ops node:$pg, node:$op, node:$pt), [(int_aarch64_sve_cls node:$pt, node:$pg, node:$op)]>;
@@ -349,19 +355,25 @@ def AArch64fmul_p_oneuse : PatFrag<(ops node:$pred, node:$src1, node:$src2),
349355
def AArch64fabd_p : PatFrag<(ops node:$pg, node:$op1, node:$op2),
350356
(AArch64fabs_mt node:$pg, (AArch64fsub_p node:$pg, node:$op1, node:$op2), undef)>;
351357

352-
// FMAs with a negated multiplication operand can be commuted.
353-
def AArch64fmls_p : PatFrags<(ops node:$pred, node:$op1, node:$op2, node:$op3),
354-
[(AArch64fma_p node:$pred, (AArch64fneg_mt node:$pred, node:$op1, (undef)), node:$op2, node:$op3),
355-
(AArch64fma_p node:$pred, node:$op2, (AArch64fneg_mt node:$pred, node:$op1, (undef)), node:$op3)]>;
358+
def AArch64fmla_p : PatFrags<(ops node:$pg, node:$za, node:$zn, node:$zm),
359+
[(AArch64fma_p node:$pg, node:$zn, node:$zm, node:$za),
360+
(vselect node:$pg, (AArch64fma_p (AArch64ptrue 31), node:$zn, node:$zm, node:$za), node:$za)]>;
361+
362+
def AArch64fmls_p : PatFrags<(ops node:$pg, node:$za, node:$zn, node:$zm),
363+
[(AArch64fma_p node:$pg, (AArch64fneg_mt node:$pg, node:$zn, (undef)), node:$zm, node:$za),
364+
(AArch64fma_p node:$pg, node:$zm, (AArch64fneg_mt node:$pg, node:$zn, (undef)), node:$za),
365+
(vselect node:$pg, (AArch64fma_p (AArch64ptrue 31), (AArch64fneg_mt (AArch64ptrue 31), node:$zn, (undef)), node:$zm, node:$za), node:$za)]>;
366+
367+
def AArch64fnmla_p : PatFrags<(ops node:$pg, node:$za, node:$zn, node:$zm),
368+
[(AArch64fma_p node:$pg, (AArch64fneg_mt node:$pg, node:$zn, (undef)), node:$zm, (AArch64fneg_mt node:$pg, node:$za, (undef))),
369+
(AArch64fneg_mt_nsz node:$pg, (AArch64fma_p node:$pg, node:$zn, node:$zm, node:$za), (undef))]>;
370+
371+
def AArch64fnmls_p : PatFrags<(ops node:$pg, node:$za, node:$zn, node:$zm),
372+
[(AArch64fma_p node:$pg, node:$zn, node:$zm, (AArch64fneg_mt node:$pg, node:$za, (undef)))]>;
356373

357374
def AArch64fsubr_p : PatFrag<(ops node:$pg, node:$op1, node:$op2),
358375
(AArch64fsub_p node:$pg, node:$op2, node:$op1)>;
359376

360-
def AArch64fneg_mt_nsz : PatFrag<(ops node:$pred, node:$op, node:$pt),
361-
(AArch64fneg_mt node:$pred, node:$op, node:$pt), [{
362-
return N->getFlags().hasNoSignedZeros();
363-
}]>;
364-
365377
def SDT_AArch64Arith_Unpred : SDTypeProfile<1, 2, [
366378
SDTCisVec<0>, SDTCisVec<1>, SDTCisVec<2>,
367379
SDTCisSameAs<0,1>, SDTCisSameAs<1,2>
@@ -649,7 +661,7 @@ let Predicates = [HasSVE] in {
649661
} // End HasSVE
650662

651663
let Predicates = [HasSVEorSME] in {
652-
defm FCADD_ZPmZ : sve_fp_fcadd<"fcadd", int_aarch64_sve_fcadd>;
664+
defm FCADD_ZPmZ : sve_fp_fcadd<"fcadd", int_aarch64_sve_fcadd>;
653665
defm FCMLA_ZPmZZ : sve_fp_fcmla<"fcmla", int_aarch64_sve_fcmla>;
654666

655667
defm FMLA_ZPmZZ : sve_fp_3op_p_zds_a<0b00, "fmla", "FMLA_ZPZZZ", AArch64fmla_m1, "FMAD_ZPmZZ">;
@@ -662,48 +674,10 @@ let Predicates = [HasSVEorSME] in {
662674
defm FNMAD_ZPmZZ : sve_fp_3op_p_zds_b<0b10, "fnmad", int_aarch64_sve_fnmad, "FNMLA_ZPmZZ", /*isReverseInstr*/ 1>;
663675
defm FNMSB_ZPmZZ : sve_fp_3op_p_zds_b<0b11, "fnmsb", int_aarch64_sve_fnmsb, "FNMLS_ZPmZZ", /*isReverseInstr*/ 1>;
664676

665-
defm FMLA_ZPZZZ : sve_fp_3op_p_zds_zx;
666-
defm FMLS_ZPZZZ : sve_fp_3op_p_zds_zx;
667-
defm FNMLA_ZPZZZ : sve_fp_3op_p_zds_zx;
668-
defm FNMLS_ZPZZZ : sve_fp_3op_p_zds_zx;
669-
670-
multiclass fma<ValueType Ty, ValueType PredTy, string Suffix> {
671-
// Zd = Za + Zn * Zm
672-
def : Pat<(Ty (AArch64fma_p PredTy:$P, Ty:$Zn, Ty:$Zm, Ty:$Za)),
673-
(!cast<Instruction>("FMLA_ZPZZZ_UNDEF_"#Suffix) $P, ZPR:$Za, ZPR:$Zn, ZPR:$Zm)>;
674-
675-
// Zd = Za + -Zn * Zm
676-
def : Pat<(Ty (AArch64fmls_p PredTy:$P, Ty:$Zn, Ty:$Zm, Ty:$Za)),
677-
(!cast<Instruction>("FMLS_ZPZZZ_UNDEF_"#Suffix) $P, ZPR:$Za, ZPR:$Zn, ZPR:$Zm)>;
678-
679-
// Zd = -Za + Zn * Zm
680-
def : Pat<(Ty (AArch64fma_p PredTy:$P, Ty:$Zn, Ty:$Zm, (AArch64fneg_mt PredTy:$P, Ty:$Za, (Ty (undef))))),
681-
(!cast<Instruction>("FNMLS_ZPZZZ_UNDEF_"#Suffix) $P, ZPR:$Za, ZPR:$Zn, ZPR:$Zm)>;
682-
683-
// Zd = -Za + -Zn * Zm
684-
def : Pat<(Ty (AArch64fma_p PredTy:$P, (AArch64fneg_mt PredTy:$P, Ty:$Zn, (Ty (undef))), Ty:$Zm, (AArch64fneg_mt PredTy:$P, Ty:$Za, (Ty (undef))))),
685-
(!cast<Instruction>("FNMLA_ZPZZZ_UNDEF_"#Suffix) $P, ZPR:$Za, ZPR:$Zn, ZPR:$Zm)>;
686-
687-
// Zd = -(Za + Zn * Zm)
688-
// (with nsz neg.)
689-
def : Pat<(AArch64fneg_mt_nsz PredTy:$P, (AArch64fma_p PredTy:$P, Ty:$Zn, Ty:$Zm, Ty:$Za), (Ty (undef))),
690-
(!cast<Instruction>("FNMLA_ZPZZZ_UNDEF_"#Suffix) $P, ZPR:$Za, ZPR:$Zn, ZPR:$Zm)>;
691-
692-
// Zda = Zda + Zn * Zm
693-
def : Pat<(vselect (PredTy PPR:$Pg), (Ty (AArch64fma_p (PredTy (AArch64ptrue 31)), ZPR:$Zn, ZPR:$Zm, ZPR:$Za)), ZPR:$Za),
694-
(!cast<Instruction>("FMLA_ZPmZZ_"#Suffix) PPR:$Pg, ZPR:$Za, ZPR:$Zn, ZPR:$Zm)>;
695-
696-
// Zda = Zda + -Zn * Zm
697-
def : Pat<(vselect (PredTy PPR:$Pg), (Ty (AArch64fma_p (PredTy (AArch64ptrue 31)), (AArch64fneg_mt (PredTy (AArch64ptrue 31)), Ty:$Zn, (Ty (undef))), ZPR:$Zm, ZPR:$Za)), ZPR:$Za),
698-
(!cast<Instruction>("FMLS_ZPmZZ_"#Suffix) PPR:$Pg, ZPR:$Za, ZPR:$Zn, ZPR:$Zm)>;
699-
}
700-
701-
defm : fma<nxv8f16, nxv8i1, "H">;
702-
defm : fma<nxv4f16, nxv4i1, "H">;
703-
defm : fma<nxv2f16, nxv2i1, "H">;
704-
defm : fma<nxv4f32, nxv4i1, "S">;
705-
defm : fma<nxv2f32, nxv2i1, "S">;
706-
defm : fma<nxv2f64, nxv2i1, "D">;
677+
defm FMLA_ZPZZZ : sve_fp_3op_pred_hfd<AArch64fmla_p>;
678+
defm FMLS_ZPZZZ : sve_fp_3op_pred_hfd<AArch64fmls_p>;
679+
defm FNMLA_ZPZZZ : sve_fp_3op_pred_hfd<AArch64fnmla_p>;
680+
defm FNMLS_ZPZZZ : sve_fp_3op_pred_hfd<AArch64fnmls_p>;
707681
} // End HasSVEorSME
708682

709683
let Predicates = [HasSVE] in {

llvm/lib/Target/AArch64/SVEInstrFormats.td

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2286,12 +2286,6 @@ multiclass sve_fp_3op_p_zds_b<bits<2> opc, string asm, SDPatternOperator op,
22862286
def : SVE_4_Op_Pat<nxv2f64, op, nxv2i1, nxv2f64, nxv2f64, nxv2f64, !cast<Instruction>(NAME # _D)>;
22872287
}
22882288

2289-
multiclass sve_fp_3op_p_zds_zx {
2290-
def _UNDEF_H : PredThreeOpPseudo<NAME # _H, ZPR16, FalseLanesUndef>;
2291-
def _UNDEF_S : PredThreeOpPseudo<NAME # _S, ZPR32, FalseLanesUndef>;
2292-
def _UNDEF_D : PredThreeOpPseudo<NAME # _D, ZPR64, FalseLanesUndef>;
2293-
}
2294-
22952289
//===----------------------------------------------------------------------===//
22962290
// SVE Floating Point Multiply-Add - Indexed Group
22972291
//===----------------------------------------------------------------------===//
@@ -8963,6 +8957,20 @@ multiclass sve_fp_bin_pred_hfd<SDPatternOperator op> {
89638957
def : SVE_3_Op_Pat<nxv2f64, op, nxv2i1, nxv2f64, nxv2f64, !cast<Pseudo>(NAME # _UNDEF_D)>;
89648958
}
89658959

8960+
// Predicated pseudo floating point three operand instructions.
8961+
multiclass sve_fp_3op_pred_hfd<SDPatternOperator op> {
8962+
def _UNDEF_H : PredThreeOpPseudo<NAME # _H, ZPR16, FalseLanesUndef>;
8963+
def _UNDEF_S : PredThreeOpPseudo<NAME # _S, ZPR32, FalseLanesUndef>;
8964+
def _UNDEF_D : PredThreeOpPseudo<NAME # _D, ZPR64, FalseLanesUndef>;
8965+
8966+
def : SVE_4_Op_Pat<nxv8f16, op, nxv8i1, nxv8f16, nxv8f16, nxv8f16, !cast<Instruction>(NAME # _UNDEF_H)>;
8967+
def : SVE_4_Op_Pat<nxv4f16, op, nxv4i1, nxv4f16, nxv4f16, nxv4f16, !cast<Instruction>(NAME # _UNDEF_H)>;
8968+
def : SVE_4_Op_Pat<nxv2f16, op, nxv2i1, nxv2f16, nxv2f16, nxv2f16, !cast<Instruction>(NAME # _UNDEF_H)>;
8969+
def : SVE_4_Op_Pat<nxv4f32, op, nxv4i1, nxv4f32, nxv4f32, nxv4f32, !cast<Instruction>(NAME # _UNDEF_S)>;
8970+
def : SVE_4_Op_Pat<nxv2f32, op, nxv2i1, nxv2f32, nxv2f32, nxv2f32, !cast<Instruction>(NAME # _UNDEF_S)>;
8971+
def : SVE_4_Op_Pat<nxv2f64, op, nxv2i1, nxv2f64, nxv2f64, nxv2f64, !cast<Instruction>(NAME # _UNDEF_D)>;
8972+
}
8973+
89668974
// Predicated pseudo integer two operand instructions.
89678975
multiclass sve_int_bin_pred_bhsd<SDPatternOperator op> {
89688976
def _UNDEF_B : PredTwoOpPseudo<NAME # _B, ZPR8, FalseLanesUndef>;

0 commit comments

Comments
 (0)