diff --git a/llvm/lib/Target/RISCV/RISCVISelLowering.cpp b/llvm/lib/Target/RISCV/RISCVISelLowering.cpp index 5d61baae0ce4e..a38352e8e87f2 100644 --- a/llvm/lib/Target/RISCV/RISCVISelLowering.cpp +++ b/llvm/lib/Target/RISCV/RISCVISelLowering.cpp @@ -4998,32 +4998,32 @@ static SDValue lowerVECTOR_SHUFFLE(SDValue Op, SelectionDAG &DAG, MVT MaskVT = MVT::getVectorVT(MVT::i1, NumElts); SDValue SelectMask = DAG.getBuildVector(MaskVT, DL, MaskVals); - unsigned GatherVVOpc = RISCVISD::VRGATHER_VV_VL; - MVT IndexVT = VT.changeTypeToInteger(); - // Since we can't introduce illegal index types at this stage, use i16 and - // vrgatherei16 if the corresponding index type for plain vrgather is greater - // than XLenVT. - if (IndexVT.getScalarType().bitsGT(XLenVT)) { - GatherVVOpc = RISCVISD::VRGATHEREI16_VV_VL; - IndexVT = IndexVT.changeVectorElementType(MVT::i16); - } - - // If the mask allows, we can do all the index computation in 16 bits. This - // requires less work and less register pressure at high LMUL, and creates - // smaller constants which may be cheaper to materialize. - if (IndexVT.getScalarType().bitsGT(MVT::i16) && isUInt<16>(NumElts - 1) && - (IndexVT.getSizeInBits() / Subtarget.getRealMinVLen()) > 1) { - GatherVVOpc = RISCVISD::VRGATHEREI16_VV_VL; - IndexVT = IndexVT.changeVectorElementType(MVT::i16); - } - - MVT IndexContainerVT = - ContainerVT.changeVectorElementType(IndexVT.getScalarType()); - // Base case for the recursion just below - handle the worst case // single source permutation. Note that all the splat variants // are handled above. if (V2.isUndef()) { + unsigned GatherVVOpc = RISCVISD::VRGATHER_VV_VL; + MVT IndexVT = VT.changeTypeToInteger(); + // Since we can't introduce illegal index types at this stage, use i16 and + // vrgatherei16 if the corresponding index type for plain vrgather is greater + // than XLenVT. + if (IndexVT.getScalarType().bitsGT(XLenVT)) { + GatherVVOpc = RISCVISD::VRGATHEREI16_VV_VL; + IndexVT = IndexVT.changeVectorElementType(MVT::i16); + } + + // If the mask allows, we can do all the index computation in 16 bits. This + // requires less work and less register pressure at high LMUL, and creates + // smaller constants which may be cheaper to materialize. + if (IndexVT.getScalarType().bitsGT(MVT::i16) && isUInt<16>(NumElts - 1) && + (IndexVT.getSizeInBits() / Subtarget.getRealMinVLen()) > 1) { + GatherVVOpc = RISCVISD::VRGATHEREI16_VV_VL; + IndexVT = IndexVT.changeVectorElementType(MVT::i16); + } + + MVT IndexContainerVT = + ContainerVT.changeVectorElementType(IndexVT.getScalarType()); + V1 = convertToScalableVector(ContainerVT, V1, DAG, Subtarget); SmallVector GatherIndicesLHS; for (int ShuffleIdx : ShuffleMaskLHS) @@ -5039,7 +5039,7 @@ static SDValue lowerVECTOR_SHUFFLE(SDValue Op, SelectionDAG &DAG, } // Recursively invoke lowering for each operand if we had two - // independent single source permutes, and then combine the result via a + // independent single source shuffles, and then combine the result via a // vselect. Note that the vselect will likely be folded back into the // second permute (vrgather, or other) by the post-isel combine. V1 = DAG.getVectorShuffle(VT, DL, V1, DAG.getUNDEF(VT), ShuffleMaskLHS);