-
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
A way to remove otherwise unused locals from MIR #36306
Conversation
@@ -18,14 +18,14 @@ | |||
#[rustc_mir] // FIXME #27840 MIR has different codegen. | |||
pub fn test() { | |||
let a = 0; | |||
&a; // keep variable in an alloca | |||
drop(&a); // keep variable in an alloca |
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.
Why does this matter?
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.
Got cherry-picked from the dataflow commit. Doesn’t matter here, will remove.
10f1b2c
to
08c2d29
Compare
☔ The latest upstream changes (presumably #36296) made this pull request unmergeable. Please resolve the merge conflicts. |
I think we want a pass that also removes written-but-never-used locals. |
@arielb1 Isn't that DSE? That would remove the stores, but not the locals themselves. |
08c2d29
to
e4a52ac
Compare
Yes, that’s dead store/dead code elimination (yes, we certainly want one). It would work well together with this pass in a sense that dead store/dead code pass wouldn’t need to bother with remapping the locals or removing the declarations; that’s something this pass would do for it later. This pass is still useful without DSE/DCE because we happen to generate (and remove some uses in subsequent passes) variables which end up not being used. |
☔ The latest upstream changes (presumably #36752) made this pull request unmergeable. Please resolve the merge conflicts. |
ping, what's the next steps on this? |
Needs a review, I guess? |
In that case, ping @eddyb |
r=me (ping me after rebase) |
Replaces the hack where a similar thing is done within trans.
e4a52ac
to
4752367
Compare
Rebased. |
@bors r+ |
📌 Commit 4752367 has been approved by |
A way to remove otherwise unused locals from MIR There is a certain amount of desire for a pass which cleans up the provably unused variables (no assignments or reads). There has been an implementation of such pass by @scottcarr, and another (two!) implementations by me in my own dataflow efforts. PR like #35916 proves that this pass is useful even on its own, which is why I cherry-picked it out from my dataflow effort. @nikomatsakis previously expressed concerns over this pass not seeming to be very cheap to run and therefore unsuitable for regular cleanup duties. Turns out, regular cleanup of local declarations is not at all necessary, at least now, because majority of passes simply do not (or should not) care about them. That’s why it is viable to only run this pass once (perhaps a few more times in the future?) per function, right before translation. r? @eddyb or @nikomatsakis
💔 Test failed - auto-mac-32-opt |
@bors: retry |
@bors: retry force clean |
A way to remove otherwise unused locals from MIR There is a certain amount of desire for a pass which cleans up the provably unused variables (no assignments or reads). There has been an implementation of such pass by @scottcarr, and another (two!) implementations by me in my own dataflow efforts. PR like #35916 proves that this pass is useful even on its own, which is why I cherry-picked it out from my dataflow effort. @nikomatsakis previously expressed concerns over this pass not seeming to be very cheap to run and therefore unsuitable for regular cleanup duties. Turns out, regular cleanup of local declarations is not at all necessary, at least now, because majority of passes simply do not (or should not) care about them. That’s why it is viable to only run this pass once (perhaps a few more times in the future?) per function, right before translation. r? @eddyb or @nikomatsakis
@bors: retry force clean |
A way to remove otherwise unused locals from MIR There is a certain amount of desire for a pass which cleans up the provably unused variables (no assignments or reads). There has been an implementation of such pass by @scottcarr, and another (two!) implementations by me in my own dataflow efforts. PR like #35916 proves that this pass is useful even on its own, which is why I cherry-picked it out from my dataflow effort. @nikomatsakis previously expressed concerns over this pass not seeming to be very cheap to run and therefore unsuitable for regular cleanup duties. Turns out, regular cleanup of local declarations is not at all necessary, at least now, because majority of passes simply do not (or should not) care about them. That’s why it is viable to only run this pass once (perhaps a few more times in the future?) per function, right before translation. r? @eddyb or @nikomatsakis
There is a certain amount of desire for a pass which cleans up the provably unused variables (no assignments or reads). There has been an implementation of such pass by @scottcarr, and another (two!) implementations by me in my own dataflow efforts.
PR like #35916 proves that this pass is useful even on its own, which is why I cherry-picked it out from my dataflow effort.
@nikomatsakis previously expressed concerns over this pass not seeming to be very cheap to run and therefore unsuitable for regular cleanup duties. Turns out, regular cleanup of local declarations is not at all necessary, at least now, because majority of passes simply do not (or should not) care about them. That’s why it is viable to only run this pass once (perhaps a few more times in the future?) per function, right before translation.
r? @eddyb or @nikomatsakis