Skip to content

Commit 1c4abd1

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 f59b600 commit 1c4abd1

File tree

2 files changed

+408
-677
lines changed

2 files changed

+408
-677
lines changed

llvm/lib/Target/RISCV/RISCVISelLowering.cpp

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

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

35163516
MVT ContainerVT = VT;
35173517
if (VT.isFixedLengthVector())

0 commit comments

Comments
 (0)