Skip to content

Commit 59b934b

Browse files
[RISCV] Update matchSplatAsGather to use the index of extract_elt if it is in-bounds
This a follow up to llvm#117878 and allows the usage of vrgather if the index we are accessing in VT is a constant and within bounds. This patch replaces the previous behavior of bailing out if the length of the search vector was greater than the vector of elements we are searching for. Since matchSplatAsGather works on EXTRACT_VECTOR_ELT, and we know the index where the element is being extracted from, we can use safely use vrgather.
1 parent b3ce6dc commit 59b934b

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

llvm/lib/Target/RISCV/RISCVISelLowering.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3526,9 +3526,9 @@ static SDValue matchSplatAsGather(SDValue SplatVal, MVT VT, const SDLoc &DL,
35263526
return SDValue();
35273527

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

35333533
MVT ContainerVT = VT;
35343534
if (VT.isFixedLengthVector())

0 commit comments

Comments
 (0)