[llvm] [RISCV] Lower unmasked zero-stride vp.stride to a splat of one scalar load. (PR #97394)
Luke Lau via llvm-commits
llvm-commits at lists.llvm.org
Tue Jul 2 01:46:32 PDT 2024
================
@@ -11666,31 +11666,56 @@ SDValue RISCVTargetLowering::lowerVPStridedLoad(SDValue Op,
auto *VPNode = cast<VPStridedLoadSDNode>(Op);
// Check if the mask is known to be all ones
SDValue Mask = VPNode->getMask();
+ SDValue VL = VPNode->getVectorLength();
+ SDValue Stride = VPNode->getStride();
bool IsUnmasked = ISD::isConstantSplatVectorAllOnes(Mask.getNode());
-
- SDValue IntID = DAG.getTargetConstant(IsUnmasked ? Intrinsic::riscv_vlse
- : Intrinsic::riscv_vlse_mask,
- DL, XLenVT);
- SmallVector<SDValue, 8> Ops{VPNode->getChain(), IntID,
- DAG.getUNDEF(ContainerVT), VPNode->getBasePtr(),
- VPNode->getStride()};
- if (!IsUnmasked) {
- if (VT.isFixedLengthVector()) {
- MVT MaskVT = ContainerVT.changeVectorElementType(MVT::i1);
- Mask = convertToScalableVector(MaskVT, Mask, DAG, Subtarget);
+ SDValue Result, Chain;
+
+ // TODO: We restrict this to unmasked loads currently in consideration of
+ // the complexity of handling all falses masks.
+ MVT ScalarVT = ContainerVT.getVectorElementType();
+ if (IsUnmasked && isNullConstant(Stride) && ContainerVT.isInteger() &&
+ !Subtarget.hasOptimizedZeroStrideLoad()) {
+ SDValue ScalarLoad =
+ DAG.getExtLoad(ISD::EXTLOAD, DL, XLenVT, VPNode->getChain(),
+ VPNode->getBasePtr(), ScalarVT, VPNode->getMemOperand());
+ Chain = ScalarLoad.getValue(1);
----------------
lukel97 wrote:
I just noticed this is the same code as how `Intrinsic::riscv_masked_strided_load` is lowered, but I'm wondering in both riscv_masked_strided_load and vp_load should we not be also checking the AVL/EVL is non-zero?
I see the requirement for it being unmasked was [discussed here](https://reviews.llvm.org/D137931) but I can't see the AVL mentioned. Maybe I'm missing something.
https://github.com/llvm/llvm-project/pull/97394
More information about the llvm-commits
mailing list