-
Notifications
You must be signed in to change notification settings - Fork 13k
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
Attempt to improve codegen for arrays of repeated enums #104384
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
// compile-flags: -O | ||
|
||
#![crate_type = "lib"] | ||
|
||
// CHECK-LABEL: @none_repeat | ||
#[no_mangle] | ||
pub fn none_repeat() -> [Option<u8>; 64] { | ||
// CHECK: store <128 x i8> | ||
// CHECK-NEXT: ret void | ||
[None; 64] | ||
} | ||
|
||
// CHECK-LABEL: @some_repeat | ||
#[no_mangle] | ||
pub fn some_repeat() -> [Option<u8>; 64] { | ||
// CHECK: store <128 x i8> | ||
// CHECK-NEXT: ret void | ||
[Some(0); 64] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's interesting to me that Also, out of curiosity, what's the assembly difference before/after this PR? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. godbolt - This is The current assembly output is
With this patch
|
||
} |
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.
No idea if this is better, but you could do it in O(1) LLVM instructions by making a
<2 x _>
(with two insert_elements) and then repeating that one with a shuffle likehttps://llvm.godbolt.org/z/5feKaEo5z