Skip to content
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

Merged
merged 1 commit into from
Nov 4, 2016

Conversation

nagisa
Copy link
Member

@nagisa nagisa commented Sep 6, 2016

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

@@ -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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why does this matter?

Copy link
Member Author

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.

@bors
Copy link
Contributor

bors commented Sep 7, 2016

☔ The latest upstream changes (presumably #36296) made this pull request unmergeable. Please resolve the merge conflicts.

@arielb1
Copy link
Contributor

arielb1 commented Sep 8, 2016

I think we want a pass that also removes written-but-never-used locals.

@eddyb
Copy link
Member

eddyb commented Sep 8, 2016

@arielb1 Isn't that DSE? That would remove the stores, but not the locals themselves.

@nagisa
Copy link
Member Author

nagisa commented Sep 8, 2016

I think we want a pass that also removes written-but-never-used locals.

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.

@bors
Copy link
Contributor

bors commented Sep 29, 2016

☔ The latest upstream changes (presumably #36752) made this pull request unmergeable. Please resolve the merge conflicts.

@alexcrichton
Copy link
Member

ping, what's the next steps on this?

@nagisa
Copy link
Member Author

nagisa commented Nov 1, 2016

Needs a review, I guess?

@alexcrichton
Copy link
Member

In that case, ping @eddyb

@eddyb
Copy link
Member

eddyb commented Nov 1, 2016

r=me (ping me after rebase)

Replaces the hack where a similar thing is done within trans.
@nagisa
Copy link
Member Author

nagisa commented Nov 3, 2016

Rebased.

@eddyb
Copy link
Member

eddyb commented Nov 3, 2016

@bors r+

@bors
Copy link
Contributor

bors commented Nov 3, 2016

📌 Commit 4752367 has been approved by eddyb

@bors
Copy link
Contributor

bors commented Nov 3, 2016

⌛ Testing commit 4752367 with merge 37ace30...

bors added a commit that referenced this pull request Nov 3, 2016
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
Copy link
Contributor

bors commented Nov 3, 2016

💔 Test failed - auto-mac-32-opt

@alexcrichton
Copy link
Member

@bors: retry

@alexcrichton
Copy link
Member

@bors: retry force clean

@bors
Copy link
Contributor

bors commented Nov 3, 2016

⌛ Testing commit 4752367 with merge 1b87855...

bors added a commit that referenced this pull request Nov 3, 2016
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
@alexcrichton
Copy link
Member

@bors: retry force clean

@bors
Copy link
Contributor

bors commented Nov 4, 2016

⌛ Testing commit 4752367 with merge 49c36bf...

bors added a commit that referenced this pull request Nov 4, 2016
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 bors merged commit 4752367 into rust-lang:master Nov 4, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants