-
Notifications
You must be signed in to change notification settings - Fork 12.9k
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
Only preserve DebugInfo in DeadStoreElimination if requested. #106852
base: master
Are you sure you want to change the base?
Conversation
Failed to set assignee to
|
Some changes occurred to MIR optimizations cc @rust-lang/wg-mir-opt |
r? wg-mir-opt |
@bors try @rust-timer queue |
This comment has been minimized.
This comment has been minimized.
⌛ Trying commit 7e940fd36a93faafc4f402b0423816942a65fc8c with merge 7dc1f7ab3906a64a8ed85774edd3b3805670f534... |
☀️ Try build successful - checks-actions |
This comment has been minimized.
This comment has been minimized.
Finished benchmarking commit (7dc1f7ab3906a64a8ed85774edd3b3805670f534): 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.
|
analysis.initialize_start_block(body, &mut entry_sets[mir::START_BLOCK]); | ||
} else { | ||
// For backward analyses, initialize blocks that exit MIR. | ||
analysis.initialize_start_block(body, &mut init_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.
Using initialize_start_block
for this feels weird. Can you instead treat locals with debuginfo as being read on return/resume terminators?
Treating locals as being live when the function returns feels like a bit of a weird solution. It will still cause the dead write to be removed in an example like this: x = 5;
x = 10;
dbg!(x); See also #103657 for a different approach.
It does not anymore. If I accidentally left a comment in saying otherwise, feel free to remove it. |
That's a bit of the point. My proposal is to remove all the assignments that are "overwritten" without being read, but stop just before removing all assignments entirely. Effectively, this amounts to only keep the last assignment. The debugger won't see the dead assignments, but will see the final value, and the variable will still exist. I'm tempted to consider this a middle ground between optimization and debuggability. After all, debugging an optimizing build, one's bound to see pink elephants 😄 |
6951a9b
to
a17b591
Compare
Hmm, ok, makes sense. Tbh, I think we should also block this on the same discussion as on the other PR. Once we have the T-compiler design meeting on this topic, we can write up an updated policy on the opt levels and make a decision at that point. Feels more principled than merging either of these PRs before that |
r? @JakobDegen |
☔ The latest upstream changes (presumably #107727) made this pull request unmergeable. Please resolve the merge conflicts. |
This comment has been minimized.
This comment has been minimized.
(I'm going to see if I can finish up this PR) I pushed a rebase because it produced a new test failure, which I've fixed. At least the first part of the test suite looks good locally now? Let's see... |
@cjgillot This now passes CI. But I think you had some lingering concern about some sort of inconsistency? Up above, you said:
But all the mir-opt test output looks good to me; is there some other kind of experiment or test you were doing locally? |
☔ The latest upstream changes (presumably #125912) made this pull request unmergeable. Please resolve the merge conflicts. |
☔ The latest upstream changes (presumably #125910) made this pull request unmergeable. Please resolve the merge conflicts. |
☔ The latest upstream changes (presumably #126605) made this pull request unmergeable. Please resolve the merge conflicts. |
scope 3 { | ||
debug z => const 42_u32; | ||
debug z => _3; |
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 seems strange? Feels like either we should remove the debug
info for this variable or it should have the constant. Having debuginfo pointing to something that's never initialized feels weird at PreCodegen
phase.
(It'd be fine as an intermediate thing, to be removed in a subsequent pass, but seems weird like this.)
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.
Should we maybe DeadStoreElem after SingleUseConsts?
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.
Sure, I pushed a commit that changes the pass order. I'm not sure it's always better, but it fixes this one problem.
This comment has been minimized.
This comment has been minimized.
☔ The latest upstream changes (presumably #127096) made this pull request unmergeable. Please resolve the merge conflicts. |
This comment has been minimized.
This comment has been minimized.
&gvn::GVN, | ||
&simplify::SimplifyLocals::AfterGVN, | ||
&dataflow_const_prop::DataflowConstProp, | ||
&single_use_consts::SingleUseConsts, | ||
&dead_store_elimination::DeadStoreElimination::Initial, |
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.
I'd rather see SingleUseConsts
run multiple times than move DSE.
Having DSE run early is interesting to reduce work and create additional opportunities for GVN.
Furthermore, SingleUseConsts should be cheap enough to run multiple times, doesn't it?
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.
SingleUseConsts
is just O(statements), so should be fine to run multiple times.
Come to think of it, doing it after inlining and before InstSimplify
probably makes sense, as otherwise I don't think that https://github.com/cjgillot/rust/blob/a299aa5df79dd8e5a1405b97ddd7b367b61eecc6/compiler/rustc_mir_transform/src/instsimplify.rs#L121 will realistically find anything to simplify.
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.
🤔 I've tried to apply this concept, and it seems to have fixed a FIXME in the SingleUseConsts test?
This comment has been minimized.
This comment has been minimized.
- _1 = const <T as MyTrait>::ASSOC_BOOL; | ||
- switchInt(move _1) -> [0: bb2, otherwise: bb1]; | ||
+ nop; | ||
+ switchInt(const <T as MyTrait>::ASSOC_BOOL) -> [0: bb2, otherwise: bb1]; | ||
nop; | ||
switchInt(const <T as MyTrait>::ASSOC_BOOL) -> [0: bb2, otherwise: bb1]; |
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.
fix: I think if you're going to run it multiple times you need to make it an enum and manually give each run a different name. Otherwise the tests have nothing to see any more, like here where the diff
file is the diff from the second run where nothing happens because it's the first run that did it, and we do want the diff to actually show a diff in the MIR here.
- debug my_bool => _1; | ||
+ debug my_bool => const <T as MyTrait>::ASSOC_BOOL; | ||
debug my_bool => const <T as MyTrait>::ASSOC_BOOL; |
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.
Ditto here; this test should be showing a change in the debuginfo for the pass.
The job Click to see the possible cause of the failure (guessed by this bot)
|
☔ The latest upstream changes (presumably #128186) made this pull request unmergeable. Please resolve the merge conflicts. |
The current pass may delete assignments to locals that appear in debuginfo, irrespective of the opt-level. This PR attempts to preserve such assignments.
Fixes #103655