-
Notifications
You must be signed in to change notification settings - Fork 13.7k
Detect and optimize SIMD-like struct #146049
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
base: master
Are you sure you want to change the base?
Conversation
r? @wesleywiser rustbot has assigned @wesleywiser. Use |
The job Click to see the possible cause of the failure (guessed by this bot)
|
Please make the PR description a brief summary of what is fixed, rather than just crosslinking an issue (so we don't need to follow it for context, GH doesn't even link it). Also the commit message only says "Update layout.rs", ideally it should be the same as the description. |
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.
This could really use a regression test to demonstrate that the fix indeed fixes the reported issue
if !matches!(crate_name_str, | ||
"core" | "std" | "alloc" | "proc_macro" | "test" | | ||
"rustc_std_workspace_core" | "rustc_std_workspace_alloc" | | ||
"compiler_builtins" | "libc" | "unwind" | "panic_abort" | | ||
"panic_unwind" | "adler2" | "object" | "memchr" | ||
) { |
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.
Why do these get special treatment?
Name matching specific ecosystem crates to give them special treatment is very hazardous. Occasionally we need to match std crates, for which we have the list at
rust/compiler/rustc_span/src/symbol.rs
Line 2444 in 64a99db
pub const STDLIB_STABLE_CRATES: &[Symbol] = &[sym::std, sym::core, sym::alloc, sym::proc_macro]; |
if let ty::Array(element_ty, array_len) = field_ty.kind() { | ||
if is_simd_friendly_element_type(*element_ty) { | ||
if let Some(len) = extract_const_value(cx, ty, *array_len)? | ||
.try_to_target_usize(tcx) | ||
{ | ||
// Common SIMD sizes: 4, 8, 16 (conservative range) | ||
if matches!(len, 4 | 8 | 16) { |
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.
Use a let
chain to flatten this nesting.
If I am understanding this correctly, it looks like it is changing arrays to SIMD vectors if they match a reasonable size/align? This probably makes sense in some cases, but doing it in layout seems way too early: things like ABI calculation rely on the computed layout, saying we have a SIMD type when we don't is probably going to cause confusion somewhere. Tbh I'm not even certain this is an optimization we should be trying to do on the Rust side or if it's something LLVM has enough information for, what does the IR look like? |
Fixes: #145248