Skip to content

Commit 5fde925

Browse files
committed
[RISCV] Use ri.vzip2{a,b} for interleave2 if available
If XRivosVizip is available, the ri.vzip2a and ri.vzip2b instructions can be used perform a interleave shuffle. This patch only effects the intrinsic lowering (and thus scalable vectors). Fixed vectors go through shuffle lowering and the zip2a (but not zip2b) case is already handled there..
1 parent 722d589 commit 5fde925

File tree

4 files changed

+1085
-289
lines changed

4 files changed

+1085
-289
lines changed

llvm/lib/Target/RISCV/RISCVISelLowering.cpp

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5018,8 +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 || RISCVISD::RI_VUNZIP2A_VL == Opc ||
5022-
RISCVISD::RI_VUNZIP2B_VL == Opc);
5021+
RISCVISD::RI_VZIP2A_VL == Opc || RISCVISD::RI_VZIP2B_VL == Opc ||
5022+
RISCVISD::RI_VUNZIP2A_VL == Opc || RISCVISD::RI_VUNZIP2B_VL == Opc);
50235023
assert(Op0.getSimpleValueType() == Op1.getSimpleValueType());
50245024

50255025
MVT VT = Op0.getSimpleValueType();
@@ -6935,7 +6935,7 @@ static bool hasPassthruOp(unsigned Opcode) {
69356935
Opcode <= RISCVISD::LAST_STRICTFP_OPCODE &&
69366936
"not a RISC-V target specific op");
69376937
static_assert(
6938-
RISCVISD::LAST_VL_VECTOR_OP - RISCVISD::FIRST_VL_VECTOR_OP == 132 &&
6938+
RISCVISD::LAST_VL_VECTOR_OP - RISCVISD::FIRST_VL_VECTOR_OP == 133 &&
69396939
RISCVISD::LAST_STRICTFP_OPCODE - RISCVISD::FIRST_STRICTFP_OPCODE == 21 &&
69406940
"adding target specific op should update this function");
69416941
if (Opcode >= RISCVISD::ADD_VL && Opcode <= RISCVISD::VFMAX_VL)
@@ -6959,7 +6959,7 @@ static bool hasMaskOp(unsigned Opcode) {
69596959
Opcode <= RISCVISD::LAST_STRICTFP_OPCODE &&
69606960
"not a RISC-V target specific op");
69616961
static_assert(
6962-
RISCVISD::LAST_VL_VECTOR_OP - RISCVISD::FIRST_VL_VECTOR_OP == 132 &&
6962+
RISCVISD::LAST_VL_VECTOR_OP - RISCVISD::FIRST_VL_VECTOR_OP == 133 &&
69636963
RISCVISD::LAST_STRICTFP_OPCODE - RISCVISD::FIRST_STRICTFP_OPCODE == 21 &&
69646964
"adding target specific op should update this function");
69656965
if (Opcode >= RISCVISD::TRUNCATE_VECTOR_VL && Opcode <= RISCVISD::SETCC_VL)
@@ -11753,6 +11753,17 @@ SDValue RISCVTargetLowering::lowerVECTOR_INTERLEAVE(SDValue Op,
1175311753
return DAG.getMergeValues(Loads, DL);
1175411754
}
1175511755

11756+
// Use ri.vzip2{a,b} if available
11757+
// TODO: Figure out the best lowering for the spread variants
11758+
if (Subtarget.hasVendorXRivosVizip() &&
11759+
!Op.getOperand(0).isUndef() && !Op.getOperand(1).isUndef()) {
11760+
SDValue V1 = Op->getOperand(0);
11761+
SDValue V2 = Op->getOperand(1);
11762+
SDValue Lo = lowerVZIP(RISCVISD::RI_VZIP2A_VL, V1, V2, DL, DAG, Subtarget);
11763+
SDValue Hi = lowerVZIP(RISCVISD::RI_VZIP2B_VL, V1, V2, DL, DAG, Subtarget);
11764+
return DAG.getMergeValues({Lo, Hi}, DL);
11765+
}
11766+
1175611767
// If the element type is smaller than ELEN, then we can interleave with
1175711768
// vwaddu.vv and vwmaccu.vx
1175811769
if (VecVT.getScalarSizeInBits() < Subtarget.getELen()) {
@@ -22256,6 +22267,7 @@ const char *RISCVTargetLowering::getTargetNodeName(unsigned Opcode) const {
2225622267
NODE_NAME_CASE(RI_VZIPEVEN_VL)
2225722268
NODE_NAME_CASE(RI_VZIPODD_VL)
2225822269
NODE_NAME_CASE(RI_VZIP2A_VL)
22270+
NODE_NAME_CASE(RI_VZIP2B_VL)
2225922271
NODE_NAME_CASE(RI_VUNZIP2A_VL)
2226022272
NODE_NAME_CASE(RI_VUNZIP2B_VL)
2226122273
NODE_NAME_CASE(READ_CSR)

llvm/lib/Target/RISCV/RISCVISelLowering.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -408,6 +408,7 @@ enum NodeType : unsigned {
408408
RI_VZIPEVEN_VL,
409409
RI_VZIPODD_VL,
410410
RI_VZIP2A_VL,
411+
RI_VZIP2B_VL,
411412
RI_VUNZIP2A_VL,
412413
RI_VUNZIP2B_VL,
413414

llvm/lib/Target/RISCV/RISCVInstrInfoXRivos.td

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ 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_vzip2b_vl : SDNode<"RISCVISD::RI_VZIP2B_VL", SDT_RISCVIntBinOp_VL>;
7475
def ri_vunzip2a_vl : SDNode<"RISCVISD::RI_VUNZIP2A_VL", SDT_RISCVIntBinOp_VL>;
7576
def ri_vunzip2b_vl : SDNode<"RISCVISD::RI_VUNZIP2B_VL", SDT_RISCVIntBinOp_VL>;
7677

@@ -84,6 +85,7 @@ let Predicates = [HasVendorXRivosVizip],
8485
defm PseudoRI_VZIPEVEN : RIVPseudoVALU_VV;
8586
defm PseudoRI_VZIPODD : RIVPseudoVALU_VV;
8687
defm PseudoRI_VZIP2A : RIVPseudoVALU_VV;
88+
defm PseudoRI_VZIP2B : RIVPseudoVALU_VV;
8789
defm PseudoRI_VUNZIP2A : RIVPseudoVALU_VV;
8890
defm PseudoRI_VUNZIP2B : RIVPseudoVALU_VV;
8991
}
@@ -102,6 +104,7 @@ multiclass RIVPatBinaryVL_VV<SDPatternOperator vop, string instruction_name,
102104
defm : RIVPatBinaryVL_VV<ri_vzipeven_vl, "PseudoRI_VZIPEVEN">;
103105
defm : RIVPatBinaryVL_VV<ri_vzipodd_vl, "PseudoRI_VZIPODD">;
104106
defm : RIVPatBinaryVL_VV<ri_vzip2a_vl, "PseudoRI_VZIP2A">;
107+
defm : RIVPatBinaryVL_VV<ri_vzip2b_vl, "PseudoRI_VZIP2B">;
105108
defm : RIVPatBinaryVL_VV<ri_vunzip2a_vl, "PseudoRI_VUNZIP2A">;
106109
defm : RIVPatBinaryVL_VV<ri_vunzip2b_vl, "PseudoRI_VUNZIP2B">;
107110

0 commit comments

Comments
 (0)