Skip to content

Commit 722d589

Browse files
authored
[RISCV] Lower e64 vector_deinterleave via ri.vunzip2{a,b} if available (#136321)
If XRivosVizip is available, the ri.vunzip2a and ri.vunzip2b can be used to the concatenation and register deinterleave shuffle. This patch only effects the intrinsic lowering (and thus scalable vectors because the fixed vectors go through shuffle lowering). Note that this patch is restricted to e64 for staging purposes only. e64 is obviously profitable (i.e. we remove a vcompress). At e32 and below, our alternative is a vnsrl instead, and we need a bit more complexity around lowering with fractional LMUL before the ri.vunzip2a/b versions becomes always profitable. I'll post the followup change once this lands.
1 parent fdcee2d commit 722d589

File tree

4 files changed

+209
-135
lines changed

4 files changed

+209
-135
lines changed

llvm/lib/Target/RISCV/RISCVISelLowering.cpp

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5018,7 +5018,8 @@ static SDValue lowerVZIP(unsigned Opc, SDValue Op0, SDValue Op1,
50185018
const SDLoc &DL, SelectionDAG &DAG,
50195019
const RISCVSubtarget &Subtarget) {
50205020
assert(RISCVISD::RI_VZIPEVEN_VL == Opc || RISCVISD::RI_VZIPODD_VL == Opc ||
5021-
RISCVISD::RI_VZIP2A_VL == Opc);
5021+
RISCVISD::RI_VZIP2A_VL == Opc || RISCVISD::RI_VUNZIP2A_VL == Opc ||
5022+
RISCVISD::RI_VUNZIP2B_VL == Opc);
50225023
assert(Op0.getSimpleValueType() == Op1.getSimpleValueType());
50235024

50245025
MVT VT = Op0.getSimpleValueType();
@@ -6934,7 +6935,7 @@ static bool hasPassthruOp(unsigned Opcode) {
69346935
Opcode <= RISCVISD::LAST_STRICTFP_OPCODE &&
69356936
"not a RISC-V target specific op");
69366937
static_assert(
6937-
RISCVISD::LAST_VL_VECTOR_OP - RISCVISD::FIRST_VL_VECTOR_OP == 130 &&
6938+
RISCVISD::LAST_VL_VECTOR_OP - RISCVISD::FIRST_VL_VECTOR_OP == 132 &&
69386939
RISCVISD::LAST_STRICTFP_OPCODE - RISCVISD::FIRST_STRICTFP_OPCODE == 21 &&
69396940
"adding target specific op should update this function");
69406941
if (Opcode >= RISCVISD::ADD_VL && Opcode <= RISCVISD::VFMAX_VL)
@@ -6958,7 +6959,7 @@ static bool hasMaskOp(unsigned Opcode) {
69586959
Opcode <= RISCVISD::LAST_STRICTFP_OPCODE &&
69596960
"not a RISC-V target specific op");
69606961
static_assert(
6961-
RISCVISD::LAST_VL_VECTOR_OP - RISCVISD::FIRST_VL_VECTOR_OP == 130 &&
6962+
RISCVISD::LAST_VL_VECTOR_OP - RISCVISD::FIRST_VL_VECTOR_OP == 132 &&
69626963
RISCVISD::LAST_STRICTFP_OPCODE - RISCVISD::FIRST_STRICTFP_OPCODE == 21 &&
69636964
"adding target specific op should update this function");
69646965
if (Opcode >= RISCVISD::TRUNCATE_VECTOR_VL && Opcode <= RISCVISD::SETCC_VL)
@@ -11509,6 +11510,19 @@ SDValue RISCVTargetLowering::lowerVECTOR_DEINTERLEAVE(SDValue Op,
1150911510
return DAG.getMergeValues(Res, DL);
1151011511
}
1151111512

11513+
// TODO: Remove the e64 restriction once the fractional LMUL lowering
11514+
// is improved to always beat the vnsrl lowering below.
11515+
if (Subtarget.hasVendorXRivosVizip() && Factor == 2 &&
11516+
VecVT.getVectorElementType().getSizeInBits() == 64) {
11517+
SDValue V1 = Op->getOperand(0);
11518+
SDValue V2 = Op->getOperand(1);
11519+
SDValue Even =
11520+
lowerVZIP(RISCVISD::RI_VUNZIP2A_VL, V1, V2, DL, DAG, Subtarget);
11521+
SDValue Odd =
11522+
lowerVZIP(RISCVISD::RI_VUNZIP2B_VL, V1, V2, DL, DAG, Subtarget);
11523+
return DAG.getMergeValues({Even, Odd}, DL);
11524+
}
11525+
1151211526
SmallVector<SDValue, 8> Ops(Op->op_values());
1151311527

1151411528
// Concatenate the vectors as one vector to deinterleave
@@ -22242,6 +22256,8 @@ const char *RISCVTargetLowering::getTargetNodeName(unsigned Opcode) const {
2224222256
NODE_NAME_CASE(RI_VZIPEVEN_VL)
2224322257
NODE_NAME_CASE(RI_VZIPODD_VL)
2224422258
NODE_NAME_CASE(RI_VZIP2A_VL)
22259+
NODE_NAME_CASE(RI_VUNZIP2A_VL)
22260+
NODE_NAME_CASE(RI_VUNZIP2B_VL)
2224522261
NODE_NAME_CASE(READ_CSR)
2224622262
NODE_NAME_CASE(WRITE_CSR)
2224722263
NODE_NAME_CASE(SWAP_CSR)

llvm/lib/Target/RISCV/RISCVISelLowering.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -408,8 +408,10 @@ enum NodeType : unsigned {
408408
RI_VZIPEVEN_VL,
409409
RI_VZIPODD_VL,
410410
RI_VZIP2A_VL,
411+
RI_VUNZIP2A_VL,
412+
RI_VUNZIP2B_VL,
411413

412-
LAST_VL_VECTOR_OP = RI_VZIP2A_VL,
414+
LAST_VL_VECTOR_OP = RI_VUNZIP2B_VL,
413415

414416
// Read VLENB CSR
415417
READ_VLENB,

llvm/lib/Target/RISCV/RISCVInstrInfoXRivos.td

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,8 @@ defm RI_VUNZIP2B_V : VALU_IV_V<"ri.vunzip2b", 0b011000>;
7171
def ri_vzipeven_vl : SDNode<"RISCVISD::RI_VZIPEVEN_VL", SDT_RISCVIntBinOp_VL>;
7272
def ri_vzipodd_vl : SDNode<"RISCVISD::RI_VZIPODD_VL", SDT_RISCVIntBinOp_VL>;
7373
def ri_vzip2a_vl : SDNode<"RISCVISD::RI_VZIP2A_VL", SDT_RISCVIntBinOp_VL>;
74+
def ri_vunzip2a_vl : SDNode<"RISCVISD::RI_VUNZIP2A_VL", SDT_RISCVIntBinOp_VL>;
75+
def ri_vunzip2b_vl : SDNode<"RISCVISD::RI_VUNZIP2B_VL", SDT_RISCVIntBinOp_VL>;
7476

7577
multiclass RIVPseudoVALU_VV {
7678
foreach m = MxList in
@@ -82,6 +84,8 @@ let Predicates = [HasVendorXRivosVizip],
8284
defm PseudoRI_VZIPEVEN : RIVPseudoVALU_VV;
8385
defm PseudoRI_VZIPODD : RIVPseudoVALU_VV;
8486
defm PseudoRI_VZIP2A : RIVPseudoVALU_VV;
87+
defm PseudoRI_VUNZIP2A : RIVPseudoVALU_VV;
88+
defm PseudoRI_VUNZIP2B : RIVPseudoVALU_VV;
8589
}
8690

8791
multiclass RIVPatBinaryVL_VV<SDPatternOperator vop, string instruction_name,
@@ -98,6 +102,8 @@ multiclass RIVPatBinaryVL_VV<SDPatternOperator vop, string instruction_name,
98102
defm : RIVPatBinaryVL_VV<ri_vzipeven_vl, "PseudoRI_VZIPEVEN">;
99103
defm : RIVPatBinaryVL_VV<ri_vzipodd_vl, "PseudoRI_VZIPODD">;
100104
defm : RIVPatBinaryVL_VV<ri_vzip2a_vl, "PseudoRI_VZIP2A">;
105+
defm : RIVPatBinaryVL_VV<ri_vunzip2a_vl, "PseudoRI_VUNZIP2A">;
106+
defm : RIVPatBinaryVL_VV<ri_vunzip2b_vl, "PseudoRI_VUNZIP2B">;
101107

102108
//===----------------------------------------------------------------------===//
103109
// XRivosVisni

0 commit comments

Comments
 (0)