@@ -3517,20 +3517,22 @@ static SDValue matchSplatAsGather(SDValue SplatVal, MVT VT, const SDLoc &DL,
35173517 // different
35183518 // FIXME: Support i1 vectors, maybe by promoting to i8?
35193519 MVT EltTy = VT.getVectorElementType();
3520- if (EltTy == MVT::i1 ||
3521- EltTy != Vec.getSimpleValueType() .getVectorElementType())
3520+ MVT VecVT = Vec.getSimpleValueType();
3521+ if (EltTy == MVT::i1 || EltTy != VecVT .getVectorElementType())
35223522 return SDValue();
35233523 SDValue Idx = SplatVal.getOperand(1);
35243524 // The index must be a legal type.
35253525 if (Idx.getValueType() != Subtarget.getXLenVT())
35263526 return SDValue();
35273527
3528- // Check that Index lies within VT
3529- if (auto *CIdx = dyn_cast<ConstantSDNode>(Idx)) {
3530- if (VT.getVectorElementCount().getKnownMinValue() <= CIdx->getZExtValue())
3528+ // If the search vector is smaller than the vector of elements we are searching for,
3529+ // try to extract the subvector from it
3530+ if (VT.getVectorMinNumElements() < VecVT.getVectorMinNumElements()) {
3531+ if (!(VT.isFixedLengthVector() || VecVT.isScalableVector()))
35313532 return SDValue();
3532- } else if (!TypeSize::isKnownLE(Vec.getValueSizeInBits(), VT.getSizeInBits()))
3533- return SDValue();
3533+ Vec = DAG.getNode(ISD::EXTRACT_SUBVECTOR, DL, VT, Vec,
3534+ DAG.getVectorIdxConstant(0, DL));
3535+ }
35343536
35353537 MVT ContainerVT = VT;
35363538 if (VT.isFixedLengthVector())
0 commit comments