Skip to content

Conversation

@RiverDave
Copy link
Collaborator

@RiverDave RiverDave commented Dec 25, 2025

Currently, one gap in AS handling between CIR and OG is the fact that return values are casted to their default stack addresses in some heterogeneous targets like AMDGPU. see:

OG:

define dso_local void @_Z5test4Pi(ptr noundef %a) #0 {
entry:
  %a.addr = alloca ptr, align 8, addrspace(5)
  %a.addr.ascast = addrspacecast ptr addrspace(5) %a.addr to ptr
...

This PR aims for further parity in address space handling for return value allocas on AMDGPU targets (& others..) and updates test patterns to handle alignment attributes in CIR.

  • Modified emitAndUpdateRetAlloca in to use CreateMemTemp instead of emitAlloca, ensuring the return value alloca gets the proper address space cast on AMDGPU (addrspace 5 → flat).

  • Updated stores/loads to __retval to go through ReturnValue (the cast address) instead of FnRetAlloca (raw alloca). This is essentially what OG does, see:

    EmitStoreOfScalar(Ret, MakeAddrLValue(ReturnValue, RV->getType()),
    . Indirectly, this implies that loads and stores now hold alignment information at the CIR level. I adjusted the tests to make them compliant with this.

@RiverDave
Copy link
Collaborator Author

RiverDave commented Dec 25, 2025

Warning

This pull request is not mergeable via GitHub because a downstack PR is open. Once all requirements are satisfied, merge this PR as a stack on Graphite.
Learn more

This stack of pull requests is managed by Graphite. Learn more about stacking.

@RiverDave RiverDave marked this pull request as ready for review December 25, 2025 20:08
@RiverDave RiverDave changed the title [CIR][CIRGen] Handle AS on function return values for heterogeneous languages [CIR][CIRGen] Handle AS on function return allocas for heterogeneous languages Dec 26, 2025
Copy link
Member

@bcardosolopes bcardosolopes left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

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