-
Notifications
You must be signed in to change notification settings - Fork 13.2k
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
Missed optimization when using const-blocks for MaybeUninit arrays #138625
Labels
A-codegen
Area: Code generation
C-bug
Category: This is a bug.
I-slow
Issue: Problems and improvements with respect to performance of generated code.
T-compiler
Relevant to the compiler team, which will review and decide on the PR/issue.
Comments
As with most such examples, you can get the codegen you want with more const: #[unsafe(no_mangle)]
pub fn uninit_arr_via_const() -> SmallVec<String> {
SmallVec { len: 0, arr: const { [const { MaybeUninit::uninit() }; 24] } }
} So it's nice that works, but I'll try to fix this properly. |
I'm not tagging this as LLVM because the bug here is our bug. We are giving the backend a loop for the assignment of |
bors
added a commit
to rust-lang-ci/rust
that referenced
this issue
Mar 18, 2025
Lower to a no-op when Rvalue::Repeat repeats uninit Fixes rust-lang#138625 r? oli-obk
bors
added a commit
to rust-lang-ci/rust
that referenced
this issue
Mar 24, 2025
…,oli-obk Lower to a memset(undef) when Rvalue::Repeat repeats uninit Fixes rust-lang#138625. It is technically correct to just do nothing. But if we actually do nothing, we may miss that this is de-initializing something, so instead we just lower to a single memset that writes undef. This is still superior to the memcpy loop, in both quality of code we hand to the backend and LLVM's final output.
bors
added a commit
to rust-lang-ci/rust
that referenced
this issue
Mar 25, 2025
…,oli-obk Lower to a memset(undef) when Rvalue::Repeat repeats uninit Fixes rust-lang#138625. It is technically correct to just do nothing. But if we actually do nothing, we may miss that this is de-initializing something, so instead we just lower to a single memset that writes undef. This is still superior to the memcpy loop, in both quality of code we hand to the backend and LLVM's final output.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
A-codegen
Area: Code generation
C-bug
Category: This is a bug.
I-slow
Issue: Problems and improvements with respect to performance of generated code.
T-compiler
Relevant to the compiler team, which will review and decide on the PR/issue.
Please see the assembly from these functions (Rust 1.85.0
--release
):The
const {}
variant compiles with code that seems to zero-out thearr
field. This should not be necessary and the other version (correctly) only initializes thelen
field.This is particularly troublesome because the documentation in multiple places expresses that const-blocks are the preferred way to create a
[MaybeUnint; _]
.The text was updated successfully, but these errors were encountered: