Skip to content

Commit 19c2fb2

Browse files
authored
[ISel/RISCV] Custom-lower vector [l]lround (#147713)
Lower it just like the vector [l]lrint, using vfcvt, with the right rounding mode. Updating costs to account for this custom-lowering is left to a companion patch.
1 parent d7859ed commit 19c2fb2

File tree

5 files changed

+1475
-2753
lines changed

5 files changed

+1475
-2753
lines changed

llvm/lib/Target/RISCV/RISCVISelLowering.cpp

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1070,6 +1070,7 @@ RISCVTargetLowering::RISCVTargetLowering(const TargetMachine &TM,
10701070
// vXf32.
10711071
setOperationAction({ISD::FP_ROUND, ISD::FP_EXTEND}, VT, Custom);
10721072
setOperationAction({ISD::LRINT, ISD::LLRINT}, VT, Custom);
1073+
setOperationAction({ISD::LROUND, ISD::LLROUND}, VT, Custom);
10731074
// Custom-lower insert/extract operations to simplify patterns.
10741075
setOperationAction({ISD::INSERT_VECTOR_ELT, ISD::EXTRACT_VECTOR_ELT}, VT,
10751076
Custom);
@@ -1151,6 +1152,7 @@ RISCVTargetLowering::RISCVTargetLowering(const TargetMachine &TM,
11511152
Custom);
11521153
setOperationAction({ISD::VP_FP_ROUND, ISD::VP_FP_EXTEND}, VT, Custom);
11531154
setOperationAction({ISD::LRINT, ISD::LLRINT}, VT, Custom);
1155+
setOperationAction({ISD::LROUND, ISD::LLROUND}, VT, Custom);
11541156
setOperationAction({ISD::VP_MERGE, ISD::VP_SELECT, ISD::SELECT}, VT,
11551157
Custom);
11561158
setOperationAction(ISD::SELECT_CC, VT, Expand);
@@ -1453,6 +1455,7 @@ RISCVTargetLowering::RISCVTargetLowering(const TargetMachine &TM,
14531455
setOperationAction({ISD::VP_SINT_TO_FP, ISD::VP_UINT_TO_FP}, VT,
14541456
Custom);
14551457
setOperationAction({ISD::LRINT, ISD::LLRINT}, VT, Custom);
1458+
setOperationAction({ISD::LROUND, ISD::LLROUND}, VT, Custom);
14561459
if (Subtarget.hasStdExtZfhmin()) {
14571460
setOperationAction(ISD::BUILD_VECTOR, VT, Custom);
14581461
} else {
@@ -1478,6 +1481,7 @@ RISCVTargetLowering::RISCVTargetLowering(const TargetMachine &TM,
14781481
setOperationAction(ISD::BITCAST, VT, Custom);
14791482
setOperationAction({ISD::VP_FP_ROUND, ISD::VP_FP_EXTEND}, VT, Custom);
14801483
setOperationAction({ISD::LRINT, ISD::LLRINT}, VT, Custom);
1484+
setOperationAction({ISD::LROUND, ISD::LLROUND}, VT, Custom);
14811485
if (Subtarget.hasStdExtZfbfmin()) {
14821486
setOperationAction(ISD::BUILD_VECTOR, VT, Custom);
14831487
} else {
@@ -1511,7 +1515,8 @@ RISCVTargetLowering::RISCVTargetLowering(const TargetMachine &TM,
15111515

15121516
setOperationAction({ISD::FTRUNC, ISD::FCEIL, ISD::FFLOOR, ISD::FROUND,
15131517
ISD::FROUNDEVEN, ISD::FRINT, ISD::LRINT,
1514-
ISD::LLRINT, ISD::FNEARBYINT},
1518+
ISD::LLRINT, ISD::LROUND, ISD::LLROUND,
1519+
ISD::FNEARBYINT},
15151520
VT, Custom);
15161521

15171522
setCondCodeAction(VFPCCToExpand, VT, Expand);
@@ -3211,7 +3216,11 @@ static RISCVFPRndMode::RoundingMode matchRoundingOp(unsigned Opc) {
32113216
case ISD::VP_FCEIL:
32123217
return RISCVFPRndMode::RUP;
32133218
case ISD::FROUND:
3219+
case ISD::LROUND:
3220+
case ISD::LLROUND:
32143221
case ISD::STRICT_FROUND:
3222+
case ISD::STRICT_LROUND:
3223+
case ISD::STRICT_LLROUND:
32153224
case ISD::VP_FROUND:
32163225
return RISCVFPRndMode::RMM;
32173226
case ISD::FRINT:
@@ -3469,9 +3478,9 @@ lowerFTRUNC_FCEIL_FFLOOR_FROUND(SDValue Op, SelectionDAG &DAG,
34693478
DAG.getTargetConstant(FRM, DL, Subtarget.getXLenVT()));
34703479
}
34713480

3472-
// Expand vector LRINT and LLRINT by converting to the integer domain.
3473-
static SDValue lowerVectorXRINT(SDValue Op, SelectionDAG &DAG,
3474-
const RISCVSubtarget &Subtarget) {
3481+
// Expand vector [L]LRINT and [L]LROUND by converting to the integer domain.
3482+
static SDValue lowerVectorXRINT_XROUND(SDValue Op, SelectionDAG &DAG,
3483+
const RISCVSubtarget &Subtarget) {
34753484
SDLoc DL(Op);
34763485
MVT DstVT = Op.getSimpleValueType();
34773486
SDValue Src = Op.getOperand(0);
@@ -7711,11 +7720,10 @@ SDValue RISCVTargetLowering::LowerOperation(SDValue Op,
77117720
return lowerFTRUNC_FCEIL_FFLOOR_FROUND(Op, DAG, Subtarget);
77127721
case ISD::LRINT:
77137722
case ISD::LLRINT:
7714-
if (Op.getValueType().isVector())
7715-
return lowerVectorXRINT(Op, DAG, Subtarget);
7716-
[[fallthrough]];
77177723
case ISD::LROUND:
77187724
case ISD::LLROUND: {
7725+
if (Op.getValueType().isVector())
7726+
return lowerVectorXRINT_XROUND(Op, DAG, Subtarget);
77197727
assert(Op.getOperand(0).getValueType() == MVT::f16 &&
77207728
"Unexpected custom legalisation");
77217729
SDLoc DL(Op);

0 commit comments

Comments
 (0)