Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 26 additions & 9 deletions llvm/lib/Target/RISCV/RISCVISelLowering.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3522,27 +3522,44 @@ static SDValue matchSplatAsGather(SDValue SplatVal, MVT VT, const SDLoc &DL,
// different
// FIXME: Support i1 vectors, maybe by promoting to i8?
MVT EltTy = VT.getVectorElementType();
if (EltTy == MVT::i1 ||
EltTy != Vec.getSimpleValueType().getVectorElementType())
MVT VecVT = Vec.getSimpleValueType();
if (EltTy == MVT::i1 || EltTy != VecVT.getVectorElementType())
return SDValue();
SDValue Idx = SplatVal.getOperand(1);
// The index must be a legal type.
if (Idx.getValueType() != Subtarget.getXLenVT())
return SDValue();

// Check that Index lies within VT
// TODO: Can we check if the Index is constant and known in-bounds?
if (!TypeSize::isKnownLE(Vec.getValueSizeInBits(), VT.getSizeInBits()))
return SDValue();
// Check that we know Idx lies within VT
if (!TypeSize::isKnownLE(Vec.getValueSizeInBits(), VT.getSizeInBits())) {
auto *CIdx = dyn_cast<ConstantSDNode>(Idx);
if (!CIdx ||
CIdx->getZExtValue() >= VT.getVectorElementCount().getKnownMinValue())
return SDValue();
}

// Convert fixed length vectors to scalable
MVT ContainerVT = VT;
if (VT.isFixedLengthVector())
ContainerVT = getContainerForFixedLengthVector(DAG, VT, Subtarget);

Vec = DAG.getNode(ISD::INSERT_SUBVECTOR, DL, ContainerVT,
DAG.getUNDEF(ContainerVT), Vec,
DAG.getVectorIdxConstant(0, DL));
MVT ContainerVecVT = VecVT;
if (VecVT.isFixedLengthVector()) {
ContainerVecVT = getContainerForFixedLengthVector(DAG, VecVT, Subtarget);
Vec = convertToScalableVector(ContainerVecVT, Vec, DAG, Subtarget);
}

// Put Vec in a VT sized vector
if (ContainerVecVT.getVectorMinNumElements() <
ContainerVT.getVectorMinNumElements())
Vec = DAG.getNode(ISD::INSERT_SUBVECTOR, DL, ContainerVT,
DAG.getUNDEF(ContainerVT), Vec,
DAG.getVectorIdxConstant(0, DL));
else
Vec = DAG.getNode(ISD::EXTRACT_SUBVECTOR, DL, ContainerVT, Vec,
DAG.getVectorIdxConstant(0, DL));

// We checked that Idx fits inside VT earlier
auto [Mask, VL] = getDefaultVLOps(VT, ContainerVT, DL, DAG, Subtarget);

SDValue Gather = DAG.getNode(RISCVISD::VRGATHER_VX_VL, DL, ContainerVT, Vec,
Expand Down
Loading
Loading