Skip to content

Commit f652777

Browse files
authored
[AMDGPU] Fix kernarg preloading crash with some types and alignments (#91625)
Lowering of preloded arguments would fail with half/bfloat if they were dword aligned in the kernarg segment and not part of a vector. Added more tests with different alignments and types.
1 parent ebbbc73 commit f652777

File tree

2 files changed

+1231
-1020
lines changed

2 files changed

+1231
-1020
lines changed

llvm/lib/Target/AMDGPU/SIISelLowering.cpp

+14-6
Original file line numberDiff line numberDiff line change
@@ -2976,12 +2976,20 @@ SDValue SITargetLowering::LowerFormalArguments(
29762976
DL, Elts);
29772977
}
29782978

2979-
SDValue CMemVT;
2980-
if (VT.isScalarInteger() && VT.bitsLT(NewArg.getSimpleValueType()))
2981-
CMemVT = DAG.getNode(ISD::TRUNCATE, DL, MemVT, NewArg);
2982-
else
2983-
CMemVT = DAG.getBitcast(MemVT, NewArg);
2984-
NewArg = convertArgType(DAG, VT, MemVT, DL, CMemVT,
2979+
// If the argument was preloaded to multiple consecutive 32-bit
2980+
// registers because of misalignment between addressable SGPR tuples
2981+
// and the argument size, we can still assume that because of kernarg
2982+
// segment alignment restrictions that NewArg's size is the same as
2983+
// MemVT and just do a bitcast. If MemVT is less than 32-bits we add a
2984+
// truncate since we cannot preload to less than a single SGPR and the
2985+
// MemVT may be smaller.
2986+
EVT MemVTInt =
2987+
EVT::getIntegerVT(*DAG.getContext(), MemVT.getSizeInBits());
2988+
if (MemVT.bitsLT(NewArg.getSimpleValueType()))
2989+
NewArg = DAG.getNode(ISD::TRUNCATE, DL, MemVTInt, NewArg);
2990+
2991+
NewArg = DAG.getBitcast(MemVT, NewArg);
2992+
NewArg = convertArgType(DAG, VT, MemVT, DL, NewArg,
29852993
Ins[i].Flags.isSExt(), &Ins[i]);
29862994
NewArg = DAG.getMergeValues({NewArg, Chain}, DL);
29872995
}

0 commit comments

Comments
 (0)