[llvm] AMDGPU: Fix using illegal extract_subvector indexes (PR #154098)
Pierre van Houtryve via llvm-commits
llvm-commits at lists.llvm.org
Mon Aug 18 05:04:19 PDT 2025
================
@@ -1802,15 +1802,35 @@ std::pair<SDValue, SDValue>
AMDGPUTargetLowering::splitVector(const SDValue &N, const SDLoc &DL,
const EVT &LoVT, const EVT &HiVT,
SelectionDAG &DAG) const {
+ EVT VT = N.getValueType();
assert(LoVT.getVectorNumElements() +
(HiVT.isVector() ? HiVT.getVectorNumElements() : 1) <=
- N.getValueType().getVectorNumElements() &&
+ VT.getVectorNumElements() &&
"More vector elements requested than available!");
SDValue Lo = DAG.getNode(ISD::EXTRACT_SUBVECTOR, DL, LoVT, N,
DAG.getVectorIdxConstant(0, DL));
- SDValue Hi = DAG.getNode(
- HiVT.isVector() ? ISD::EXTRACT_SUBVECTOR : ISD::EXTRACT_VECTOR_ELT, DL,
- HiVT, N, DAG.getVectorIdxConstant(LoVT.getVectorNumElements(), DL));
+
+ unsigned LoNumElts = LoVT.getVectorNumElements();
+
+ if (HiVT.isVector()) {
+ unsigned HiNumElts = HiVT.getVectorNumElements();
+ if ((VT.getVectorNumElements() % HiNumElts) == 0) {
+ // Avoid creating an extract_subvector with an index that isn't a multiple
+ // of the result type.
+ SDValue Hi = DAG.getNode(ISD::EXTRACT_SUBVECTOR, DL, HiVT, N,
+ DAG.getConstant(LoNumElts, DL, MVT::i32));
+ return {Lo, Hi};
+ }
+
+ SmallVector<SDValue, 8> Elts;
+ DAG.ExtractVectorElements(N, Elts, /*Start=*/LoNumElts,
+ /*Count=*/HiNumElts);
+ SDValue Hi = DAG.getBuildVector(HiVT, DL, Elts);
+ return {Lo, Hi};
+ }
+
+ SDValue Hi = DAG.getNode(ISD::EXTRACT_VECTOR_ELT, DL, HiVT, N,
+ DAG.getVectorIdxConstant(LoNumElts, DL));
return std::pair(Lo, Hi);
----------------
Pierre-vh wrote:
Change this to match the style used by the other 2 returns
https://github.com/llvm/llvm-project/pull/154098
More information about the llvm-commits
mailing list