Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DRAFT: Fix for spir-v implicit address space cast #651

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

coldav
Copy link
Collaborator

@coldav coldav commented Jan 21, 2025

Overview

Fix for spir-v implicit address space cast

Reason for change

It is legal for spirv to implicitly cast the address space within the bitcast instruction, but we don't handle this case.

Description of change

This adds a check for this and creates an AddrSpaceCast instruction.

It is legal for spirv to implicitly cast the address space within the
bitcast instruction, but we don't handle this case. This adds a check
for this and creates an AddrSpaceCast instruction.
@coldav coldav changed the title Fix for spir-v implicit address space cast DRAFT: Fix for spir-v implicit address space cast Jan 21, 2025
//value = new llvm::AddrSpaceCastInst(value, type);
//IRBuilder.Insert(value);
value = IRBuilder.CreateAddrSpaceCast(value, type);
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

The effect of a bitcast is supposed to be that of a store to memory as one type, and a load from the same memory as another type. I could be wrong, but I believe in general an addrspacecast is not guaranteed to be bit-pattern-preserving and this could be a wrong translation, unless I am missing a guarantee that we make somewhere that it doesn't matter?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

https://llvm.org/docs/LangRef.html#addrspacecast-to-instruction "(i.e. casting the result back to the original address space should yield the original bit pattern)." - are you sure it's not reasonable to do this? How else would we get the same effect?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Casting the result back may yield the original bit pattern, but in the different address space it may have a different bit pattern. Also from that link: "It can be a no-op cast or a complex value modification, depending on the target and the address space pair." I'm not sure what the best way to translate this is, one possibility is actually doing an alloca to have somewhere to store and load from, another possibility is it may be okay to do ptrtoint and then inttoptr to the other address space, there may yet be more options that I'm not seeing right now.

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.

2 participants