Skip to content

Commit f0bb5cf

Browse files
authored
[Mips] Add instruction selection for strict FP (#168870)
This consists of marking the various strict opcodes as legal, and adjusting instruction selection patterns so that 'op' is 'any_op'. The changes are similar to those in D114946 for AArch64 and #160696 for ARM. Only Mips32/64 FPU instructions are affected. Added lowering for for STRICT_FP_TO_UINT and STRICT_FP_TO_SINT ops.
1 parent 31d4150 commit f0bb5cf

File tree

5 files changed

+798
-36
lines changed

5 files changed

+798
-36
lines changed

llvm/lib/Target/Mips/MipsISelLowering.cpp

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -356,6 +356,8 @@ MipsTargetLowering::MipsTargetLowering(const MipsTargetMachine &TM,
356356
setOperationAction(ISD::FCOPYSIGN, MVT::f32, Custom);
357357
setOperationAction(ISD::FCOPYSIGN, MVT::f64, Custom);
358358
setOperationAction(ISD::FP_TO_SINT, MVT::i32, Custom);
359+
setOperationAction(ISD::STRICT_FP_TO_SINT, MVT::i32, Custom);
360+
setOperationAction(ISD::STRICT_FP_TO_UINT, MVT::i32, Custom);
359361

360362
if (Subtarget.hasMips32r2() ||
361363
getTargetMachine().getTargetTriple().isOSLinux())
@@ -395,6 +397,8 @@ MipsTargetLowering::MipsTargetLowering(const MipsTargetMachine &TM,
395397
setOperationAction(ISD::STORE, MVT::i64, Custom);
396398
}
397399
setOperationAction(ISD::FP_TO_SINT, MVT::i64, Custom);
400+
setOperationAction(ISD::STRICT_FP_TO_UINT, MVT::i64, Custom);
401+
setOperationAction(ISD::STRICT_FP_TO_SINT, MVT::i64, Custom);
398402
setOperationAction(ISD::SHL_PARTS, MVT::i64, Custom);
399403
setOperationAction(ISD::SRA_PARTS, MVT::i64, Custom);
400404
setOperationAction(ISD::SRL_PARTS, MVT::i64, Custom);
@@ -433,6 +437,7 @@ MipsTargetLowering::MipsTargetLowering(const MipsTargetMachine &TM,
433437
setOperationAction(ISD::FP_TO_UINT, MVT::i32, Expand);
434438
setOperationAction(ISD::FP_TO_UINT, MVT::i64, Expand);
435439
setOperationAction(ISD::SIGN_EXTEND_INREG, MVT::i1, Expand);
440+
436441
if (Subtarget.hasCnMips()) {
437442
setOperationAction(ISD::CTPOP, MVT::i32, Legal);
438443
setOperationAction(ISD::CTPOP, MVT::i64, Legal);
@@ -1354,6 +1359,9 @@ LowerOperation(SDValue Op, SelectionDAG &DAG) const
13541359
case ISD::LOAD: return lowerLOAD(Op, DAG);
13551360
case ISD::STORE: return lowerSTORE(Op, DAG);
13561361
case ISD::EH_DWARF_CFA: return lowerEH_DWARF_CFA(Op, DAG);
1362+
case ISD::STRICT_FP_TO_SINT:
1363+
case ISD::STRICT_FP_TO_UINT:
1364+
return lowerSTRICT_FP_TO_INT(Op, DAG);
13571365
case ISD::FP_TO_SINT: return lowerFP_TO_SINT(Op, DAG);
13581366
case ISD::READCYCLECOUNTER:
13591367
return lowerREADCYCLECOUNTER(Op, DAG);
@@ -3011,6 +3019,20 @@ SDValue MipsTargetLowering::lowerFP_TO_SINT(SDValue Op,
30113019
return DAG.getNode(ISD::BITCAST, SDLoc(Op), Op.getValueType(), Trunc);
30123020
}
30133021

3022+
SDValue MipsTargetLowering::lowerSTRICT_FP_TO_INT(SDValue Op,
3023+
SelectionDAG &DAG) const {
3024+
assert(Op->isStrictFPOpcode());
3025+
SDValue SrcVal = Op.getOperand(1);
3026+
SDLoc Loc(Op);
3027+
3028+
SDValue Result =
3029+
DAG.getNode(Op.getOpcode() == ISD::STRICT_FP_TO_SINT ? ISD::FP_TO_SINT
3030+
: ISD::FP_TO_UINT,
3031+
Loc, Op.getValueType(), SrcVal);
3032+
3033+
return DAG.getMergeValues({Result, Op.getOperand(0)}, Loc);
3034+
}
3035+
30143036
//===----------------------------------------------------------------------===//
30153037
// Calling Convention Implementation
30163038
//===----------------------------------------------------------------------===//

llvm/lib/Target/Mips/MipsISelLowering.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -590,6 +590,7 @@ class TargetRegisterClass;
590590
bool IsSRA) const;
591591
SDValue lowerEH_DWARF_CFA(SDValue Op, SelectionDAG &DAG) const;
592592
SDValue lowerFP_TO_SINT(SDValue Op, SelectionDAG &DAG) const;
593+
SDValue lowerSTRICT_FP_TO_INT(SDValue Op, SelectionDAG &DAG) const;
593594
SDValue lowerREADCYCLECOUNTER(SDValue Op, SelectionDAG &DAG) const;
594595

595596
/// isEligibleForTailCallOptimization - Check whether the call is eligible

llvm/lib/Target/Mips/MipsInstrFPU.td

Lines changed: 35 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -203,14 +203,14 @@ class MADDS_FT<string opstr, RegisterOperand RC, InstrItinClass Itin,
203203
SDPatternOperator OpNode = null_frag> :
204204
InstSE<(outs RC:$fd), (ins RC:$fr, RC:$fs, RC:$ft),
205205
!strconcat(opstr, "\t$fd, $fr, $fs, $ft"),
206-
[(set RC:$fd, (OpNode (fmul RC:$fs, RC:$ft), RC:$fr))], Itin,
206+
[(set RC:$fd, (OpNode (any_fmul RC:$fs, RC:$ft), RC:$fr))], Itin,
207207
FrmFR, opstr>, HARDFLOAT;
208208

209209
class NMADDS_FT<string opstr, RegisterOperand RC, InstrItinClass Itin,
210210
SDPatternOperator OpNode = null_frag> :
211211
InstSE<(outs RC:$fd), (ins RC:$fr, RC:$fs, RC:$ft),
212212
!strconcat(opstr, "\t$fd, $fr, $fs, $ft"),
213-
[(set RC:$fd, (fsub fpimm0, (OpNode (fmul RC:$fs, RC:$ft), RC:$fr)))],
213+
[(set RC:$fd, (any_fsub fpimm0, (OpNode (any_fmul RC:$fs, RC:$ft), RC:$fr)))],
214214
Itin, FrmFR, opstr>, HARDFLOAT;
215215

216216
class LWXC1_FT<string opstr, RegisterOperand DRC,
@@ -280,7 +280,6 @@ class C_COND_FT<string CondStr, string Typestr, RegisterOperand RC,
280280
let hasFCCRegOperand = 1;
281281
}
282282

283-
284283
multiclass C_COND_M<string TypeStr, RegisterOperand RC, bits<5> fmt,
285284
InstrItinClass itin> {
286285
def C_F_#NAME : MMRel, C_COND_FT<"f", TypeStr, RC, itin>,
@@ -539,8 +538,8 @@ let AdditionalPredicates = [NotInMicroMips] in {
539538

540539
let AdditionalPredicates = [NotInMicroMips] in {
541540
def FSQRT_S : MMRel, StdMMR6Rel, ABSS_FT<"sqrt.s", FGR32Opnd, FGR32Opnd,
542-
II_SQRT_S, fsqrt>, ABSS_FM<0x4, 16>, ISA_MIPS2;
543-
defm FSQRT : ABSS_M<"sqrt.d", II_SQRT_D, fsqrt>, ABSS_FM<0x4, 17>, ISA_MIPS2;
541+
II_SQRT_S, any_fsqrt>, ABSS_FM<0x4, 16>, ISA_MIPS2;
542+
defm FSQRT : ABSS_M<"sqrt.d", II_SQRT_D, any_fsqrt>, ABSS_FM<0x4, 17>, ISA_MIPS2;
544543
}
545544

546545
// The odd-numbered registers are only referenced when doing loads,
@@ -661,58 +660,58 @@ let AdditionalPredicates = [NotInMicroMips],
661660

662661
/// Floating-point Arithmetic
663662
let AdditionalPredicates = [NotInMicroMips] in {
664-
def FADD_S : MMRel, ADDS_FT<"add.s", FGR32Opnd, II_ADD_S, 1, fadd>,
663+
def FADD_S : MMRel, ADDS_FT<"add.s", FGR32Opnd, II_ADD_S, 1, any_fadd>,
665664
ADDS_FM<0x00, 16>, ISA_MIPS1;
666-
defm FADD : ADDS_M<"add.d", II_ADD_D, 1, fadd>, ADDS_FM<0x00, 17>,
665+
defm FADD : ADDS_M<"add.d", II_ADD_D, 1, any_fadd>, ADDS_FM<0x00, 17>,
667666
ISA_MIPS1;
668-
def FDIV_S : MMRel, ADDS_FT<"div.s", FGR32Opnd, II_DIV_S, 0, fdiv>,
667+
def FDIV_S : MMRel, ADDS_FT<"div.s", FGR32Opnd, II_DIV_S, 0, any_fdiv>,
669668
ADDS_FM<0x03, 16>, ISA_MIPS1;
670-
defm FDIV : ADDS_M<"div.d", II_DIV_D, 0, fdiv>, ADDS_FM<0x03, 17>,
669+
defm FDIV : ADDS_M<"div.d", II_DIV_D, 0, any_fdiv>, ADDS_FM<0x03, 17>,
671670
ISA_MIPS1;
672-
def FMUL_S : MMRel, ADDS_FT<"mul.s", FGR32Opnd, II_MUL_S, 1, fmul>,
671+
def FMUL_S : MMRel, ADDS_FT<"mul.s", FGR32Opnd, II_MUL_S, 1, any_fmul>,
673672
ADDS_FM<0x02, 16>, ISA_MIPS1;
674-
defm FMUL : ADDS_M<"mul.d", II_MUL_D, 1, fmul>, ADDS_FM<0x02, 17>,
673+
defm FMUL : ADDS_M<"mul.d", II_MUL_D, 1, any_fmul>, ADDS_FM<0x02, 17>,
675674
ISA_MIPS1;
676-
def FSUB_S : MMRel, ADDS_FT<"sub.s", FGR32Opnd, II_SUB_S, 0, fsub>,
675+
def FSUB_S : MMRel, ADDS_FT<"sub.s", FGR32Opnd, II_SUB_S, 0, any_fsub>,
677676
ADDS_FM<0x01, 16>, ISA_MIPS1;
678-
defm FSUB : ADDS_M<"sub.d", II_SUB_D, 0, fsub>, ADDS_FM<0x01, 17>,
677+
defm FSUB : ADDS_M<"sub.d", II_SUB_D, 0, any_fsub>, ADDS_FM<0x01, 17>,
679678
ISA_MIPS1;
680679
}
681680

682681
let AdditionalPredicates = [NotInMicroMips, HasMadd4] in {
683-
def MADD_S : MMRel, MADDS_FT<"madd.s", FGR32Opnd, II_MADD_S, fadd>,
682+
def MADD_S : MMRel, MADDS_FT<"madd.s", FGR32Opnd, II_MADD_S, any_fadd>,
684683
MADDS_FM<4, 0>, INSN_MIPS4_32R2_NOT_32R6_64R6;
685-
def MSUB_S : MMRel, MADDS_FT<"msub.s", FGR32Opnd, II_MSUB_S, fsub>,
684+
def MSUB_S : MMRel, MADDS_FT<"msub.s", FGR32Opnd, II_MSUB_S, any_fsub>,
686685
MADDS_FM<5, 0>, INSN_MIPS4_32R2_NOT_32R6_64R6;
687686

688-
def MADD_D32 : MMRel, MADDS_FT<"madd.d", AFGR64Opnd, II_MADD_D, fadd>,
687+
def MADD_D32 : MMRel, MADDS_FT<"madd.d", AFGR64Opnd, II_MADD_D, any_fadd>,
689688
MADDS_FM<4, 1>, INSN_MIPS4_32R2_NOT_32R6_64R6, FGR_32;
690-
def MSUB_D32 : MMRel, MADDS_FT<"msub.d", AFGR64Opnd, II_MSUB_D, fsub>,
689+
def MSUB_D32 : MMRel, MADDS_FT<"msub.d", AFGR64Opnd, II_MSUB_D, any_fsub>,
691690
MADDS_FM<5, 1>, INSN_MIPS4_32R2_NOT_32R6_64R6, FGR_32;
692691

693692
let DecoderNamespace = "MipsFP64" in {
694-
def MADD_D64 : MADDS_FT<"madd.d", FGR64Opnd, II_MADD_D, fadd>,
693+
def MADD_D64 : MADDS_FT<"madd.d", FGR64Opnd, II_MADD_D, any_fadd>,
695694
MADDS_FM<4, 1>, INSN_MIPS4_32R2_NOT_32R6_64R6, FGR_64;
696-
def MSUB_D64 : MADDS_FT<"msub.d", FGR64Opnd, II_MSUB_D, fsub>,
695+
def MSUB_D64 : MADDS_FT<"msub.d", FGR64Opnd, II_MSUB_D, any_fsub>,
697696
MADDS_FM<5, 1>, INSN_MIPS4_32R2_NOT_32R6_64R6, FGR_64;
698697
}
699698
}
700699

701700
let AdditionalPredicates = [NoNaNsFPMath, HasMadd4, NotInMicroMips] in {
702-
def NMADD_S : MMRel, NMADDS_FT<"nmadd.s", FGR32Opnd, II_NMADD_S, fadd>,
701+
def NMADD_S : MMRel, NMADDS_FT<"nmadd.s", FGR32Opnd, II_NMADD_S, any_fadd>,
703702
MADDS_FM<6, 0>, INSN_MIPS4_32R2_NOT_32R6_64R6;
704-
def NMSUB_S : MMRel, NMADDS_FT<"nmsub.s", FGR32Opnd, II_NMSUB_S, fsub>,
703+
def NMSUB_S : MMRel, NMADDS_FT<"nmsub.s", FGR32Opnd, II_NMSUB_S, any_fsub>,
705704
MADDS_FM<7, 0>, INSN_MIPS4_32R2_NOT_32R6_64R6;
706705

707-
def NMADD_D32 : MMRel, NMADDS_FT<"nmadd.d", AFGR64Opnd, II_NMADD_D, fadd>,
706+
def NMADD_D32 : MMRel, NMADDS_FT<"nmadd.d", AFGR64Opnd, II_NMADD_D, any_fadd>,
708707
MADDS_FM<6, 1>, INSN_MIPS4_32R2_NOT_32R6_64R6, FGR_32;
709-
def NMSUB_D32 : MMRel, NMADDS_FT<"nmsub.d", AFGR64Opnd, II_NMSUB_D, fsub>,
708+
def NMSUB_D32 : MMRel, NMADDS_FT<"nmsub.d", AFGR64Opnd, II_NMSUB_D, any_fsub>,
710709
MADDS_FM<7, 1>, INSN_MIPS4_32R2_NOT_32R6_64R6, FGR_32;
711710

712711
let DecoderNamespace = "MipsFP64" in {
713-
def NMADD_D64 : NMADDS_FT<"nmadd.d", FGR64Opnd, II_NMADD_D, fadd>,
712+
def NMADD_D64 : NMADDS_FT<"nmadd.d", FGR64Opnd, II_NMADD_D, any_fadd>,
714713
MADDS_FM<6, 1>, INSN_MIPS4_32R2_NOT_32R6_64R6, FGR_64;
715-
def NMSUB_D64 : NMADDS_FT<"nmsub.d", FGR64Opnd, II_NMSUB_D, fsub>,
714+
def NMSUB_D64 : NMADDS_FT<"nmsub.d", FGR64Opnd, II_NMSUB_D, any_fsub>,
716715
MADDS_FM<7, 1>, INSN_MIPS4_32R2_NOT_32R6_64R6, FGR_64;
717716
}
718717
}
@@ -935,34 +934,34 @@ let AdditionalPredicates = [NotInMicroMips] in {
935934
def : MipsPat<(f32 fpimm0), (MTC1 ZERO)>, ISA_MIPS1;
936935
def : MipsPat<(f32 fpimm0neg), (FNEG_S (MTC1 ZERO))>, ISA_MIPS1;
937936

938-
def : MipsPat<(f32 (sint_to_fp GPR32Opnd:$src)),
937+
def : MipsPat<(f32 (any_sint_to_fp GPR32Opnd:$src)),
939938
(PseudoCVT_S_W GPR32Opnd:$src)>;
940939
def : MipsPat<(MipsTruncIntFP FGR32Opnd:$src),
941940
(TRUNC_W_S FGR32Opnd:$src)>, ISA_MIPS1;
942941

943942
def : MipsPat<(MipsMTC1_D64 GPR32Opnd:$src),
944943
(MTC1_D64 GPR32Opnd:$src)>, ISA_MIPS1, FGR_64;
945944

946-
def : MipsPat<(f64 (sint_to_fp GPR32Opnd:$src)),
945+
def : MipsPat<(f64 (any_sint_to_fp GPR32Opnd:$src)),
947946
(PseudoCVT_D32_W GPR32Opnd:$src)>, FGR_32;
948947
let AdditionalPredicates = [NotInMicroMips] in {
949948
def : MipsPat<(MipsTruncIntFP AFGR64Opnd:$src),
950949
(TRUNC_W_D32 AFGR64Opnd:$src)>, ISA_MIPS2, FGR_32;
951-
def : MipsPat<(f32 (fpround AFGR64Opnd:$src)),
950+
def : MipsPat<(f32 (any_fpround AFGR64Opnd:$src)),
952951
(CVT_S_D32 AFGR64Opnd:$src)>, ISA_MIPS1, FGR_32;
953-
def : MipsPat<(f64 (fpextend FGR32Opnd:$src)),
952+
def : MipsPat<(f64 (any_fpextend FGR32Opnd:$src)),
954953
(CVT_D32_S FGR32Opnd:$src)>, ISA_MIPS1, FGR_32;
955954
}
956955

957956
def : MipsPat<(f64 fpimm0), (DMTC1 ZERO_64)>, ISA_MIPS3, GPR_64, FGR_64;
958957
def : MipsPat<(f64 fpimm0neg), (FNEG_D64 (DMTC1 ZERO_64))>, ISA_MIPS3, GPR_64,
959958
FGR_64;
960959

961-
def : MipsPat<(f64 (sint_to_fp GPR32Opnd:$src)),
960+
def : MipsPat<(f64 (any_sint_to_fp GPR32Opnd:$src)),
962961
(PseudoCVT_D64_W GPR32Opnd:$src)>, FGR_64;
963-
def : MipsPat<(f32 (sint_to_fp GPR64Opnd:$src)),
962+
def : MipsPat<(f32 (any_sint_to_fp GPR64Opnd:$src)),
964963
(EXTRACT_SUBREG (PseudoCVT_S_L GPR64Opnd:$src), sub_lo)>, FGR_64;
965-
def : MipsPat<(f64 (sint_to_fp GPR64Opnd:$src)),
964+
def : MipsPat<(f64 (any_sint_to_fp GPR64Opnd:$src)),
966965
(PseudoCVT_D64_L GPR64Opnd:$src)>, FGR_64;
967966

968967
def : MipsPat<(MipsTruncIntFP FGR64Opnd:$src),
@@ -973,17 +972,17 @@ def : MipsPat<(MipsTruncIntFP FGR64Opnd:$src),
973972
(TRUNC_L_D64 FGR64Opnd:$src)>, ISA_MIPS2, FGR_64;
974973

975974
let AdditionalPredicates = [NotInMicroMips] in {
976-
def : MipsPat<(f32 (fpround FGR64Opnd:$src)),
975+
def : MipsPat<(f32 (any_fpround FGR64Opnd:$src)),
977976
(CVT_S_D64 FGR64Opnd:$src)>, ISA_MIPS1, FGR_64;
978-
def : MipsPat<(f64 (fpextend FGR32Opnd:$src)),
977+
def : MipsPat<(f64 (any_fpextend FGR32Opnd:$src)),
979978
(CVT_D64_S FGR32Opnd:$src)>, ISA_MIPS1, FGR_64;
980979
}
981980

982981
// To generate NMADD and NMSUB instructions when fneg node is present
983982
multiclass NMADD_NMSUB<Instruction Nmadd, Instruction Nmsub, RegisterOperand RC> {
984-
def : MipsPat<(fneg (fadd (fmul RC:$fs, RC:$ft), RC:$fr)),
983+
def : MipsPat<(fneg (any_fadd (any_fmul RC:$fs, RC:$ft), RC:$fr)),
985984
(Nmadd RC:$fr, RC:$fs, RC:$ft)>;
986-
def : MipsPat<(fneg (fsub (fmul RC:$fs, RC:$ft), RC:$fr)),
985+
def : MipsPat<(fneg (any_fsub (any_fmul RC:$fs, RC:$ft), RC:$fr)),
987986
(Nmsub RC:$fr, RC:$fs, RC:$ft)>;
988987
}
989988

llvm/lib/Target/Mips/MipsSEISelLowering.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,12 @@ MipsSETargetLowering::MipsSETargetLowering(const MipsTargetMachine &TM,
210210
else
211211
addRegisterClass(MVT::f64, &Mips::AFGR64RegClass);
212212
}
213+
214+
for (auto Op : {ISD::STRICT_FADD, ISD::STRICT_FSUB, ISD::STRICT_FMUL,
215+
ISD::STRICT_FDIV, ISD::STRICT_FSQRT}) {
216+
setOperationAction(Op, MVT::f32, Legal);
217+
setOperationAction(Op, MVT::f64, Legal);
218+
}
213219
}
214220

215221
// Targets with 64bits integer registers, but no 64bit floating point register

0 commit comments

Comments
 (0)