-
Notifications
You must be signed in to change notification settings - Fork 12.9k
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
memset not being optimized out when initializing array contents #38613
Comments
If clang has the same issue, it's likely an LLVM bug, not our bug, I'd guess. |
Quite possibly yes, the difference is that everything starts out uninitialized so you wouldn't be running into this case by default. Could MIR omit the check to prevent it from cascading down to the IR level? |
Sounds like it's related to #35662 |
It seems to be present in older versions of Rust too (at least when comparing with rust.godbolt.org). I tried switching to enumerate and that didn't cause the memset to go away. |
Use |
Hi, I don't believe I said I wanted the behaviour of C? I only wanted to clarify that we wouldn't run into this bug as often there because arrays start out uninitialized. I'd prefer the behavior of Rust but without the redundant zero fill. :) |
Is it even a good idea to allocate 4 KB off the stack? And, when allocating off the heap, you can just do |
Triage: Problem remains in Rust 1.72. Ideally this would be fixed by LLVM, but the incentives for LLVM to do so might be weak since this is mostly a problem in safe languages. So to get this fixed a Rust specific MIR optimization pass is probably needed. |
Apologies as there's most likely already a tracking issue for this, but I wasn't able to find it. When initializing an array's contents, it seems that the initial memset is not optimized out:
https://godbolt.org/g/pbgnlq
Clang has the same issue actually, except there memset would have to be called explicitly.
The text was updated successfully, but these errors were encountered: