Skip to content

Commit 2349fb0

Browse files
committed
[RISCV] Remove RISCVISD::SPLAT_VECTOR_I64 in favor of RISCVISD::VMV_V_X_VL.
SPLAT_VECTOR_I64 has the same semantics as RISCVISD::VMV_V_X_VL, it just assumed VLMax instead of carrying a VL operand. Include order of RISCVInstrInfoVSDPatterns.td and RISCVInstrInfoVVLPatterns.td has been swapped to avoid moving riscv_vmv_v_x_vl into RISCVInstrInfoVSDPatterns.td and to allow moving other "_vl" SDNodes back to RISCVInstrInfoVVLPatterns.td Reviewed By: frasercrmck Differential Revision: https://reviews.llvm.org/D118841
1 parent bad0301 commit 2349fb0

File tree

6 files changed

+42
-45
lines changed

6 files changed

+42
-45
lines changed

llvm/lib/Target/RISCV/RISCVISelDAGToDAG.cpp

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1885,7 +1885,6 @@ bool RISCVDAGToDAGISel::selectVLOp(SDValue N, SDValue &VL) {
18851885

18861886
bool RISCVDAGToDAGISel::selectVSplat(SDValue N, SDValue &SplatVal) {
18871887
if (N.getOpcode() != ISD::SPLAT_VECTOR &&
1888-
N.getOpcode() != RISCVISD::SPLAT_VECTOR_I64 &&
18891888
N.getOpcode() != RISCVISD::VMV_V_X_VL)
18901889
return false;
18911890
SplatVal = N.getOperand(0);
@@ -1899,18 +1898,17 @@ static bool selectVSplatSimmHelper(SDValue N, SDValue &SplatVal,
18991898
const RISCVSubtarget &Subtarget,
19001899
ValidateFn ValidateImm) {
19011900
if ((N.getOpcode() != ISD::SPLAT_VECTOR &&
1902-
N.getOpcode() != RISCVISD::SPLAT_VECTOR_I64 &&
19031901
N.getOpcode() != RISCVISD::VMV_V_X_VL) ||
19041902
!isa<ConstantSDNode>(N.getOperand(0)))
19051903
return false;
19061904

19071905
int64_t SplatImm = cast<ConstantSDNode>(N.getOperand(0))->getSExtValue();
19081906

1909-
// ISD::SPLAT_VECTOR, RISCVISD::SPLAT_VECTOR_I64 and RISCVISD::VMV_V_X_VL
1910-
// share semantics when the operand type is wider than the resulting vector
1911-
// element type: an implicit truncation first takes place. Therefore, perform
1912-
// a manual truncation/sign-extension in order to ignore any truncated bits
1913-
// and catch any zero-extended immediate.
1907+
// ISD::SPLAT_VECTOR, RISCVISD::VMV_V_X_VL share semantics when the operand
1908+
// type is wider than the resulting vector element type: an implicit
1909+
// truncation first takes place. Therefore, perform a manual
1910+
// truncation/sign-extension in order to ignore any truncated bits and catch
1911+
// any zero-extended immediate.
19141912
// For example, we wish to match (i8 -1) -> (XLenVT 255) as a simm5 by first
19151913
// sign-extending to (XLenVT -1).
19161914
MVT XLenVT = Subtarget.getXLenVT();
@@ -1948,7 +1946,6 @@ bool RISCVDAGToDAGISel::selectVSplatSimm5Plus1NonZero(SDValue N,
19481946

19491947
bool RISCVDAGToDAGISel::selectVSplatUimm5(SDValue N, SDValue &SplatVal) {
19501948
if ((N.getOpcode() != ISD::SPLAT_VECTOR &&
1951-
N.getOpcode() != RISCVISD::SPLAT_VECTOR_I64 &&
19521949
N.getOpcode() != RISCVISD::VMV_V_X_VL) ||
19531950
!isa<ConstantSDNode>(N.getOperand(0)))
19541951
return false;

llvm/lib/Target/RISCV/RISCVISelLowering.cpp

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4025,7 +4025,7 @@ SDValue RISCVTargetLowering::lowerVectorMaskSplat(SDValue Op,
40254025
// Custom-lower a SPLAT_VECTOR_PARTS where XLEN<SEW, as the SEW element type is
40264026
// illegal (currently only vXi64 RV32).
40274027
// FIXME: We could also catch non-constant sign-extended i32 values and lower
4028-
// them to SPLAT_VECTOR_I64
4028+
// them to VMV_V_X_VL.
40294029
SDValue RISCVTargetLowering::lowerSPLAT_VECTOR_PARTS(SDValue Op,
40304030
SelectionDAG &DAG) const {
40314031
SDLoc DL(Op);
@@ -4054,14 +4054,18 @@ SDValue RISCVTargetLowering::lowerSPLAT_VECTOR_PARTS(SDValue Op,
40544054
// If Hi constant is all the same sign bit as Lo, lower this as a custom
40554055
// node in order to try and match RVV vector/scalar instructions.
40564056
if ((LoC >> 31) == HiC)
4057-
return DAG.getNode(RISCVISD::SPLAT_VECTOR_I64, DL, VecVT, Lo);
4057+
return DAG.getNode(
4058+
RISCVISD::VMV_V_X_VL, DL, VecVT, Lo,
4059+
DAG.getTargetConstant(RISCV::VLMaxSentinel, DL, MVT::i32));
40584060
}
40594061

40604062
// Detect cases where Hi is (SRA Lo, 31) which means Hi is Lo sign extended.
40614063
if (Hi.getOpcode() == ISD::SRA && Hi.getOperand(0) == Lo &&
40624064
isa<ConstantSDNode>(Hi.getOperand(1)) &&
40634065
Hi.getConstantOperandVal(1) == 31)
4064-
return DAG.getNode(RISCVISD::SPLAT_VECTOR_I64, DL, VecVT, Lo);
4066+
return DAG.getNode(
4067+
RISCVISD::VMV_V_X_VL, DL, VecVT, Lo,
4068+
DAG.getTargetConstant(RISCV::VLMaxSentinel, DL, MVT::i32));
40654069

40664070
// Fall back to use a stack store and stride x0 vector load. Use X0 as VL.
40674071
return DAG.getNode(RISCVISD::SPLAT_VECTOR_SPLIT_I64_VL, DL, VecVT, Lo, Hi,
@@ -4089,17 +4093,20 @@ SDValue RISCVTargetLowering::lowerVectorMaskExt(SDValue Op, SelectionDAG &DAG,
40894093
// Be careful not to introduce illegal scalar types at this stage, and be
40904094
// careful also about splatting constants as on RV32, vXi64 SPLAT_VECTOR is
40914095
// illegal and must be expanded. Since we know that the constants are
4092-
// sign-extended 32-bit values, we use SPLAT_VECTOR_I64 directly.
4096+
// sign-extended 32-bit values, we use VMV_V_X_VL directly.
40934097
bool IsRV32E64 =
40944098
!Subtarget.is64Bit() && VecVT.getVectorElementType() == MVT::i64;
40954099

40964100
if (!IsRV32E64) {
40974101
SplatZero = DAG.getSplatVector(VecVT, DL, SplatZero);
40984102
SplatTrueVal = DAG.getSplatVector(VecVT, DL, SplatTrueVal);
40994103
} else {
4100-
SplatZero = DAG.getNode(RISCVISD::SPLAT_VECTOR_I64, DL, VecVT, SplatZero);
4104+
SplatZero =
4105+
DAG.getNode(RISCVISD::VMV_V_X_VL, DL, VecVT, SplatZero,
4106+
DAG.getTargetConstant(RISCV::VLMaxSentinel, DL, XLenVT));
41014107
SplatTrueVal =
4102-
DAG.getNode(RISCVISD::SPLAT_VECTOR_I64, DL, VecVT, SplatTrueVal);
4108+
DAG.getNode(RISCVISD::VMV_V_X_VL, DL, VecVT, SplatTrueVal,
4109+
DAG.getTargetConstant(RISCV::VLMaxSentinel, DL, XLenVT));
41034110
}
41044111

41054112
return DAG.getNode(ISD::VSELECT, DL, VecVT, Src, SplatTrueVal, SplatZero);
@@ -5416,7 +5423,9 @@ SDValue RISCVTargetLowering::lowerVECTOR_REVERSE(SDValue Op,
54165423
if (!IsRV32E64)
54175424
SplatVL = DAG.getSplatVector(IntVT, DL, VLMinus1);
54185425
else
5419-
SplatVL = DAG.getNode(RISCVISD::SPLAT_VECTOR_I64, DL, IntVT, VLMinus1);
5426+
SplatVL =
5427+
DAG.getNode(RISCVISD::VMV_V_X_VL, DL, IntVT, VLMinus1,
5428+
DAG.getTargetConstant(RISCV::VLMaxSentinel, DL, XLenVT));
54205429

54215430
SDValue VID = DAG.getNode(RISCVISD::VID_VL, DL, IntVT, Mask, VL);
54225431
SDValue Indices =
@@ -8134,8 +8143,9 @@ SDValue RISCVTargetLowering::PerformDAGCombine(SDNode *N,
81348143
// We don't need the upper 32 bits of a 64-bit element for a shift amount.
81358144
SDLoc DL(N);
81368145
EVT VT = N->getValueType(0);
8137-
ShAmt =
8138-
DAG.getNode(RISCVISD::SPLAT_VECTOR_I64, DL, VT, ShAmt.getOperand(0));
8146+
ShAmt = DAG.getNode(RISCVISD::VMV_V_X_VL, DL, VT, ShAmt.getOperand(0),
8147+
DAG.getTargetConstant(RISCV::VLMaxSentinel, DL,
8148+
Subtarget.getXLenVT()));
81398149
return DAG.getNode(N->getOpcode(), DL, VT, N->getOperand(0), ShAmt);
81408150
}
81418151
break;
@@ -10290,7 +10300,6 @@ const char *RISCVTargetLowering::getTargetNodeName(unsigned Opcode) const {
1029010300
NODE_NAME_CASE(VMV_X_S)
1029110301
NODE_NAME_CASE(VMV_S_X_VL)
1029210302
NODE_NAME_CASE(VFMV_S_F_VL)
10293-
NODE_NAME_CASE(SPLAT_VECTOR_I64)
1029410303
NODE_NAME_CASE(SPLAT_VECTOR_SPLIT_I64_VL)
1029510304
NODE_NAME_CASE(READ_VLENB)
1029610305
NODE_NAME_CASE(TRUNCATE_VECTOR_VL)

llvm/lib/Target/RISCV/RISCVISelLowering.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -141,9 +141,6 @@ enum NodeType : unsigned {
141141
VMV_S_X_VL,
142142
// VFMV_S_F_VL matches the semantics of vfmv.s.f. It carries a VL operand.
143143
VFMV_S_F_VL,
144-
// Splats an i64 scalar to a vector type (with element type i64) where the
145-
// scalar is a sign-extended i32.
146-
SPLAT_VECTOR_I64,
147144
// Splats an 64-bit value that has been split into two i32 parts. This is
148145
// expanded late to two scalar stores and a stride 0 vector load.
149146
SPLAT_VECTOR_SPLIT_I64_VL,

llvm/lib/Target/RISCV/RISCVInstrInfoVPseudos.td

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5097,5 +5097,5 @@ let Predicates = [HasVInstructionsAnyF] in {
50975097
} // Predicates = [HasVInstructionsAnyF]
50985098

50995099
// Include the non-intrinsic ISel patterns
5100-
include "RISCVInstrInfoVSDPatterns.td"
51015100
include "RISCVInstrInfoVVLPatterns.td"
5101+
include "RISCVInstrInfoVSDPatterns.td"

llvm/lib/Target/RISCV/RISCVInstrInfoVSDPatterns.td

Lines changed: 1 addition & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -22,31 +22,9 @@
2222
// Helpers to define the SDNode patterns.
2323
//===----------------------------------------------------------------------===//
2424

25-
def SDTSplatI64 : SDTypeProfile<1, 1, [
26-
SDTCVecEltisVT<0, i64>, SDTCisVT<1, i32>
27-
]>;
28-
29-
def rv32_splat_i64 : SDNode<"RISCVISD::SPLAT_VECTOR_I64", SDTSplatI64>;
30-
31-
def SDT_RISCVVMSETCLR_VL : SDTypeProfile<1, 1, [SDTCVecEltisVT<0, i1>,
32-
SDTCisVT<1, XLenVT>]>;
33-
def riscv_vmclr_vl : SDNode<"RISCVISD::VMCLR_VL", SDT_RISCVVMSETCLR_VL>;
34-
def riscv_vmset_vl : SDNode<"RISCVISD::VMSET_VL", SDT_RISCVVMSETCLR_VL>;
35-
3625
def rvv_vnot : PatFrag<(ops node:$in),
3726
(xor node:$in, (riscv_vmset_vl (XLenVT srcvalue)))>;
3827

39-
// Give explicit Complexity to prefer simm5/uimm5.
40-
def SplatPat : ComplexPattern<vAny, 1, "selectVSplat", [splat_vector, rv32_splat_i64], [], 1>;
41-
def SplatPat_simm5 : ComplexPattern<vAny, 1, "selectVSplatSimm5", [splat_vector, rv32_splat_i64], [], 2>;
42-
def SplatPat_uimm5 : ComplexPattern<vAny, 1, "selectVSplatUimm5", [splat_vector, rv32_splat_i64], [], 2>;
43-
def SplatPat_simm5_plus1
44-
: ComplexPattern<vAny, 1, "selectVSplatSimm5Plus1",
45-
[splat_vector, rv32_splat_i64], [], 2>;
46-
def SplatPat_simm5_plus1_nonzero
47-
: ComplexPattern<vAny, 1, "selectVSplatSimm5Plus1NonZero",
48-
[splat_vector, rv32_splat_i64], [], 2>;
49-
5028
class SwapHelper<dag Prefix, dag A, dag B, dag Suffix, bit swap> {
5129
dag Value = !con(Prefix, !if(swap, B, A), !if(swap, A, B), Suffix);
5230
}
@@ -526,7 +504,7 @@ foreach vti = AllIntegerVectors in {
526504
}
527505
foreach vti = [VI64M1, VI64M2, VI64M4, VI64M8] in {
528506
def : Pat<(shl (vti.Vector vti.RegClass:$rs1),
529-
(vti.Vector (rv32_splat_i64 (XLenVT 1)))),
507+
(vti.Vector (riscv_vmv_v_x_vl 1, (XLenVT srcvalue)))),
530508
(!cast<Instruction>("PseudoVADD_VV_"# vti.LMul.MX)
531509
vti.RegClass:$rs1, vti.RegClass:$rs1, vti.AVL, vti.Log2SEW)>;
532510

llvm/lib/Target/RISCV/RISCVInstrInfoVVLPatterns.td

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,11 @@ def SDT_RISCVSelect_VL : SDTypeProfile<1, 4, [
185185
def riscv_vselect_vl : SDNode<"RISCVISD::VSELECT_VL", SDT_RISCVSelect_VL>;
186186
def riscv_vp_merge_vl : SDNode<"RISCVISD::VP_MERGE_VL", SDT_RISCVSelect_VL>;
187187

188+
def SDT_RISCVVMSETCLR_VL : SDTypeProfile<1, 1, [SDTCVecEltisVT<0, i1>,
189+
SDTCisVT<1, XLenVT>]>;
190+
def riscv_vmclr_vl : SDNode<"RISCVISD::VMCLR_VL", SDT_RISCVVMSETCLR_VL>;
191+
def riscv_vmset_vl : SDNode<"RISCVISD::VMSET_VL", SDT_RISCVVMSETCLR_VL>;
192+
188193
def SDT_RISCVMaskBinOp_VL : SDTypeProfile<1, 3, [SDTCisSameAs<0, 1>,
189194
SDTCisSameAs<0, 2>,
190195
SDTCVecEltisVT<0, i1>,
@@ -273,6 +278,17 @@ foreach kind = ["ADD", "UMAX", "SMAX", "UMIN", "SMIN", "AND", "OR", "XOR",
273278
"FADD", "SEQ_FADD", "FMIN", "FMAX"] in
274279
def rvv_vecreduce_#kind#_vl : SDNode<"RISCVISD::VECREDUCE_"#kind#"_VL", SDTRVVVecReduce>;
275280

281+
// Give explicit Complexity to prefer simm5/uimm5.
282+
def SplatPat : ComplexPattern<vAny, 1, "selectVSplat", [splat_vector], [], 1>;
283+
def SplatPat_simm5 : ComplexPattern<vAny, 1, "selectVSplatSimm5", [splat_vector], [], 2>;
284+
def SplatPat_uimm5 : ComplexPattern<vAny, 1, "selectVSplatUimm5", [splat_vector], [], 2>;
285+
def SplatPat_simm5_plus1
286+
: ComplexPattern<vAny, 1, "selectVSplatSimm5Plus1",
287+
[splat_vector], [], 2>;
288+
def SplatPat_simm5_plus1_nonzero
289+
: ComplexPattern<vAny, 1, "selectVSplatSimm5Plus1NonZero",
290+
[splat_vector], [], 2>;
291+
276292
// Ignore the vl operand.
277293
def SplatFPOp : PatFrag<(ops node:$op),
278294
(riscv_vfmv_v_f_vl node:$op, srcvalue)>;

0 commit comments

Comments
 (0)