-
Notifications
You must be signed in to change notification settings - Fork 13k
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
Fortify and re-enable NRVO MIR opt #116531
Conversation
r? @b-naber (rustbot has picked a reviewer for you, use r? to override) |
Some changes occurred to MIR optimizations cc @rust-lang/wg-mir-opt |
@bors try @rust-timer queue |
This comment has been minimized.
This comment has been minimized.
Fortify and re-enable RNVO MIR opt Fixes rust-lang#111005 Fixes rust-lang#110902 This PR re-enables NRVO opt that had been disabled in rust-lang#111007 To look for RVO opportunities, we walk the MIR backwards from `return` terminators. In addition to the former implementation, we look at all the traversed statements and terminators for writes. If a local is written-to or moved-from, we discard it from the RVO candidates (`assigned_locals` bitset). If we see an indirect write or move, we discard all borrowed locals from candidates. cc `@JakobDegen`
☀️ Try build successful - checks-actions |
1 similar comment
☀️ Try build successful - checks-actions |
This comment has been minimized.
This comment has been minimized.
Finished benchmarking commit (549ef8c): comparison URL. Overall result: ❌✅ regressions and improvements - ACTION NEEDEDBenchmarking this pull request likely means that it is perf-sensitive, so we're automatically marking it as not fit for rolling up. While you can manually mark this PR as fit for rollup, we strongly recommend not doing so since this PR may lead to changes in compiler perf. Next Steps: If you can justify the regressions found in this try perf run, please indicate this with @bors rollup=never Instruction countThis is a highly reliable metric that was used to determine the overall result at the top of this comment.
Max RSS (memory usage)ResultsThis is a less reliable metric that may be of interest but was not used to determine the overall result at the top of this comment.
CyclesResultsThis is a less reliable metric that may be of interest but was not used to determine the overall result at the top of this comment.
Binary sizeResultsThis is a less reliable metric that may be of interest but was not used to determine the overall result at the top of this comment.
Bootstrap: 624.124s -> 624.52s (0.06%) |
Will this ever lead to MIR that takes a reference to the return place? E.g. this fn foo(f: fn(&i16), k: i16) -> i16 {
let mut x = k;
x += 2;
f(&x);
x
} could replace all EDIT: looks like it will |
if let StatementKind::Assign(box (lhs, ref rhs)) = stmt.kind | ||
&& lhs.as_local() == Some(RETURN_PLACE) | ||
&& let Rvalue::Use(rhs) = rhs | ||
&& let Some(rhs) = rhs.place() | ||
&& let Some(rhs) = rhs.as_local() | ||
&& !assigned_locals.contains(rhs) | ||
{ | ||
return Some(rhs); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
#![allow(internal_features, unused_assignments)]
#![feature(custom_mir, core_intrinsics)]
extern crate core;
use core::intrinsics::mir::*;
#[custom_mir(dialect = "runtime", phase = "initial")]
pub fn f() -> u32 {
mir!({
let x = 1;
RET = 2;
RET = x;
Return()
})
}
fn main() {
assert_eq!(f(), 1);
}
$ rustc +stage1 a.rs -Zmir-opt-level=0 && ./a
$ rustc +stage1 a.rs -Zmir-opt-level=0 -Zmir-enable-passes=+RenameReturnPlace && ./a
thread 'main' panicked at a.rs:16:5:
assertion `left == right` failed
left: 2
right: 1
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Indeed, that's even worse. This does not appear solvable without reimplementing DestProp here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The approach seems plausible if limited to a MIR that contains a single occurrence of a return place - as a destination of an assignment.
Should this say NRVO? |
Fixes #111005
Fixes #110902
This PR re-enables NRVO opt that had been disabled in #111007
To look for RVO opportunities, we walk the MIR backwards from
return
terminators. In addition to the former implementation, we look at all the traversed statements and terminators for writes. If a local is written-to or moved-from, we discard it from the RVO candidates (assigned_locals
bitset). If we see an indirect write or move, we discard all borrowed locals from candidates.cc @JakobDegen