-
Notifications
You must be signed in to change notification settings - Fork 37
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
base: main
Are you sure you want to change the base?
Conversation
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.
//value = new llvm::AddrSpaceCastInst(value, type); | ||
//IRBuilder.Insert(value); | ||
value = IRBuilder.CreateAddrSpaceCast(value, type); | ||
} |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
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.