Skip to content

Commit 56cb5cb

Browse files
authored
[RISCV] Remove RISCVISD::VNSRL_VL and adjust deinterleave lowering to match (llvm#118391)
Instead of directly lowering to vnsrl_vl and having custom pattern matching for that case, we can just lower to a (legal) shift and truncate, and let generic pattern matching produce the vnsrl. The major motivation for this is that I'm going to reuse this logic to handle e.g. deinterleave4 w/ i8 result. The test changes aren't particularly interesting. They're minor code improvements - I think because we do slightly better with the insert_subvector patterns, but that's mostly irrelevant.
1 parent a6ef0de commit 56cb5cb

File tree

4 files changed

+35
-99
lines changed

4 files changed

+35
-99
lines changed

llvm/lib/Target/RISCV/RISCVISelLowering.cpp

Lines changed: 21 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -4618,51 +4618,31 @@ static int isElementRotate(int &LoSrc, int &HiSrc, ArrayRef<int> Mask) {
46184618
// VT is the type of the vector to return, <[vscale x ]n x ty>
46194619
// Src is the vector to deinterleave of type <[vscale x ]n*2 x ty>
46204620
static SDValue getDeinterleaveViaVNSRL(const SDLoc &DL, MVT VT, SDValue Src,
4621-
bool EvenElts,
4622-
const RISCVSubtarget &Subtarget,
4623-
SelectionDAG &DAG) {
4624-
// The result is a vector of type <m x n x ty>
4625-
MVT ContainerVT = VT;
4626-
// Convert fixed vectors to scalable if needed
4627-
if (ContainerVT.isFixedLengthVector()) {
4628-
assert(Src.getSimpleValueType().isFixedLengthVector());
4629-
ContainerVT = getContainerForFixedLengthVector(DAG, ContainerVT, Subtarget);
4630-
4631-
// The source is a vector of type <m x n*2 x ty> (For the single source
4632-
// case, the high half is undefined)
4633-
MVT SrcContainerVT =
4634-
MVT::getVectorVT(ContainerVT.getVectorElementType(),
4635-
ContainerVT.getVectorElementCount() * 2);
4636-
Src = convertToScalableVector(SrcContainerVT, Src, DAG, Subtarget);
4621+
bool EvenElts, SelectionDAG &DAG) {
4622+
// The result is a vector of type <m x n x ty>. The source is a vector of
4623+
// type <m x n*2 x ty> (For the single source case, the high half is undef)
4624+
if (Src.getValueType() == VT) {
4625+
EVT WideVT = VT.getDoubleNumVectorElementsVT();
4626+
Src = DAG.getNode(ISD::INSERT_SUBVECTOR, DL, WideVT, DAG.getUNDEF(WideVT),
4627+
Src, DAG.getVectorIdxConstant(0, DL));
46374628
}
46384629

4639-
auto [TrueMask, VL] = getDefaultVLOps(VT, ContainerVT, DL, DAG, Subtarget);
4640-
46414630
// Bitcast the source vector from <m x n*2 x ty> -> <m x n x ty*2>
46424631
// This also converts FP to int.
4643-
unsigned EltBits = ContainerVT.getScalarSizeInBits();
4644-
MVT WideSrcContainerVT = MVT::getVectorVT(
4645-
MVT::getIntegerVT(EltBits * 2), ContainerVT.getVectorElementCount());
4646-
Src = DAG.getBitcast(WideSrcContainerVT, Src);
4632+
unsigned EltBits = VT.getScalarSizeInBits();
4633+
MVT WideSrcVT = MVT::getVectorVT(MVT::getIntegerVT(EltBits * 2),
4634+
VT.getVectorElementCount());
4635+
Src = DAG.getBitcast(WideSrcVT, Src);
46474636

4648-
// The integer version of the container type.
4649-
MVT IntContainerVT = ContainerVT.changeVectorElementTypeToInteger();
4637+
MVT IntVT = VT.changeVectorElementTypeToInteger();
46504638

46514639
// If we want even elements, then the shift amount is 0. Otherwise, shift by
46524640
// the original element size.
46534641
unsigned Shift = EvenElts ? 0 : EltBits;
4654-
SDValue SplatShift = DAG.getNode(
4655-
RISCVISD::VMV_V_X_VL, DL, IntContainerVT, DAG.getUNDEF(ContainerVT),
4656-
DAG.getConstant(Shift, DL, Subtarget.getXLenVT()), VL);
4657-
SDValue Res =
4658-
DAG.getNode(RISCVISD::VNSRL_VL, DL, IntContainerVT, Src, SplatShift,
4659-
DAG.getUNDEF(IntContainerVT), TrueMask, VL);
4660-
// Cast back to FP if needed.
4661-
Res = DAG.getBitcast(ContainerVT, Res);
4662-
4663-
if (VT.isFixedLengthVector())
4664-
Res = convertFromScalableVector(VT, Res, DAG, Subtarget);
4665-
return Res;
4642+
SDValue Res = DAG.getNode(ISD::SRL, DL, WideSrcVT, Src,
4643+
DAG.getConstant(Shift, DL, WideSrcVT));
4644+
Res = DAG.getNode(ISD::TRUNCATE, DL, IntVT, Res);
4645+
return DAG.getBitcast(VT, Res);
46664646
}
46674647

46684648
// Lower the following shuffle to vslidedown.
@@ -5356,7 +5336,7 @@ static SDValue lowerVECTOR_SHUFFLE(SDValue Op, SelectionDAG &DAG,
53565336
// vnsrl to deinterleave.
53575337
if (SDValue Src =
53585338
isDeinterleaveShuffle(VT, ContainerVT, V1, V2, Mask, Subtarget))
5359-
return getDeinterleaveViaVNSRL(DL, VT, Src, Mask[0] == 0, Subtarget, DAG);
5339+
return getDeinterleaveViaVNSRL(DL, VT, Src, Mask[0] == 0, DAG);
53605340

53615341
if (SDValue V =
53625342
lowerVECTOR_SHUFFLEAsVSlideup(DL, VT, V1, V2, Mask, Subtarget, DAG))
@@ -6258,7 +6238,7 @@ static bool hasPassthruOp(unsigned Opcode) {
62586238
Opcode <= RISCVISD::LAST_RISCV_STRICTFP_OPCODE &&
62596239
"not a RISC-V target specific op");
62606240
static_assert(RISCVISD::LAST_VL_VECTOR_OP - RISCVISD::FIRST_VL_VECTOR_OP ==
6261-
128 &&
6241+
127 &&
62626242
RISCVISD::LAST_RISCV_STRICTFP_OPCODE -
62636243
ISD::FIRST_TARGET_STRICTFP_OPCODE ==
62646244
21 &&
@@ -6284,7 +6264,7 @@ static bool hasMaskOp(unsigned Opcode) {
62846264
Opcode <= RISCVISD::LAST_RISCV_STRICTFP_OPCODE &&
62856265
"not a RISC-V target specific op");
62866266
static_assert(RISCVISD::LAST_VL_VECTOR_OP - RISCVISD::FIRST_VL_VECTOR_OP ==
6287-
128 &&
6267+
127 &&
62886268
RISCVISD::LAST_RISCV_STRICTFP_OPCODE -
62896269
ISD::FIRST_TARGET_STRICTFP_OPCODE ==
62906270
21 &&
@@ -10763,10 +10743,8 @@ SDValue RISCVTargetLowering::lowerVECTOR_DEINTERLEAVE(SDValue Op,
1076310743
// We can deinterleave through vnsrl.wi if the element type is smaller than
1076410744
// ELEN
1076510745
if (VecVT.getScalarSizeInBits() < Subtarget.getELen()) {
10766-
SDValue Even =
10767-
getDeinterleaveViaVNSRL(DL, VecVT, Concat, true, Subtarget, DAG);
10768-
SDValue Odd =
10769-
getDeinterleaveViaVNSRL(DL, VecVT, Concat, false, Subtarget, DAG);
10746+
SDValue Even = getDeinterleaveViaVNSRL(DL, VecVT, Concat, true, DAG);
10747+
SDValue Odd = getDeinterleaveViaVNSRL(DL, VecVT, Concat, false, DAG);
1077010748
return DAG.getMergeValues({Even, Odd}, DL);
1077110749
}
1077210750

@@ -20494,7 +20472,6 @@ const char *RISCVTargetLowering::getTargetNodeName(unsigned Opcode) const {
2049420472
NODE_NAME_CASE(VWMACC_VL)
2049520473
NODE_NAME_CASE(VWMACCU_VL)
2049620474
NODE_NAME_CASE(VWMACCSU_VL)
20497-
NODE_NAME_CASE(VNSRL_VL)
2049820475
NODE_NAME_CASE(SETCC_VL)
2049920476
NODE_NAME_CASE(VMERGE_VL)
2050020477
NODE_NAME_CASE(VMAND_VL)

llvm/lib/Target/RISCV/RISCVISelLowering.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -369,10 +369,6 @@ enum NodeType : unsigned {
369369
VWMACCU_VL,
370370
VWMACCSU_VL,
371371

372-
// Narrowing logical shift right.
373-
// Operands are (source, shift, passthru, mask, vl)
374-
VNSRL_VL,
375-
376372
// Vector compare producing a mask. Fourth operand is input mask. Fifth
377373
// operand is VL.
378374
SETCC_VL,

llvm/lib/Target/RISCV/RISCVInstrInfoVVLPatterns.td

Lines changed: 0 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -459,17 +459,6 @@ def riscv_vfwmul_vl : SDNode<"RISCVISD::VFWMUL_VL", SDT_RISCVVWFPBinOp_VL, [SDNP
459459
def riscv_vfwadd_vl : SDNode<"RISCVISD::VFWADD_VL", SDT_RISCVVWFPBinOp_VL, [SDNPCommutative]>;
460460
def riscv_vfwsub_vl : SDNode<"RISCVISD::VFWSUB_VL", SDT_RISCVVWFPBinOp_VL, []>;
461461

462-
def SDT_RISCVVNIntBinOp_VL : SDTypeProfile<1, 5, [SDTCisVec<0>, SDTCisInt<0>,
463-
SDTCisInt<1>,
464-
SDTCisSameNumEltsAs<0, 1>,
465-
SDTCisOpSmallerThanOp<0, 1>,
466-
SDTCisSameAs<0, 2>,
467-
SDTCisSameAs<0, 3>,
468-
SDTCisSameNumEltsAs<0, 4>,
469-
SDTCVecEltisVT<4, i1>,
470-
SDTCisVT<5, XLenVT>]>;
471-
def riscv_vnsrl_vl : SDNode<"RISCVISD::VNSRL_VL", SDT_RISCVVNIntBinOp_VL>;
472-
473462
def SDT_RISCVVWIntBinOpW_VL : SDTypeProfile<1, 5, [SDTCisVec<0>, SDTCisInt<0>,
474463
SDTCisSameAs<0, 1>,
475464
SDTCisInt<2>,
@@ -885,29 +874,6 @@ multiclass VPatBinaryWVL_VV_VX_WV_WX<SDPatternOperator vop, SDNode vop_w,
885874
}
886875
}
887876

888-
multiclass VPatBinaryNVL_WV_WX_WI<SDPatternOperator vop, string instruction_name> {
889-
foreach VtiToWti = AllWidenableIntVectors in {
890-
defvar vti = VtiToWti.Vti;
891-
defvar wti = VtiToWti.Wti;
892-
let Predicates = !listconcat(GetVTypePredicates<vti>.Predicates,
893-
GetVTypePredicates<wti>.Predicates) in {
894-
def : VPatBinaryVL_V<vop, instruction_name, "WV",
895-
vti.Vector, wti.Vector, vti.Vector, vti.Mask,
896-
vti.Log2SEW, vti.LMul, vti.RegClass, wti.RegClass,
897-
vti.RegClass>;
898-
def : VPatBinaryVL_XI<vop, instruction_name, "WX",
899-
vti.Vector, wti.Vector, vti.Vector, vti.Mask,
900-
vti.Log2SEW, vti.LMul, vti.RegClass, wti.RegClass,
901-
SplatPat, GPR>;
902-
def : VPatBinaryVL_XI<vop, instruction_name, "WI",
903-
vti.Vector, wti.Vector, vti.Vector, vti.Mask,
904-
vti.Log2SEW, vti.LMul, vti.RegClass, wti.RegClass,
905-
!cast<ComplexPattern>(SplatPat#_#uimm5),
906-
uimm5>;
907-
}
908-
}
909-
}
910-
911877
class VPatBinaryVL_VF<SDPatternOperator vop,
912878
string instruction_name,
913879
ValueType result_type,
@@ -2166,8 +2132,6 @@ defm : VPatNarrowShiftSplatExt_WX<riscv_srl_vl, riscv_zext_vl_oneuse, "PseudoVNS
21662132
defm : VPatNarrowShiftVL_WV<riscv_srl_vl, "PseudoVNSRL">;
21672133
defm : VPatNarrowShiftVL_WV<riscv_sra_vl, "PseudoVNSRA">;
21682134

2169-
defm : VPatBinaryNVL_WV_WX_WI<riscv_vnsrl_vl, "PseudoVNSRL">;
2170-
21712135
foreach vtiTowti = AllWidenableIntVectors in {
21722136
defvar vti = vtiTowti.Vti;
21732137
defvar wti = vtiTowti.Wti;

llvm/test/CodeGen/RISCV/rvv/fixed-vectors-shuffle-changes-length.ll

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -97,41 +97,40 @@ define <4 x i32> @v4i32_v8i32(<8 x i32>) {
9797
define <4 x i32> @v4i32_v16i32(<16 x i32>) {
9898
; RV32-LABEL: v4i32_v16i32:
9999
; RV32: # %bb.0:
100-
; RV32-NEXT: vsetivli zero, 8, e32, m4, ta, ma
101-
; RV32-NEXT: vslidedown.vi v16, v8, 8
102-
; RV32-NEXT: vmv4r.v v20, v8
103100
; RV32-NEXT: vsetivli zero, 8, e16, m1, ta, ma
104-
; RV32-NEXT: vmv.v.i v8, 1
105-
; RV32-NEXT: vmv2r.v v22, v12
106-
; RV32-NEXT: vmv.v.i v10, 6
101+
; RV32-NEXT: vmv.v.i v12, 1
102+
; RV32-NEXT: vmv.v.i v14, 6
107103
; RV32-NEXT: li a0, 32
108104
; RV32-NEXT: vmv.v.i v0, 10
109105
; RV32-NEXT: vsetivli zero, 2, e16, m1, tu, ma
110-
; RV32-NEXT: vslideup.vi v10, v8, 1
106+
; RV32-NEXT: vslideup.vi v14, v12, 1
107+
; RV32-NEXT: vsetivli zero, 8, e32, m2, ta, ma
108+
; RV32-NEXT: vnsrl.wx v12, v8, a0
109+
; RV32-NEXT: vsetivli zero, 8, e32, m4, ta, ma
110+
; RV32-NEXT: vslidedown.vi v8, v8, 8
111111
; RV32-NEXT: vsetivli zero, 8, e32, m2, ta, mu
112-
; RV32-NEXT: vnsrl.wx v8, v20, a0
113-
; RV32-NEXT: vrgatherei16.vv v8, v16, v10, v0.t
112+
; RV32-NEXT: vrgatherei16.vv v12, v8, v14, v0.t
113+
; RV32-NEXT: vmv1r.v v8, v12
114114
; RV32-NEXT: ret
115115
;
116116
; RV64-LABEL: v4i32_v16i32:
117117
; RV64: # %bb.0:
118-
; RV64-NEXT: vsetivli zero, 8, e32, m4, ta, ma
119-
; RV64-NEXT: vslidedown.vi v16, v8, 8
120-
; RV64-NEXT: vmv4r.v v20, v8
121118
; RV64-NEXT: li a0, 32
122-
; RV64-NEXT: vmv2r.v v22, v12
123119
; RV64-NEXT: vsetivli zero, 1, e8, mf8, ta, ma
124120
; RV64-NEXT: vmv.v.i v0, 10
125121
; RV64-NEXT: vsetivli zero, 8, e32, m2, ta, ma
126-
; RV64-NEXT: vnsrl.wx v8, v20, a0
122+
; RV64-NEXT: vnsrl.wx v12, v8, a0
123+
; RV64-NEXT: vsetivli zero, 8, e32, m4, ta, ma
124+
; RV64-NEXT: vslidedown.vi v8, v8, 8
127125
; RV64-NEXT: li a0, 3
128126
; RV64-NEXT: slli a0, a0, 33
129127
; RV64-NEXT: addi a0, a0, 1
130128
; RV64-NEXT: slli a0, a0, 16
131129
; RV64-NEXT: vsetivli zero, 2, e64, m1, ta, ma
132130
; RV64-NEXT: vmv.v.x v10, a0
133131
; RV64-NEXT: vsetivli zero, 8, e32, m2, ta, mu
134-
; RV64-NEXT: vrgatherei16.vv v8, v16, v10, v0.t
132+
; RV64-NEXT: vrgatherei16.vv v12, v8, v10, v0.t
133+
; RV64-NEXT: vmv1r.v v8, v12
135134
; RV64-NEXT: ret
136135
%2 = shufflevector <16 x i32> %0, <16 x i32> poison, <4 x i32> <i32 1, i32 9, i32 5, i32 14>
137136
ret <4 x i32> %2

0 commit comments

Comments
 (0)