-
Notifications
You must be signed in to change notification settings - Fork 13.3k
Lift a few limitations on ConstProp optimization pass #107856
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
Conversation
r? @lcnr (rustbot has picked a reviewer for you, use r? to override) |
Some changes occurred to MIR optimizations cc @rust-lang/wg-mir-opt Some changes occurred to the CTFE / Miri engine cc @rust-lang/miri Some changes occurred to the CTFE / Miri engine cc @rust-lang/miri |
@bors try @rust-timer queue |
This comment has been minimized.
This comment has been minimized.
⌛ Trying commit b27fb59b1c018d8223f4ef35d5ae3eb687a8bbf3 with merge 85e382751271dbc84dc43390b8ce9624f3b96753... |
@@ -601,7 +601,9 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> { | |||
// that the `RevealAll` pass has happened and that the body's consts | |||
// are normalized, so any call to resolve before that needs to be | |||
// manually normalized. | |||
let val = self.tcx.normalize_erasing_regions(self.param_env, *val); | |||
let Ok(val) = self.tcx.try_normalize_erasing_regions(self.param_env, *val) else { | |||
throw_unsup!(Normalization) |
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.
This is more invalid than unsupported I think, just like all the other const-prop-hacks we carry in the interpreter.
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.
throw_inval!(TooGeneric)
may be better suited then.
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.
Ah right, we already have that variant. Agreed.
@@ -356,7 +356,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> { | |||
} | |||
|
|||
_ => { | |||
span_bug!(self.cur_span(), "invalid unsizing {:?} -> {:?}", src.layout.ty, cast_ty) | |||
throw_inval!(Unsize(src.layout.ty, cast_ty)) |
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.
Even more const-prop induced technical debt in the interpreter. :(
How can this one even happen...?
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.
We can have a generic context
fn foo<T: ?Sized, V: std::marker::Unsize<T>>(value: &V) -> &T { value }
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.
Please add a comment explaining that (and that this is only needed for ConstProp).
Why does that not affect the similar bug!
in unsize_into?
I don't think we should make const prop smarter. We should get the dataflow const prop to cover most of the const prop optimizations and then just remove const prop. |
Do we have a solution to DataFlowConstProp's runtime? |
I don't agree with this vision. My suggestion is to have:
Whatever the decision on that discussion, there are 2 changes that I'd like to propose:
I can move them in separate PRs if needed. |
☀️ Try build successful - checks-actions |
This comment has been minimized.
This comment has been minimized.
Finished benchmarking commit (85e382751271dbc84dc43390b8ce9624f3b96753): 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.
|
This comment has been minimized.
This comment has been minimized.
I think that would be great, if it can be done in our perf budget. It means less code to maintain, and fewer issues with ConstProp using the interpreter in ways it was not intended to be used. |
I'll benchmark removing the old pass and enabling the new one so we can make a decision here. Even if we can't split it, we can still change const prop to stop using mir interpreter rvalue processing and instead make it only use the math APIs like the dataflow const prop does |
On the perf report:
|
⌛ Trying commit 2131dae17d267c3c4cb53690cf00cdbc7a2e9de0 with merge 47d13e87e7c1c86fba1429c13a990657fa7a3561... |
☀️ Try build successful - checks-actions |
This comment has been minimized.
This comment has been minimized.
Finished benchmarking commit (47d13e87e7c1c86fba1429c13a990657fa7a3561): 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.
|
This comment has been minimized.
This comment has been minimized.
2131dae
to
d341cd3
Compare
d341cd3
to
9a58168
Compare
@bors try @rust-timer queue |
This comment has been minimized.
This comment has been minimized.
⌛ Trying commit 9a58168 with merge 1cff2133ab3b7724841c768a38ec63160562386a... |
☀️ Try build successful - checks-actions |
This comment has been minimized.
This comment has been minimized.
Finished benchmarking commit (1cff2133ab3b7724841c768a38ec63160562386a): 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.
CyclesThis benchmark run did not return any relevant results for this metric. |
The last perf result confirm there is nothing to gain by extending this pass. |
ConstProp
does not emit lints any more. Therefore, we can extend and simplify it.This PR starts by fortifying the current implementation of
ConstProp
and of the interpreter.In a second part, we enable propagation even if overflow checks are disabled. It's now codegen's responsibility to skip emitting overflow checks.
In a third part, we remove limitation on propagation.
Finally, we only disable the pass for mir-opt-level=1, since it's now purely an optimization pass.