-
Notifications
You must be signed in to change notification settings - Fork 209
memset()
/memclr()
emitted for Vec::new()
#305
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
Comments
jordens
added a commit
to quartiq/stabilizer
that referenced
this issue
Jul 24, 2022
jordens
added a commit
to quartiq/stabilizer
that referenced
this issue
Jul 24, 2022
bors bot
added a commit
to quartiq/stabilizer
that referenced
this issue
Jul 25, 2022
566: pounder: tune initialization r=ryan-summers a=jordens rust-embedded/heapless#305 Co-authored-by: Robert Jördens <rj@quartiq.de>
Related: They appear to indicate that this is indeed an issue in LLVM that is likely resolved in LLVM 15. |
Current nightly uses llvm 15 and does not generate the memset/memclrs anymore. |
Closed
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
memclr()
/memset()
calls can be emitted, e.g. ifVec
is contained in another structure (even if its position is last):Godbolt
Complete code to reproduce with a couple variations
Result:
When hunting down a few unexpected and expensive
memclr()
/memset()
I noticed that they are generated forVec::new()
.This is even though
Vec
almost exclusively consists ofMaybeUninit::uninit()
and also specifically tunes its layout so that the only initialized element (the length) is early. The optimization mentioned in the code comment to #290 does appear to be very desirable but also very easy to miss out on.From a cursory search the result is the same for all rust versions between current nightly and 1.56. With 1.55 all four cases receive
memset()
/memclr()
treatment. This is-Copt-level=3 --target=thumbv7em-none-eabihf
. I didn't try other targets or optimization levels.This is probably not a bug in
heapless
, and there may not even be a viable way to improve the situation even from the rust/llvm perspective. But it looks like a surprising data point and was certainly a pitfall in my case.Under what circumstances can the compiler be expected to actually forego the initialization of
MaybeUninit::uninit()
?Or are we using it (
Vec
orMaybeUninit
) wrong?The text was updated successfully, but these errors were encountered: