Skip to content

Commit 80889ae

Browse files
authored
[RISCV] Remove RISCVISD::VSELECT_VL. (#76866)
We can use RISCVISD::VMERGE_VL with an undef passthru operand. I had to rewrite the FMA patterns to handle both undef and non-undef cases so we can get the tail policy.
1 parent 42ec976 commit 80889ae

File tree

3 files changed

+58
-114
lines changed

3 files changed

+58
-114
lines changed

llvm/lib/Target/RISCV/RISCVISelLowering.cpp

Lines changed: 35 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -2811,8 +2811,8 @@ static SDValue lowerFP_TO_INT_SAT(SDValue Op, SelectionDAG &DAG,
28112811
SDValue SplatZero = DAG.getNode(
28122812
RISCVISD::VMV_V_X_VL, DL, DstContainerVT, DAG.getUNDEF(DstContainerVT),
28132813
DAG.getConstant(0, DL, Subtarget.getXLenVT()), VL);
2814-
Res = DAG.getNode(RISCVISD::VSELECT_VL, DL, DstContainerVT, IsNan, SplatZero,
2815-
Res, VL);
2814+
Res = DAG.getNode(RISCVISD::VMERGE_VL, DL, DstContainerVT, IsNan, SplatZero,
2815+
Res, DAG.getUNDEF(DstContainerVT), VL);
28162816

28172817
if (DstVT.isFixedLengthVector())
28182818
Res = convertFromScalableVector(DstVT, Res, DAG, Subtarget);
@@ -5401,17 +5401,17 @@ static SDValue lowerFMAXIMUM_FMINIMUM(SDValue Op, SelectionDAG &DAG,
54015401
SDValue XIsNonNan = DAG.getNode(RISCVISD::SETCC_VL, DL, Mask.getValueType(),
54025402
{X, X, DAG.getCondCode(ISD::SETOEQ),
54035403
DAG.getUNDEF(ContainerVT), Mask, VL});
5404-
NewY =
5405-
DAG.getNode(RISCVISD::VSELECT_VL, DL, ContainerVT, XIsNonNan, Y, X, VL);
5404+
NewY = DAG.getNode(RISCVISD::VMERGE_VL, DL, ContainerVT, XIsNonNan, Y, X,
5405+
DAG.getUNDEF(ContainerVT), VL);
54065406
}
54075407

54085408
SDValue NewX = X;
54095409
if (!YIsNeverNan) {
54105410
SDValue YIsNonNan = DAG.getNode(RISCVISD::SETCC_VL, DL, Mask.getValueType(),
54115411
{Y, Y, DAG.getCondCode(ISD::SETOEQ),
54125412
DAG.getUNDEF(ContainerVT), Mask, VL});
5413-
NewX =
5414-
DAG.getNode(RISCVISD::VSELECT_VL, DL, ContainerVT, YIsNonNan, X, Y, VL);
5413+
NewX = DAG.getNode(RISCVISD::VMERGE_VL, DL, ContainerVT, YIsNonNan, X, Y,
5414+
DAG.getUNDEF(ContainerVT), VL);
54155415
}
54165416

54175417
unsigned Opc =
@@ -5528,7 +5528,6 @@ static unsigned getRISCVVLOp(SDValue Op) {
55285528
return RISCVISD::VMXOR_VL;
55295529
return RISCVISD::XOR_VL;
55305530
case ISD::VP_SELECT:
5531-
return RISCVISD::VSELECT_VL;
55325531
case ISD::VP_MERGE:
55335532
return RISCVISD::VMERGE_VL;
55345533
case ISD::VP_ASHR:
@@ -5563,7 +5562,7 @@ static bool hasMergeOp(unsigned Opcode) {
55635562
Opcode <= RISCVISD::LAST_RISCV_STRICTFP_OPCODE &&
55645563
"not a RISC-V target specific op");
55655564
static_assert(RISCVISD::LAST_VL_VECTOR_OP - RISCVISD::FIRST_VL_VECTOR_OP ==
5566-
125 &&
5565+
124 &&
55675566
RISCVISD::LAST_RISCV_STRICTFP_OPCODE -
55685567
ISD::FIRST_TARGET_STRICTFP_OPCODE ==
55695568
21 &&
@@ -5589,7 +5588,7 @@ static bool hasMaskOp(unsigned Opcode) {
55895588
Opcode <= RISCVISD::LAST_RISCV_STRICTFP_OPCODE &&
55905589
"not a RISC-V target specific op");
55915590
static_assert(RISCVISD::LAST_VL_VECTOR_OP - RISCVISD::FIRST_VL_VECTOR_OP ==
5592-
125 &&
5591+
124 &&
55935592
RISCVISD::LAST_RISCV_STRICTFP_OPCODE -
55945593
ISD::FIRST_TARGET_STRICTFP_OPCODE ==
55955594
21 &&
@@ -7456,8 +7455,9 @@ SDValue RISCVTargetLowering::lowerVectorMaskExt(SDValue Op, SelectionDAG &DAG,
74567455
DAG.getUNDEF(ContainerVT), SplatZero, VL);
74577456
SplatTrueVal = DAG.getNode(RISCVISD::VMV_V_X_VL, DL, ContainerVT,
74587457
DAG.getUNDEF(ContainerVT), SplatTrueVal, VL);
7459-
SDValue Select = DAG.getNode(RISCVISD::VSELECT_VL, DL, ContainerVT, CC,
7460-
SplatTrueVal, SplatZero, VL);
7458+
SDValue Select =
7459+
DAG.getNode(RISCVISD::VMERGE_VL, DL, ContainerVT, CC, SplatTrueVal,
7460+
SplatZero, DAG.getUNDEF(ContainerVT), VL);
74617461

74627462
return convertFromScalableVector(VecVT, Select, DAG, Subtarget);
74637463
}
@@ -8240,8 +8240,8 @@ static SDValue lowerVectorIntrinsicScalars(SDValue Op, SelectionDAG &DAG,
82408240
return Vec;
82418241
// TAMU
82428242
if (Policy == RISCVII::TAIL_AGNOSTIC)
8243-
return DAG.getNode(RISCVISD::VSELECT_VL, DL, VT, Mask, Vec, MaskedOff,
8244-
AVL);
8243+
return DAG.getNode(RISCVISD::VMERGE_VL, DL, VT, Mask, Vec, MaskedOff,
8244+
DAG.getUNDEF(VT), AVL);
82458245
// TUMA or TUMU: Currently we always emit tumu policy regardless of tuma.
82468246
// It's fine because vmerge does not care mask policy.
82478247
return DAG.getNode(RISCVISD::VMERGE_VL, DL, VT, Mask, Vec, MaskedOff,
@@ -8489,8 +8489,8 @@ SDValue RISCVTargetLowering::LowerINTRINSIC_WO_CHAIN(SDValue Op,
84898489
DAG.getNode(RISCVISD::SETCC_VL, DL, MaskVT,
84908490
{VID, SplattedIdx, DAG.getCondCode(ISD::SETEQ),
84918491
DAG.getUNDEF(MaskVT), Mask, VL});
8492-
return DAG.getNode(RISCVISD::VSELECT_VL, DL, VT, SelectCond, SplattedVal,
8493-
Vec, VL);
8492+
return DAG.getNode(RISCVISD::VMERGE_VL, DL, VT, SelectCond, SplattedVal,
8493+
Vec, DAG.getUNDEF(VT), VL);
84948494
}
84958495
// EGS * EEW >= 128 bits
84968496
case Intrinsic::riscv_vaesdf_vv:
@@ -10243,8 +10243,8 @@ SDValue RISCVTargetLowering::lowerFixedLengthVectorSelectToRVV(
1024310243
SDLoc DL(Op);
1024410244
SDValue VL = getDefaultVLOps(VT, ContainerVT, DL, DAG, Subtarget).second;
1024510245

10246-
SDValue Select =
10247-
DAG.getNode(RISCVISD::VSELECT_VL, DL, ContainerVT, CC, Op1, Op2, VL);
10246+
SDValue Select = DAG.getNode(RISCVISD::VMERGE_VL, DL, ContainerVT, CC, Op1,
10247+
Op2, DAG.getUNDEF(ContainerVT), VL);
1024810248

1024910249
return convertFromScalableVector(VT, Select, DAG, Subtarget);
1025010250
}
@@ -10327,9 +10327,14 @@ SDValue RISCVTargetLowering::lowerVPOp(SDValue Op, SelectionDAG &DAG) const {
1032710327
Ops.push_back(DAG.getUNDEF(ContainerVT));
1032810328
} else if (ISD::getVPExplicitVectorLengthIdx(Op.getOpcode()) ==
1032910329
OpIdx.index()) {
10330-
// For VP_MERGE, copy the false operand instead of an undef value.
10331-
assert(Op.getOpcode() == ISD::VP_MERGE);
10332-
Ops.push_back(Ops.back());
10330+
if (Op.getOpcode() == ISD::VP_MERGE) {
10331+
// For VP_MERGE, copy the false operand instead of an undef value.
10332+
Ops.push_back(Ops.back());
10333+
} else {
10334+
assert(Op.getOpcode() == ISD::VP_SELECT);
10335+
// For VP_SELECT, add an undef value.
10336+
Ops.push_back(DAG.getUNDEF(ContainerVT));
10337+
}
1033310338
}
1033410339
}
1033510340
// Pass through operands which aren't fixed-length vectors.
@@ -10379,8 +10384,8 @@ SDValue RISCVTargetLowering::lowerVPExtMaskOp(SDValue Op,
1037910384
SDValue Splat = DAG.getNode(RISCVISD::VMV_V_X_VL, DL, ContainerVT,
1038010385
DAG.getUNDEF(ContainerVT), SplatValue, VL);
1038110386

10382-
SDValue Result = DAG.getNode(RISCVISD::VSELECT_VL, DL, ContainerVT, Src,
10383-
Splat, ZeroSplat, VL);
10387+
SDValue Result = DAG.getNode(RISCVISD::VMERGE_VL, DL, ContainerVT, Src, Splat,
10388+
ZeroSplat, DAG.getUNDEF(ContainerVT), VL);
1038410389
if (!VT.isFixedLengthVector())
1038510390
return Result;
1038610391
return convertFromScalableVector(VT, Result, DAG, Subtarget);
@@ -10508,8 +10513,8 @@ SDValue RISCVTargetLowering::lowerVPFPIntConvOp(SDValue Op,
1050810513
RISCVISDExtOpc == RISCVISD::VZEXT_VL ? 1 : -1, DL, XLenVT);
1050910514
SDValue OneSplat = DAG.getNode(RISCVISD::VMV_V_X_VL, DL, IntVT,
1051010515
DAG.getUNDEF(IntVT), One, VL);
10511-
Src = DAG.getNode(RISCVISD::VSELECT_VL, DL, IntVT, Src, OneSplat,
10512-
ZeroSplat, VL);
10516+
Src = DAG.getNode(RISCVISD::VMERGE_VL, DL, IntVT, Src, OneSplat,
10517+
ZeroSplat, DAG.getUNDEF(IntVT), VL);
1051310518
} else if (DstEltSize > (2 * SrcEltSize)) {
1051410519
// Widen before converting.
1051510520
MVT IntVT = MVT::getVectorVT(MVT::getIntegerVT(DstEltSize / 2),
@@ -10633,17 +10638,17 @@ RISCVTargetLowering::lowerVPSpliceExperimental(SDValue Op,
1063310638
SDValue SplatZeroOp1 = DAG.getNode(RISCVISD::VMV_V_X_VL, DL, ContainerVT,
1063410639
DAG.getUNDEF(ContainerVT),
1063510640
DAG.getConstant(0, DL, XLenVT), EVL1);
10636-
Op1 = DAG.getNode(RISCVISD::VSELECT_VL, DL, ContainerVT, Op1, SplatOneOp1,
10637-
SplatZeroOp1, EVL1);
10641+
Op1 = DAG.getNode(RISCVISD::VMERGE_VL, DL, ContainerVT, Op1, SplatOneOp1,
10642+
SplatZeroOp1, DAG.getUNDEF(ContainerVT), EVL1);
1063810643

1063910644
SDValue SplatOneOp2 = DAG.getNode(RISCVISD::VMV_V_X_VL, DL, ContainerVT,
1064010645
DAG.getUNDEF(ContainerVT),
1064110646
DAG.getConstant(1, DL, XLenVT), EVL2);
1064210647
SDValue SplatZeroOp2 = DAG.getNode(RISCVISD::VMV_V_X_VL, DL, ContainerVT,
1064310648
DAG.getUNDEF(ContainerVT),
1064410649
DAG.getConstant(0, DL, XLenVT), EVL2);
10645-
Op2 = DAG.getNode(RISCVISD::VSELECT_VL, DL, ContainerVT, Op2, SplatOneOp2,
10646-
SplatZeroOp2, EVL2);
10650+
Op2 = DAG.getNode(RISCVISD::VMERGE_VL, DL, ContainerVT, Op2, SplatOneOp2,
10651+
SplatZeroOp2, DAG.getUNDEF(ContainerVT), EVL2);
1064710652
}
1064810653

1064910654
int64_t ImmValue = cast<ConstantSDNode>(Offset)->getSExtValue();
@@ -10713,8 +10718,8 @@ RISCVTargetLowering::lowerVPReverseExperimental(SDValue Op,
1071310718
SDValue SplatZero = DAG.getNode(RISCVISD::VMV_V_X_VL, DL, IndicesVT,
1071410719
DAG.getUNDEF(IndicesVT),
1071510720
DAG.getConstant(0, DL, XLenVT), EVL);
10716-
Op1 = DAG.getNode(RISCVISD::VSELECT_VL, DL, IndicesVT, Op1, SplatOne,
10717-
SplatZero, EVL);
10721+
Op1 = DAG.getNode(RISCVISD::VMERGE_VL, DL, IndicesVT, Op1, SplatOne,
10722+
SplatZero, DAG.getUNDEF(IndicesVT), EVL);
1071810723
}
1071910724

1072010725
unsigned EltSize = GatherVT.getScalarSizeInBits();
@@ -18683,7 +18688,6 @@ const char *RISCVTargetLowering::getTargetNodeName(unsigned Opcode) const {
1868318688
NODE_NAME_CASE(VWMACCSU_VL)
1868418689
NODE_NAME_CASE(VNSRL_VL)
1868518690
NODE_NAME_CASE(SETCC_VL)
18686-
NODE_NAME_CASE(VSELECT_VL)
1868718691
NODE_NAME_CASE(VMERGE_VL)
1868818692
NODE_NAME_CASE(VMAND_VL)
1868918693
NODE_NAME_CASE(VMOR_VL)

llvm/lib/Target/RISCV/RISCVISelLowering.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -330,9 +330,8 @@ enum NodeType : unsigned {
330330
// operand is VL.
331331
SETCC_VL,
332332

333-
// Vector select with an additional VL operand. This operation is unmasked.
334-
VSELECT_VL,
335333
// General vmerge node with mask, true, false, passthru, and vl operands.
334+
// Tail agnostic vselect can be implemented by setting passthru to undef.
336335
VMERGE_VL,
337336

338337
// Mask binary operators.

0 commit comments

Comments
 (0)