diff options
author | Craig Topper <craig.topper@sifive.com> | 2025-05-21 15:52:08 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2025-05-21 15:52:08 -0700 |
commit | 60ad6e3fa45c03dc1fc7521ead7583a9a7d9fb61 (patch) | |
tree | 818578003f97bbb9657bf3890fe3290bcb6b6cf9 /llvm/lib | |
parent | b4d2e502e06fb96a124ef4c99668531a4c6abd3d (diff) | |
download | llvm-60ad6e3fa45c03dc1fc7521ead7583a9a7d9fb61.zip llvm-60ad6e3fa45c03dc1fc7521ead7583a9a7d9fb61.tar.gz llvm-60ad6e3fa45c03dc1fc7521ead7583a9a7d9fb61.tar.bz2 |
[SelectionDAG][RISCV] Use VP_LOAD to widen MLOAD in type legalization when possible. (#140595)
Padding the mask using 0 elements doesn't work for scalable vectors. Use
VP_LOAD and change the VL instead.
This fixes crash for Zve32x. Test file was split since i64 isn't a valid
element type for Zve32x.
Fixes #140198.
Diffstat (limited to 'llvm/lib')
-rw-r--r-- | llvm/lib/CodeGen/SelectionDAG/LegalizeVectorTypes.cpp | 29 |
1 files changed, 24 insertions, 5 deletions
diff --git a/llvm/lib/CodeGen/SelectionDAG/LegalizeVectorTypes.cpp b/llvm/lib/CodeGen/SelectionDAG/LegalizeVectorTypes.cpp index 4e9a694..59a9dce 100644 --- a/llvm/lib/CodeGen/SelectionDAG/LegalizeVectorTypes.cpp +++ b/llvm/lib/CodeGen/SelectionDAG/LegalizeVectorTypes.cpp @@ -6111,18 +6111,37 @@ SDValue DAGTypeLegalizer::WidenVecRes_VECTOR_COMPRESS(SDNode *N) { } SDValue DAGTypeLegalizer::WidenVecRes_MLOAD(MaskedLoadSDNode *N) { - - EVT WidenVT = TLI.getTypeToTransformTo(*DAG.getContext(),N->getValueType(0)); + EVT VT = N->getValueType(0); + EVT WidenVT = TLI.getTypeToTransformTo(*DAG.getContext(), VT); SDValue Mask = N->getMask(); EVT MaskVT = Mask.getValueType(); SDValue PassThru = GetWidenedVector(N->getPassThru()); ISD::LoadExtType ExtType = N->getExtensionType(); SDLoc dl(N); + EVT WideMaskVT = + EVT::getVectorVT(*DAG.getContext(), MaskVT.getVectorElementType(), + WidenVT.getVectorElementCount()); + + if (ExtType == ISD::NON_EXTLOAD && + TLI.isOperationLegalOrCustom(ISD::VP_LOAD, WidenVT) && + TLI.isTypeLegal(WideMaskVT)) { + Mask = DAG.getInsertSubvector(dl, DAG.getUNDEF(WideMaskVT), Mask, 0); + SDValue EVL = DAG.getElementCount(dl, TLI.getVPExplicitVectorLengthTy(), + VT.getVectorElementCount()); + SDValue NewLoad = + DAG.getLoadVP(N->getAddressingMode(), ISD::NON_EXTLOAD, WidenVT, dl, + N->getChain(), N->getBasePtr(), N->getOffset(), Mask, EVL, + N->getMemoryVT(), N->getMemOperand()); + + // Modified the chain - switch anything that used the old chain to use + // the new one. + ReplaceValueWith(SDValue(N, 1), NewLoad.getValue(1)); + + return NewLoad; + } + // The mask should be widened as well - EVT WideMaskVT = EVT::getVectorVT(*DAG.getContext(), - MaskVT.getVectorElementType(), - WidenVT.getVectorNumElements()); Mask = ModifyToType(Mask, WideMaskVT, true); SDValue Res = DAG.getMaskedLoad( |