-
Notifications
You must be signed in to change notification settings - Fork 13.3k
rustc_codegen_ssa: use bitcasts instead of type punning for scalar transmutes. #79801
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
Conversation
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.
LGTM. r=me after tests for the ptr special case are added (or found to already exist)
#[no_mangle] | ||
pub unsafe fn byte_to_bool(byte: u8) -> bool { | ||
std::mem::transmute(byte) | ||
} |
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.
Can you add special test around the pointer special case? (ptr->ptr, ptr->int, ...) I don't anticipate this PR breaking it, but it would be good to have it to be sure.
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.
Good point, added ptr->ptr, ptr->int, int->ptr, and included comments with what they might become in the future.
@bors r=nagisa |
📌 Commit 5c1d2ce has been approved by |
⌛ Testing commit 5c1d2ce with merge ed6739a8568aa29b8a1aa17d7af76b8e1859cc47... |
💔 Test failed - checks-actions |
Oops, guess the tests needs @bors r=nagisa |
📌 Commit 718fba9 has been approved by |
☀️ Test successful - checks-actions |
This specifically helps with
f32
<->u32
(from_bits
,to_bits
) in Rust-GPU (rustc_codegen_spirv
), where (AFAIK) we don't yet have enough infrastructure to turn type punning memory accesses into SSA bitcasts.(There may be more instances, but the one I've seen myself is
f32::signum
fromnum-traits
inspecting e.g. the sign bit)Sadly I've had to make an exception for
transmute
s between pointers and non-pointers, as LLVM disallows usingbitcast
for them.r? @nagisa cc @khyperia