Skip to content

Commit 3ea90bc

Browse files
committed
[RISCV] Remove VFCVT_X(U)_F_VL by using VFCVT_RM_X(U)_F_VL with DYN rounding mode.
Not completely happy with the hack to RISCVTargetLowering::lowerVPOp.
1 parent 744bbe0 commit 3ea90bc

File tree

3 files changed

+15
-84
lines changed

3 files changed

+15
-84
lines changed

llvm/lib/Target/RISCV/RISCVISelLowering.cpp

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -3030,6 +3030,7 @@ static RISCVFPRndMode::RoundingMode matchRoundingOp(unsigned Opc) {
30303030
case ISD::VP_FROUND:
30313031
return RISCVFPRndMode::RMM;
30323032
case ISD::FRINT:
3033+
case ISD::VP_FRINT:
30333034
return RISCVFPRndMode::DYN;
30343035
}
30353036

@@ -3101,6 +3102,8 @@ lowerVectorFTRUNC_FCEIL_FFLOOR_FROUND(SDValue Op, SelectionDAG &DAG,
31013102
switch (Op.getOpcode()) {
31023103
default:
31033104
llvm_unreachable("Unexpected opcode");
3105+
case ISD::FRINT:
3106+
case ISD::VP_FRINT:
31043107
case ISD::FCEIL:
31053108
case ISD::VP_FCEIL:
31063109
case ISD::FFLOOR:
@@ -3120,10 +3123,6 @@ lowerVectorFTRUNC_FCEIL_FFLOOR_FROUND(SDValue Op, SelectionDAG &DAG,
31203123
Truncated = DAG.getNode(RISCVISD::VFCVT_RTZ_X_F_VL, DL, IntVT, Src,
31213124
Mask, VL);
31223125
break;
3123-
case ISD::FRINT:
3124-
case ISD::VP_FRINT:
3125-
Truncated = DAG.getNode(RISCVISD::VFCVT_X_F_VL, DL, IntVT, Src, Mask, VL);
3126-
break;
31273126
case ISD::FNEARBYINT:
31283127
case ISD::VP_FNEARBYINT:
31293128
Truncated = DAG.getNode(RISCVISD::VFROUND_NOEXCEPT_VL, DL, ContainerVT, Src,
@@ -3294,8 +3293,10 @@ static SDValue lowerVectorXRINT(SDValue Op, SelectionDAG &DAG,
32943293
}
32953294

32963295
auto [Mask, VL] = getDefaultVLOps(VT, ContainerVT, DL, DAG, Subtarget);
3297-
SDValue Truncated =
3298-
DAG.getNode(RISCVISD::VFCVT_X_F_VL, DL, ContainerVT, Src, Mask, VL);
3296+
SDValue Truncated = DAG.getNode(
3297+
RISCVISD::VFCVT_RM_X_F_VL, DL, ContainerVT, Src, Mask,
3298+
DAG.getTargetConstant(RISCVFPRndMode::DYN, DL, Subtarget.getXLenVT()),
3299+
VL);
32993300

33003301
if (!VT.isFixedLengthVector())
33013302
return Truncated;
@@ -6170,7 +6171,7 @@ static unsigned getRISCVVLOp(SDValue Op) {
61706171
case ISD::VP_LRINT:
61716172
case ISD::LLRINT:
61726173
case ISD::VP_LLRINT:
6173-
return RISCVISD::VFCVT_X_F_VL;
6174+
return RISCVISD::VFCVT_RM_X_F_VL;
61746175
}
61756176
// clang-format on
61766177
#undef OP_CASE
@@ -6183,7 +6184,7 @@ static bool hasPassthruOp(unsigned Opcode) {
61836184
Opcode <= RISCVISD::LAST_RISCV_STRICTFP_OPCODE &&
61846185
"not a RISC-V target specific op");
61856186
static_assert(RISCVISD::LAST_VL_VECTOR_OP - RISCVISD::FIRST_VL_VECTOR_OP ==
6186-
130 &&
6187+
128 &&
61876188
RISCVISD::LAST_RISCV_STRICTFP_OPCODE -
61886189
ISD::FIRST_TARGET_STRICTFP_OPCODE ==
61896190
21 &&
@@ -6209,7 +6210,7 @@ static bool hasMaskOp(unsigned Opcode) {
62096210
Opcode <= RISCVISD::LAST_RISCV_STRICTFP_OPCODE &&
62106211
"not a RISC-V target specific op");
62116212
static_assert(RISCVISD::LAST_VL_VECTOR_OP - RISCVISD::FIRST_VL_VECTOR_OP ==
6212-
130 &&
6213+
128 &&
62136214
RISCVISD::LAST_RISCV_STRICTFP_OPCODE -
62146215
ISD::FIRST_TARGET_STRICTFP_OPCODE ==
62156216
21 &&
@@ -11549,6 +11550,11 @@ SDValue RISCVTargetLowering::lowerVPOp(SDValue Op, SelectionDAG &DAG) const {
1154911550
}
1155011551
}
1155111552
}
11553+
// VFCVT_RM_X_F_VL requires a rounding mode to be injected before the VL.
11554+
if (RISCVISDOpc == RISCVISD::VFCVT_RM_X_F_VL &&
11555+
ISD::getVPExplicitVectorLengthIdx(Op.getOpcode()) == OpIdx.index())
11556+
Ops.push_back(DAG.getTargetConstant(RISCVFPRndMode::DYN, DL,
11557+
Subtarget.getXLenVT()));
1155211558
// Pass through operands which aren't fixed-length vectors.
1155311559
if (!V.getValueType().isFixedLengthVector()) {
1155411560
Ops.push_back(V);
@@ -15710,10 +15716,6 @@ static SDValue performFP_TO_INTCombine(SDNode *N,
1571015716
unsigned Opc =
1571115717
IsSigned ? RISCVISD::VFCVT_RTZ_X_F_VL : RISCVISD::VFCVT_RTZ_XU_F_VL;
1571215718
FpToInt = DAG.getNode(Opc, DL, ContainerVT, XVal, Mask, VL);
15713-
} else if (FRM == RISCVFPRndMode::DYN) {
15714-
unsigned Opc =
15715-
IsSigned ? RISCVISD::VFCVT_X_F_VL : RISCVISD::VFCVT_XU_F_VL;
15716-
FpToInt = DAG.getNode(Opc, DL, ContainerVT, XVal, Mask, VL);
1571715719
} else {
1571815720
unsigned Opc =
1571915721
IsSigned ? RISCVISD::VFCVT_RM_X_F_VL : RISCVISD::VFCVT_RM_XU_F_VL;
@@ -20277,8 +20279,6 @@ const char *RISCVTargetLowering::getTargetNodeName(unsigned Opcode) const {
2027720279
NODE_NAME_CASE(VFCVT_RTZ_XU_F_VL)
2027820280
NODE_NAME_CASE(VFCVT_RM_X_F_VL)
2027920281
NODE_NAME_CASE(VFCVT_RM_XU_F_VL)
20280-
NODE_NAME_CASE(VFCVT_X_F_VL)
20281-
NODE_NAME_CASE(VFCVT_XU_F_VL)
2028220282
NODE_NAME_CASE(VFROUND_NOEXCEPT_VL)
2028320283
NODE_NAME_CASE(SINT_TO_FP_VL)
2028420284
NODE_NAME_CASE(UINT_TO_FP_VL)

llvm/lib/Target/RISCV/RISCVISelLowering.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -307,8 +307,6 @@ enum NodeType : unsigned {
307307
FCOPYSIGN_VL, // Has a passthru operand
308308
VFCVT_RTZ_X_F_VL,
309309
VFCVT_RTZ_XU_F_VL,
310-
VFCVT_X_F_VL,
311-
VFCVT_XU_F_VL,
312310
VFROUND_NOEXCEPT_VL,
313311
VFCVT_RM_X_F_VL, // Has a rounding mode operand.
314312
VFCVT_RM_XU_F_VL, // Has a rounding mode operand.

llvm/lib/Target/RISCV/RISCVInstrInfoVVLPatterns.td

Lines changed: 0 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -270,8 +270,6 @@ def SDT_RISCVSETCCOP_VL : SDTypeProfile<1, 6, [
270270
SDTCisSameAs<0, 5>, SDTCisVT<6, XLenVT>]>;
271271

272272
// Float -> Int
273-
def riscv_vfcvt_xu_f_vl : SDNode<"RISCVISD::VFCVT_XU_F_VL", SDT_RISCVFP2IOp_VL>;
274-
def riscv_vfcvt_x_f_vl : SDNode<"RISCVISD::VFCVT_X_F_VL", SDT_RISCVFP2IOp_VL>;
275273
def riscv_vfcvt_rm_xu_f_vl : SDNode<"RISCVISD::VFCVT_RM_XU_F_VL", SDT_RISCVFP2IOp_RM_VL>;
276274
def riscv_vfcvt_rm_x_f_vl : SDNode<"RISCVISD::VFCVT_RM_X_F_VL", SDT_RISCVFP2IOp_RM_VL>;
277275

@@ -1206,24 +1204,6 @@ multiclass VPatConvertFP2IVL_V<SDPatternOperator vop, string instruction_name> {
12061204
}
12071205
}
12081206

1209-
multiclass VPatConvertFP2IVL_V_RM<SDPatternOperator vop, string instruction_name> {
1210-
foreach fvti = AllFloatVectors in {
1211-
defvar ivti = GetIntVTypeInfo<fvti>.Vti;
1212-
let Predicates = !listconcat(GetVTypePredicates<fvti>.Predicates,
1213-
GetVTypePredicates<ivti>.Predicates) in
1214-
def : Pat<(ivti.Vector (vop (fvti.Vector fvti.RegClass:$rs1),
1215-
(fvti.Mask V0),
1216-
VLOpFrag)),
1217-
(!cast<Instruction>(instruction_name#"_"#ivti.LMul.MX#"_MASK")
1218-
(ivti.Vector (IMPLICIT_DEF)), fvti.RegClass:$rs1,
1219-
(fvti.Mask V0),
1220-
// Value to indicate no rounding mode change in
1221-
// RISCVInsertReadWriteCSR
1222-
FRM_DYN,
1223-
GPR:$vl, ivti.Log2SEW, TA_MA)>;
1224-
}
1225-
}
1226-
12271207

12281208
multiclass VPatConvertFP2I_RM_VL_V<SDPatternOperator vop, string instruction_name> {
12291209
foreach fvti = AllFloatVectors in {
@@ -1289,25 +1269,6 @@ multiclass VPatWConvertFP2IVL_V<SDPatternOperator vop, string instruction_name>
12891269
}
12901270
}
12911271

1292-
multiclass VPatWConvertFP2IVL_V_RM<SDPatternOperator vop, string instruction_name> {
1293-
foreach fvtiToFWti = AllWidenableFloatVectors in {
1294-
defvar fvti = fvtiToFWti.Vti;
1295-
defvar iwti = GetIntVTypeInfo<fvtiToFWti.Wti>.Vti;
1296-
let Predicates = !listconcat(GetVTypePredicates<fvti>.Predicates,
1297-
GetVTypePredicates<iwti>.Predicates) in
1298-
def : Pat<(iwti.Vector (vop (fvti.Vector fvti.RegClass:$rs1),
1299-
(fvti.Mask V0),
1300-
VLOpFrag)),
1301-
(!cast<Instruction>(instruction_name#"_"#fvti.LMul.MX#"_MASK")
1302-
(iwti.Vector (IMPLICIT_DEF)), fvti.RegClass:$rs1,
1303-
(fvti.Mask V0),
1304-
// Value to indicate no rounding mode change in
1305-
// RISCVInsertReadWriteCSR
1306-
FRM_DYN,
1307-
GPR:$vl, fvti.Log2SEW, TA_MA)>;
1308-
}
1309-
}
1310-
13111272

13121273
multiclass VPatWConvertFP2I_RM_VL_V<SDNode vop, string instruction_name> {
13131274
foreach fvtiToFWti = AllWidenableFloatVectors in {
@@ -1361,28 +1322,6 @@ multiclass VPatNConvertFP2IVL_W<SDPatternOperator vop,
13611322
}
13621323
}
13631324

1364-
multiclass VPatNConvertFP2IVL_W_RM<SDPatternOperator vop,
1365-
string instruction_name> {
1366-
// Reuse the same list of types used in the widening nodes, but just swap the
1367-
// direction of types around so we're converting from Wti -> Vti
1368-
foreach vtiToWti = AllWidenableIntToFloatVectors in {
1369-
defvar vti = vtiToWti.Vti;
1370-
defvar fwti = vtiToWti.Wti;
1371-
let Predicates = !listconcat(GetVTypePredicates<vti>.Predicates,
1372-
GetVTypePredicates<fwti>.Predicates) in
1373-
def : Pat<(vti.Vector (vop (fwti.Vector fwti.RegClass:$rs1),
1374-
(fwti.Mask V0),
1375-
VLOpFrag)),
1376-
(!cast<Instruction>(instruction_name#"_"#vti.LMul.MX#"_MASK")
1377-
(vti.Vector (IMPLICIT_DEF)), fwti.RegClass:$rs1,
1378-
(fwti.Mask V0),
1379-
// Value to indicate no rounding mode change in
1380-
// RISCVInsertReadWriteCSR
1381-
FRM_DYN,
1382-
GPR:$vl, vti.Log2SEW, TA_MA)>;
1383-
}
1384-
}
1385-
13861325
multiclass VPatNConvertFP2I_RM_VL_W<SDNode vop, string instruction_name> {
13871326
foreach vtiToWti = AllWidenableIntToFloatVectors in {
13881327
defvar vti = vtiToWti.Vti;
@@ -2637,8 +2576,6 @@ foreach fvti = AllFloatVectors in {
26372576
}
26382577

26392578
// 13.17. Vector Single-Width Floating-Point/Integer Type-Convert Instructions
2640-
defm : VPatConvertFP2IVL_V_RM<riscv_vfcvt_xu_f_vl, "PseudoVFCVT_XU_F_V">;
2641-
defm : VPatConvertFP2IVL_V_RM<riscv_vfcvt_x_f_vl, "PseudoVFCVT_X_F_V">;
26422579
defm : VPatConvertFP2I_RM_VL_V<riscv_vfcvt_rm_xu_f_vl, "PseudoVFCVT_XU_F_V">;
26432580
defm : VPatConvertFP2I_RM_VL_V<any_riscv_vfcvt_rm_x_f_vl, "PseudoVFCVT_X_F_V">;
26442581

@@ -2652,8 +2589,6 @@ defm : VPatConvertI2FP_RM_VL_V<riscv_vfcvt_rm_f_xu_vl, "PseudoVFCVT_F_XU_V">;
26522589
defm : VPatConvertI2FP_RM_VL_V<riscv_vfcvt_rm_f_x_vl, "PseudoVFCVT_F_X_V">;
26532590

26542591
// 13.18. Widening Floating-Point/Integer Type-Convert Instructions
2655-
defm : VPatWConvertFP2IVL_V_RM<riscv_vfcvt_xu_f_vl, "PseudoVFWCVT_XU_F_V">;
2656-
defm : VPatWConvertFP2IVL_V_RM<riscv_vfcvt_x_f_vl, "PseudoVFWCVT_X_F_V">;
26572592
defm : VPatWConvertFP2I_RM_VL_V<riscv_vfcvt_rm_xu_f_vl, "PseudoVFWCVT_XU_F_V">;
26582593
defm : VPatWConvertFP2I_RM_VL_V<riscv_vfcvt_rm_x_f_vl, "PseudoVFWCVT_X_F_V">;
26592594

@@ -2694,8 +2629,6 @@ foreach fvtiToFWti = AllWidenableBFloatToFloatVectors in {
26942629
}
26952630

26962631
// 13.19 Narrowing Floating-Point/Integer Type-Convert Instructions
2697-
defm : VPatNConvertFP2IVL_W_RM<riscv_vfcvt_xu_f_vl, "PseudoVFNCVT_XU_F_W">;
2698-
defm : VPatNConvertFP2IVL_W_RM<riscv_vfcvt_x_f_vl, "PseudoVFNCVT_X_F_W">;
26992632
defm : VPatNConvertFP2I_RM_VL_W<riscv_vfcvt_rm_xu_f_vl, "PseudoVFNCVT_XU_F_W">;
27002633
defm : VPatNConvertFP2I_RM_VL_W<riscv_vfcvt_rm_x_f_vl, "PseudoVFNCVT_X_F_W">;
27012634

0 commit comments

Comments
 (0)