@@ -6963,7 +6963,7 @@ static bool hasPassthruOp(unsigned Opcode) {
69636963 Opcode <= RISCVISD::LAST_STRICTFP_OPCODE &&
69646964 "not a RISC-V target specific op");
69656965 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 &&
69676967 RISCVISD::LAST_STRICTFP_OPCODE - RISCVISD::FIRST_STRICTFP_OPCODE == 21 &&
69686968 "adding target specific op should update this function");
69696969 if (Opcode >= RISCVISD::ADD_VL && Opcode <= RISCVISD::VFMAX_VL)
@@ -6987,7 +6987,7 @@ static bool hasMaskOp(unsigned Opcode) {
69876987 Opcode <= RISCVISD::LAST_STRICTFP_OPCODE &&
69886988 "not a RISC-V target specific op");
69896989 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 &&
69916991 RISCVISD::LAST_STRICTFP_OPCODE - RISCVISD::FIRST_STRICTFP_OPCODE == 21 &&
69926992 "adding target specific op should update this function");
69936993 if (Opcode >= RISCVISD::TRUNCATE_VECTOR_VL && Opcode <= RISCVISD::SETCC_VL)
@@ -9595,6 +9595,13 @@ getSmallestVTForIndex(MVT VecVT, unsigned MaxIdx, SDLoc DL, SelectionDAG &DAG,
95959595 return SmallerVT;
95969596}
95979597
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+
95989605// Custom-legalize INSERT_VECTOR_ELT so that the value is inserted into the
95999606// first position of a vector, and that vector is slid up to the insert index.
96009607// By limiting the active vector length to index+1 and merging with the
@@ -9705,6 +9712,23 @@ SDValue RISCVTargetLowering::lowerINSERT_VECTOR_ELT(SDValue Op,
97059712 return Vec;
97069713 return convertFromScalableVector(VecVT, Vec, DAG, Subtarget);
97079714 }
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+
97089732 ValInVec = lowerScalarInsert(Val, VL, ContainerVT, DL, DAG, Subtarget);
97099733 } else {
97109734 // On RV32, i64-element vectors must be specially handled to place the
@@ -9904,6 +9928,14 @@ SDValue RISCVTargetLowering::lowerEXTRACT_VECTOR_ELT(SDValue Op,
99049928 }
99059929 }
99069930
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+
99079939 // If after narrowing, the required slide is still greater than LMUL2,
99089940 // fallback to generic expansion and go through the stack. This is done
99099941 // for a subtle reason: extracting *all* elements out of a vector is
@@ -22321,12 +22353,14 @@ const char *RISCVTargetLowering::getTargetNodeName(unsigned Opcode) const {
2232122353 NODE_NAME_CASE(VZEXT_VL)
2232222354 NODE_NAME_CASE(VCPOP_VL)
2232322355 NODE_NAME_CASE(VFIRST_VL)
22356+ NODE_NAME_CASE(RI_VINSERT_VL)
2232422357 NODE_NAME_CASE(RI_VZIPEVEN_VL)
2232522358 NODE_NAME_CASE(RI_VZIPODD_VL)
2232622359 NODE_NAME_CASE(RI_VZIP2A_VL)
2232722360 NODE_NAME_CASE(RI_VZIP2B_VL)
2232822361 NODE_NAME_CASE(RI_VUNZIP2A_VL)
2232922362 NODE_NAME_CASE(RI_VUNZIP2B_VL)
22363+ NODE_NAME_CASE(RI_VEXTRACT)
2233022364 NODE_NAME_CASE(READ_CSR)
2233122365 NODE_NAME_CASE(WRITE_CSR)
2233222366 NODE_NAME_CASE(SWAP_CSR)
0 commit comments