You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Herohtar opened this issue
Oct 18, 2021
· 4 comments
Labels
A-LLVMArea: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues.C-bugCategory: This is a bug.I-slowIssue: Problems and improvements with respect to performance of generated code.
Optimization doesn't seem to happen for unused zero-initialized vectors.
If I write a method that initializes a Vec with a non-zero value and call it a couple of times from main(), then when I build with --release (-O3) the compiler optimizes everything away into effectively a no-op:
I tried out a few different rustc versions on Godbolt and it seems the behavior started in 1.18.0 -- before that, the zero-initialized code gets optimized away as well.
The text was updated successfully, but these errors were encountered:
I believe this is because we don't teach LLVM that __rust_alloc_zeroed is an allocator function. Doing so used to cause miscompiles in the past, but that was a very long time ago and we should probably try this again.
nikic
added
A-LLVM
Area: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues.
I-slow
Issue: Problems and improvements with respect to performance of generated code.
labels
Oct 19, 2021
Do you remember anything specific about the miscompiles? I'm knee-deep in that part of LLVM already in an attempt to let us use attributes instead of a static list of functions for allocator function identification anyway...
A-LLVMArea: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues.C-bugCategory: This is a bug.I-slowIssue: Problems and improvements with respect to performance of generated code.
Optimization doesn't seem to happen for unused zero-initialized vectors.
If I write a method that initializes a
Vec
with a non-zero value and call it a couple of times frommain()
, then when I build with--release
(-O3
) the compiler optimizes everything away into effectively a no-op:Code
Output
Godbolt link
However, if I instead initialize it with zero, the result is drastically different:
Code
Output
Godbolt link
Meta
rustc --version --verbose
:I tried out a few different
rustc
versions on Godbolt and it seems the behavior started in1.18.0
-- before that, the zero-initialized code gets optimized away as well.The text was updated successfully, but these errors were encountered: