[llvm] [RISCV] Update matchSplatAsGather to use the index of extract_elt if in-bounds (PR #118873)
Philip Reames via llvm-commits
llvm-commits at lists.llvm.org
Wed Jan 15 10:22:35 PST 2025
================
@@ -3517,27 +3517,43 @@ 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()))
+ // Check that we know Idx lies within VT
+ if (auto *CIdx = dyn_cast<ConstantSDNode>(Idx)) {
+ if (CIdx->getZExtValue() >= VT.getVectorElementCount().getKnownMinValue())
+ return SDValue();
+ } else if (!TypeSize::isKnownLE(Vec.getValueSizeInBits(), VT.getSizeInBits()))
----------------
preames wrote:
Please restructure this as:
if (!TypeSize::isKnownLE(Vec.getValueSizeInBits(), VT.getSizeInBits())) {
auto *CIdx = dyn_cast<ConstantSDNode>(Idx);
if (!CIdx || CIdx->getZExtValue() >= VT.getVectorElementCount().getKnownMinValue())
return SDValue();
}
https://github.com/llvm/llvm-project/pull/118873
More information about the llvm-commits
mailing list