-
Notifications
You must be signed in to change notification settings - Fork 12.7k
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: RVO isn't applied #116541
Comments
Interestingly, the stack no longer overflows when just a few fields are removed: diff --git a/src/lib.rs b/src/lib.rs
index d84519e..3d43db8 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -18,9 +18,6 @@ impl Outer {
pub struct LargeStruct {
d0: Option<Box<u128>>,
d1: Option<Box<u128>>,
- d2: Option<Box<u128>>,
- d3: Option<Box<u128>>,
- d4: Option<Box<u128>>,
huge: [u8; SIZE],
}
@@ -30,9 +27,6 @@ impl LargeStruct {
Self {
d0: None,
d1: None,
- d2: None,
- d3: None,
- d4: None,
huge: [0; SIZE],
}
} |
Both these MIR optimizations are off by default, and the NRVO MIR opt is unsound. |
Interesting, thank you. I was always under the impression that optimizations of the Also, is there a way to turn on these MIR optimizations via a compiler flag/crate attribute? |
Yes, currently LLVM performs the relevant RVO (or doesn't). Alternately, I believe most unsound opts are enabled at |
Unsound optimizations must be enabled by their own flag, It's possible your request here will be fulfilled by #116531. |
Unfortunately, if I did everything correctly, #116531 doesn't help in this case :( I've checked-out #116531 and built
Still overflows. This is the emitted MIR: mir
Also, just in case, I tried perhaps less aggressive
and there were no difference in the emitted MIR |
Did you use |
I thought that wasn't necessary judging by the diff in #116531, but to be sure, I've just tried these two variants:
Unfortunately, same outcome, and the emitted MIR is also the same as before. |
Actually, I think I'm doing something wrong. Just tried comparing this MIR to stable MIR ( |
|
Consider the code below. At the first glace, it looks like RVO/destination propagation isn't applied, resulting in a stack overflow.
File structure
tree .
Code
Cargo.toml
bin/rvo.rs
src/lib.rs
Running
cargo run --release
results in:Compiler version:
rustc --version --verbose
The text was updated successfully, but these errors were encountered: