Skip to content

Fix return type and argument types for AMD intrinsics - #246

Merged
idubinov merged 6 commits into
ROCm:amd-stagingfrom
idubinov:idu/blas
Jul 27, 2026
Merged

Fix return type and argument types for AMD intrinsics#246
idubinov merged 6 commits into
ROCm:amd-stagingfrom
idubinov:idu/blas

Conversation

@idubinov

@idubinov idubinov commented Jul 10, 2026

Copy link
Copy Markdown
Contributor

Recover AMDGCN intrinsic pointer address spaces from LLVM's intrinsic tables

Some AMDGCN intrinsics declare pointer operands/results in a specific address space — e.g. llvm.amdgcn.dispatch.ptr returns addrspace(4) (Constant). SPIR-V encodes pointers by storage class, so on a round-trip the reader reconstructs these as Generic, mismatching the intrinsic's declared type. The result is invalid IR (e.g. a ret ptr against a ptr addrspace(4) signature), which downstream crashes the COMGR JIT at first kernel launch.

This recovers the canonical (non-overloaded) function type from LLVM's intrinsic tables (generated from IntrinsicsAMDGPU.td) and uses it to re-tag both the return type and the parameters. Deriving the address spaces from the tables — instead of hardcoding intrinsic names or a fixed Constant AS — keeps the affected set of intrinsics tracking LLVM automatically and replaces the previous per-name special cases.

@idubinov
idubinov marked this pull request as draft July 10, 2026 16:00
@idubinov
idubinov marked this pull request as ready for review July 10, 2026 16:19
@idubinov idubinov changed the title Fix return type Fix return type for AMD intrinsics Jul 10, 2026
@lamb-j

lamb-j commented Jul 13, 2026

Copy link
Copy Markdown
Collaborator

Both failing checks unrelated to this PR, and are WIP to fix

@idubinov

Copy link
Copy Markdown
Contributor Author

also discussed in #186

@idubinov idubinov changed the title Fix return type for AMD intrinsics Fix return type and argument types for AMD intrinsics Jul 14, 2026
@idubinov
idubinov requested review from AlexVlx and jmmartinez July 14, 2026 12:46
Comment thread lib/SPIRV/SPIRVWriter.cpp
@idubinov

Copy link
Copy Markdown
Contributor Author

@MrSidims , @AlexVlx , @lamb-j , @jmmartinez

@idubinov
idubinov merged commit 294838c into ROCm:amd-staging Jul 27, 2026
8 checks passed
idubinov added a commit that referenced this pull request Aug 10, 2026
Covers the reader-side counterpart of #246: a non-overloaded AMDGCN
intrinsic that returns a pointer in the constant address space
(llvm.amdgcn.implicitarg.ptr, ptr addrspace(4)) must be reconstructed from
its canonical intrinsic declaration on reverse translation.

The intrinsic is imported as an external function whose pointer return uses
the Function storage class (addrspace(0)). Without the fix the reader
rebuilds the declaration from that SPIR-V function type, dropping
addrspace(4) and producing verifier-invalid IR; the test fails in that
case.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants