Skip to content

Commit

Permalink
[AMDGPU] Fix kernarg preloading crash with some types and alignments (l…
Browse files Browse the repository at this point in the history
…lvm#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.

(cherry picked from commit f652777)
Change-Id: If6acab1cec61482ee4a63d67c9afc7f3d8ec29e3
  • Loading branch information
kerbowa authored and bcahoon committed Jun 5, 2024
1 parent a9c7f77 commit 5f17a5a
Show file tree
Hide file tree
Showing 2 changed files with 1,231 additions and 1,020 deletions.
20 changes: 14 additions & 6 deletions llvm/lib/Target/AMDGPU/SIISelLowering.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2927,12 +2927,20 @@ SDValue SITargetLowering::LowerFormalArguments(
DL, Elts);
}

SDValue CMemVT;
if (VT.isScalarInteger() && VT.bitsLT(NewArg.getSimpleValueType()))
CMemVT = DAG.getNode(ISD::TRUNCATE, DL, MemVT, NewArg);
else
CMemVT = DAG.getBitcast(MemVT, NewArg);
NewArg = convertArgType(DAG, VT, MemVT, DL, CMemVT,
// If the argument was preloaded to multiple consecutive 32-bit
// registers because of misalignment between addressable SGPR tuples
// and the argument size, we can still assume that because of kernarg
// segment alignment restrictions that NewArg's size is the same as
// MemVT and just do a bitcast. If MemVT is less than 32-bits we add a
// truncate since we cannot preload to less than a single SGPR and the
// MemVT may be smaller.
EVT MemVTInt =
EVT::getIntegerVT(*DAG.getContext(), MemVT.getSizeInBits());
if (MemVT.bitsLT(NewArg.getSimpleValueType()))
NewArg = DAG.getNode(ISD::TRUNCATE, DL, MemVTInt, NewArg);

NewArg = DAG.getBitcast(MemVT, NewArg);
NewArg = convertArgType(DAG, VT, MemVT, DL, NewArg,
Ins[i].Flags.isSExt(), &Ins[i]);
NewArg = DAG.getMergeValues({NewArg, Chain}, DL);
}
Expand Down
Loading

0 comments on commit 5f17a5a

Please sign in to comment.