@@ -6963,7 +6963,7 @@ static bool hasPassthruOp(unsigned Opcode) {
6963
6963
Opcode <= RISCVISD::LAST_STRICTFP_OPCODE &&
6964
6964
"not a RISC-V target specific op");
6965
6965
static_assert(
6966
- RISCVISD::LAST_VL_VECTOR_OP - RISCVISD::FIRST_VL_VECTOR_OP == 133 &&
6966
+ RISCVISD::LAST_VL_VECTOR_OP - RISCVISD::FIRST_VL_VECTOR_OP == 134 &&
6967
6967
RISCVISD::LAST_STRICTFP_OPCODE - RISCVISD::FIRST_STRICTFP_OPCODE == 21 &&
6968
6968
"adding target specific op should update this function");
6969
6969
if (Opcode >= RISCVISD::ADD_VL && Opcode <= RISCVISD::VFMAX_VL)
@@ -6987,7 +6987,7 @@ static bool hasMaskOp(unsigned Opcode) {
6987
6987
Opcode <= RISCVISD::LAST_STRICTFP_OPCODE &&
6988
6988
"not a RISC-V target specific op");
6989
6989
static_assert(
6990
- RISCVISD::LAST_VL_VECTOR_OP - RISCVISD::FIRST_VL_VECTOR_OP == 133 &&
6990
+ RISCVISD::LAST_VL_VECTOR_OP - RISCVISD::FIRST_VL_VECTOR_OP == 134 &&
6991
6991
RISCVISD::LAST_STRICTFP_OPCODE - RISCVISD::FIRST_STRICTFP_OPCODE == 21 &&
6992
6992
"adding target specific op should update this function");
6993
6993
if (Opcode >= RISCVISD::TRUNCATE_VECTOR_VL && Opcode <= RISCVISD::SETCC_VL)
@@ -9595,6 +9595,13 @@ getSmallestVTForIndex(MVT VecVT, unsigned MaxIdx, SDLoc DL, SelectionDAG &DAG,
9595
9595
return SmallerVT;
9596
9596
}
9597
9597
9598
+ static bool isValidVisniInsertExtractIndex(SDValue Idx) {
9599
+ auto *IdxC = dyn_cast<ConstantSDNode>(Idx);
9600
+ if (!IdxC || isNullConstant(Idx))
9601
+ return false;
9602
+ return isUInt<5>(IdxC->getZExtValue());
9603
+ }
9604
+
9598
9605
// Custom-legalize INSERT_VECTOR_ELT so that the value is inserted into the
9599
9606
// first position of a vector, and that vector is slid up to the insert index.
9600
9607
// By limiting the active vector length to index+1 and merging with the
@@ -9705,6 +9712,23 @@ SDValue RISCVTargetLowering::lowerINSERT_VECTOR_ELT(SDValue Op,
9705
9712
return Vec;
9706
9713
return convertFromScalableVector(VecVT, Vec, DAG, Subtarget);
9707
9714
}
9715
+
9716
+ // Use ri.vinsert.v.x if available.
9717
+ if (Subtarget.hasVendorXRivosVisni() && VecVT.isInteger() &&
9718
+ isValidVisniInsertExtractIndex(Idx)) {
9719
+ // Tail policy applies to elements past VLMAX (by assumption Idx < VLMAX)
9720
+ SDValue PolicyOp =
9721
+ DAG.getTargetConstant(RISCVVType::TAIL_AGNOSTIC, DL, XLenVT);
9722
+ Vec = DAG.getNode(RISCVISD::RI_VINSERT_VL, DL, ContainerVT, Vec, Val, Idx,
9723
+ VL, PolicyOp);
9724
+ if (AlignedIdx)
9725
+ Vec = DAG.getNode(ISD::INSERT_SUBVECTOR, DL, OrigContainerVT, OrigVec,
9726
+ Vec, AlignedIdx);
9727
+ if (!VecVT.isFixedLengthVector())
9728
+ return Vec;
9729
+ return convertFromScalableVector(VecVT, Vec, DAG, Subtarget);
9730
+ }
9731
+
9708
9732
ValInVec = lowerScalarInsert(Val, VL, ContainerVT, DL, DAG, Subtarget);
9709
9733
} else {
9710
9734
// On RV32, i64-element vectors must be specially handled to place the
@@ -9904,6 +9928,14 @@ SDValue RISCVTargetLowering::lowerEXTRACT_VECTOR_ELT(SDValue Op,
9904
9928
}
9905
9929
}
9906
9930
9931
+ // Use ri.vextract.x.v if available.
9932
+ // TODO: Avoid index 0 and just use the vmv.x.s
9933
+ if (Subtarget.hasVendorXRivosVisni() && EltVT.isInteger() &&
9934
+ isValidVisniInsertExtractIndex(Idx)) {
9935
+ SDValue Elt = DAG.getNode(RISCVISD::RI_VEXTRACT, DL, XLenVT, Vec, Idx);
9936
+ return DAG.getNode(ISD::TRUNCATE, DL, EltVT, Elt);
9937
+ }
9938
+
9907
9939
// If after narrowing, the required slide is still greater than LMUL2,
9908
9940
// fallback to generic expansion and go through the stack. This is done
9909
9941
// for a subtle reason: extracting *all* elements out of a vector is
@@ -22321,12 +22353,14 @@ const char *RISCVTargetLowering::getTargetNodeName(unsigned Opcode) const {
22321
22353
NODE_NAME_CASE(VZEXT_VL)
22322
22354
NODE_NAME_CASE(VCPOP_VL)
22323
22355
NODE_NAME_CASE(VFIRST_VL)
22356
+ NODE_NAME_CASE(RI_VINSERT_VL)
22324
22357
NODE_NAME_CASE(RI_VZIPEVEN_VL)
22325
22358
NODE_NAME_CASE(RI_VZIPODD_VL)
22326
22359
NODE_NAME_CASE(RI_VZIP2A_VL)
22327
22360
NODE_NAME_CASE(RI_VZIP2B_VL)
22328
22361
NODE_NAME_CASE(RI_VUNZIP2A_VL)
22329
22362
NODE_NAME_CASE(RI_VUNZIP2B_VL)
22363
+ NODE_NAME_CASE(RI_VEXTRACT)
22330
22364
NODE_NAME_CASE(READ_CSR)
22331
22365
NODE_NAME_CASE(WRITE_CSR)
22332
22366
NODE_NAME_CASE(SWAP_CSR)
0 commit comments