Skip to content

Commit 901ac60

Browse files
authored
[RISCV] Use ri.vzip2{a,b} for interleave2 if available (#136364)
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 c5a5f43 commit 901ac60

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
@@ -5027,8 +5027,8 @@ static SDValue lowerVZIP(unsigned Opc, SDValue Op0, SDValue Op1,
50275027
const SDLoc &DL, SelectionDAG &DAG,
50285028
const RISCVSubtarget &Subtarget) {
50295029
assert(RISCVISD::RI_VZIPEVEN_VL == Opc || RISCVISD::RI_VZIPODD_VL == Opc ||
5030-
RISCVISD::RI_VZIP2A_VL == Opc || RISCVISD::RI_VUNZIP2A_VL == Opc ||
5031-
RISCVISD::RI_VUNZIP2B_VL == Opc);
5030+
RISCVISD::RI_VZIP2A_VL == Opc || RISCVISD::RI_VZIP2B_VL == Opc ||
5031+
RISCVISD::RI_VUNZIP2A_VL == Opc || RISCVISD::RI_VUNZIP2B_VL == Opc);
50325032
assert(Op0.getSimpleValueType() == Op1.getSimpleValueType());
50335033

50345034
MVT VT = Op0.getSimpleValueType();
@@ -6944,7 +6944,7 @@ static bool hasPassthruOp(unsigned Opcode) {
69446944
Opcode <= RISCVISD::LAST_STRICTFP_OPCODE &&
69456945
"not a RISC-V target specific op");
69466946
static_assert(
6947-
RISCVISD::LAST_VL_VECTOR_OP - RISCVISD::FIRST_VL_VECTOR_OP == 132 &&
6947+
RISCVISD::LAST_VL_VECTOR_OP - RISCVISD::FIRST_VL_VECTOR_OP == 133 &&
69486948
RISCVISD::LAST_STRICTFP_OPCODE - RISCVISD::FIRST_STRICTFP_OPCODE == 21 &&
69496949
"adding target specific op should update this function");
69506950
if (Opcode >= RISCVISD::ADD_VL && Opcode <= RISCVISD::VFMAX_VL)
@@ -6968,7 +6968,7 @@ static bool hasMaskOp(unsigned Opcode) {
69686968
Opcode <= RISCVISD::LAST_STRICTFP_OPCODE &&
69696969
"not a RISC-V target specific op");
69706970
static_assert(
6971-
RISCVISD::LAST_VL_VECTOR_OP - RISCVISD::FIRST_VL_VECTOR_OP == 132 &&
6971+
RISCVISD::LAST_VL_VECTOR_OP - RISCVISD::FIRST_VL_VECTOR_OP == 133 &&
69726972
RISCVISD::LAST_STRICTFP_OPCODE - RISCVISD::FIRST_STRICTFP_OPCODE == 21 &&
69736973
"adding target specific op should update this function");
69746974
if (Opcode >= RISCVISD::TRUNCATE_VECTOR_VL && Opcode <= RISCVISD::SETCC_VL)
@@ -11762,6 +11762,17 @@ SDValue RISCVTargetLowering::lowerVECTOR_INTERLEAVE(SDValue Op,
1176211762
return DAG.getMergeValues(Loads, DL);
1176311763
}
1176411764

11765+
// Use ri.vzip2{a,b} if available
11766+
// TODO: Figure out the best lowering for the spread variants
11767+
if (Subtarget.hasVendorXRivosVizip() && !Op.getOperand(0).isUndef() &&
11768+
!Op.getOperand(1).isUndef()) {
11769+
SDValue V1 = Op->getOperand(0);
11770+
SDValue V2 = Op->getOperand(1);
11771+
SDValue Lo = lowerVZIP(RISCVISD::RI_VZIP2A_VL, V1, V2, DL, DAG, Subtarget);
11772+
SDValue Hi = lowerVZIP(RISCVISD::RI_VZIP2B_VL, V1, V2, DL, DAG, Subtarget);
11773+
return DAG.getMergeValues({Lo, Hi}, DL);
11774+
}
11775+
1176511776
// If the element type is smaller than ELEN, then we can interleave with
1176611777
// vwaddu.vv and vwmaccu.vx
1176711778
if (VecVT.getScalarSizeInBits() < Subtarget.getELen()) {
@@ -22265,6 +22276,7 @@ const char *RISCVTargetLowering::getTargetNodeName(unsigned Opcode) const {
2226522276
NODE_NAME_CASE(RI_VZIPEVEN_VL)
2226622277
NODE_NAME_CASE(RI_VZIPODD_VL)
2226722278
NODE_NAME_CASE(RI_VZIP2A_VL)
22279+
NODE_NAME_CASE(RI_VZIP2B_VL)
2226822280
NODE_NAME_CASE(RI_VUNZIP2A_VL)
2226922281
NODE_NAME_CASE(RI_VUNZIP2B_VL)
2227022282
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)