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

[mir-opt] Run SimplifyLocals to a fixedpoint and handle most rvalues #70755

Merged

Conversation

wesleywiser
Copy link
Member

@wesleywiser wesleywiser commented Apr 4, 2020

Follow up to review feedback left on #70595.

@wesleywiser wesleywiser force-pushed the simplify_locals_2_electric_boogaloo branch from 461ad1c to cefaf31 Compare April 4, 2020 01:36
@wesleywiser
Copy link
Member Author

@bors try @rust-timer queue

@rust-timer
Copy link
Collaborator

Awaiting bors try build completion

@bors
Copy link
Contributor

bors commented Apr 4, 2020

⌛ Trying commit cefaf31138badbd10cf3d694825d73554d85f258 with merge 20c1dc4b3d1fa2dbc25cc761763c903d4e05fe43...

Comment on lines 54 to 55
+ StorageDead(_6); // bb2[2]: scope 0 at $DIR/simplify-locals-fixedpoint.rs:8:5: 8:6
+ goto -> bb3; // bb2[3]: scope 0 at $DIR/simplify-locals-fixedpoint.rs:4:5: 8:6
Copy link
Member

Choose a reason for hiding this comment

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

@oli-obk We really gotta stop printing the statement numbers if a test doesn't have NLL annotations which need them.

(speaking of which, are there NLL tests that are not in src/test/mir-opt, but still test MIR somehow?)

Comment on lines 63 to 64
StorageDead(_1); // bb4[0]: scope 0 at $DIR/simplify-locals-fixedpoint.rs:9:1: 9:2
return; // bb4[1]: scope 0 at $DIR/simplify-locals-fixedpoint.rs:9:2: 9:2
Copy link
Member

Choose a reason for hiding this comment

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

Hmm, just staring at this: could we normalize $DIR/test-name.rs to $FILE?
It would cause a big src/test/ui diff overall but it might be worth it.

@eddyb
Copy link
Member

eddyb commented Apr 4, 2020

@wesleywiser I think there's some confusion going on. You shouldn't need to remap variables in a loop, so I suspect the remapping visitor also does something that should be a separate visitor.

You should re-run the marking and the Nop-ing visitor in a loop, until you stop Nop-ing statements.
Once that's over, only then do you remap.

@bors
Copy link
Contributor

bors commented Apr 4, 2020

☀️ Try build successful - checks-azure
Build commit: 20c1dc4b3d1fa2dbc25cc761763c903d4e05fe43 (20c1dc4b3d1fa2dbc25cc761763c903d4e05fe43)

@rust-timer
Copy link
Collaborator

Queued 20c1dc4b3d1fa2dbc25cc761763c903d4e05fe43 with parent 74bd074, future comparison URL.

@rust-timer
Copy link
Collaborator

Finished benchmarking try commit 20c1dc4b3d1fa2dbc25cc761763c903d4e05fe43, comparison URL.

@eddyb
Copy link
Member

eddyb commented Apr 4, 2020

@wesleywiser Just realized that if you could the number of "uses" (or "mentions", basically a refcount) of a local you don't even need to redo most of the work, you just remove the uses a statement was providing when you Nop.
Just need to make a "for each use of a local in this statement" abstraction.

Might even be possible to track the Locations of statements defining a local that we could remove, and use that instead of scanning the MIR every time (in the pathological case you could have a long chain e.g. of ((((x+1)+1)+1)+1)... which some macros might emit!).

Are we reinventing some other pass here? Even if we are, this might be better.

src/librustc_mir/transform/simplify.rs Outdated Show resolved Hide resolved
}
let can_skip = match rvalue {
Rvalue::Use(op) if can_skip_operand(op) => true,
Rvalue::Discriminant(_) => true,
Copy link
Member

Choose a reason for hiding this comment

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

Should this use !place.is_indirect()?

Copy link
Member Author

Choose a reason for hiding this comment

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

I think eliminating a read of an indirect place's discriminant is ok in the same way removing a read of its address is. Is there a situation you're thinking of where that wouldn't be true?

@@ -0,0 +1,15 @@
// compile-flags: -Zmir-opt-level=1
Copy link
Member

Choose a reason for hiding this comment

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

This is the default, right?

Copy link
Member Author

Choose a reason for hiding this comment

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

It is for regular rustc invocations but for mir-opt tests, -Zmir-opt-level=2 is the default.

@wesleywiser wesleywiser force-pushed the simplify_locals_2_electric_boogaloo branch 3 times, most recently from b78a452 to 5614a95 Compare April 13, 2020 12:12
@wesleywiser
Copy link
Member Author

@bors try @rust-timer queue

@rust-timer
Copy link
Collaborator

Awaiting bors try build completion

@bors
Copy link
Contributor

bors commented Apr 13, 2020

⌛ Trying commit 5614a9593b5c48bfec465194f1111fa3b0a50fa3 with merge 7b53333c513bab2e3ecb26802629bcca3d21fc9f...

@bors
Copy link
Contributor

bors commented Apr 13, 2020

☀️ Try build successful - checks-azure
Build commit: 7b53333c513bab2e3ecb26802629bcca3d21fc9f (7b53333c513bab2e3ecb26802629bcca3d21fc9f)

@rust-timer
Copy link
Collaborator

Queued 7b53333c513bab2e3ecb26802629bcca3d21fc9f with parent d28a464, future comparison URL.

@wesleywiser wesleywiser force-pushed the simplify_locals_2_electric_boogaloo branch from 16f53a4 to feea95a Compare April 14, 2020 01:40
@rust-highfive

This comment has been minimized.

@wesleywiser wesleywiser force-pushed the simplify_locals_2_electric_boogaloo branch from feea95a to c6747b3 Compare April 14, 2020 22:29
@wesleywiser
Copy link
Member Author

@bors try @rust-timer queue

@rust-timer
Copy link
Collaborator

Awaiting bors try build completion

@bors
Copy link
Contributor

bors commented Apr 15, 2020

⌛ Trying commit c6747b327b899177f80afea60c59756155171b9c with merge 9a9cd24b22d0bf53056b7852d4e43323eab1940e...

@bors
Copy link
Contributor

bors commented Apr 15, 2020

☀️ Try build successful - checks-azure
Build commit: 9a9cd24b22d0bf53056b7852d4e43323eab1940e (9a9cd24b22d0bf53056b7852d4e43323eab1940e)

@rust-timer
Copy link
Collaborator

Queued 9a9cd24b22d0bf53056b7852d4e43323eab1940e with parent d12f030, future comparison URL.

@wesleywiser wesleywiser force-pushed the simplify_locals_2_electric_boogaloo branch from c6747b3 to da8f3bb Compare April 15, 2020 18:59
@wesleywiser wesleywiser changed the title [wip] Run SimplifyLocals to a fixedpoint and handle most rvalues [mir-opt] Run SimplifyLocals to a fixedpoint and handle most rvalues Apr 15, 2020
@wesleywiser
Copy link
Member Author

r? @oli-obk

- Remove reads of indirect `Place`s
- Add comments explaining what the algorithm does
@oli-obk
Copy link
Contributor

oli-obk commented Apr 16, 2020

@bors r+

@bors
Copy link
Contributor

bors commented Apr 16, 2020

📌 Commit 9666d31 has been approved by oli-obk

@bors bors added the S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. label Apr 16, 2020
@wesleywiser
Copy link
Member Author

@bors rollup=never

This is perf impacting.

@bors
Copy link
Contributor

bors commented Apr 16, 2020

⌛ Testing commit 9666d31 with merge 7fb5187...

@bors
Copy link
Contributor

bors commented Apr 16, 2020

☀️ Test successful - checks-azure
Approved by: oli-obk
Pushing 7fb5187 to master...

@bors bors added the merged-by-bors This PR was explicitly merged by bors. label Apr 16, 2020
@bors bors merged commit 7fb5187 into rust-lang:master Apr 16, 2020
@eddyb
Copy link
Member

eddyb commented Apr 18, 2020

Post-merged perf results are interesting, the effect on ctfe-stress-4 is similar, everything else doesn't seem to match, and I'm not sure exactly why.

EDIT: syn-opt in the original run is noise, but I missed this interesting bit:
script-servo-debug remained a regression (both times on "patched incremental: debugging println in dependency"). Someone should probably investigate.

@wesleywiser
Copy link
Member Author

Most of the changes seem to be in LLVM time and based on the "run count" column, it seems like more cgu's are getting regenerated in the incremental scenario?

Since this will cause more statements to be removed from the MIR, maybe this is causing code to be partitioned differently?

https://github.com/rust-lang/rust/blob/master/src/librustc_middle/mir/mono.rs#L292-L294

bors added a commit to rust-lang-ci/rust that referenced this pull request Apr 27, 2020
Emit basic block info for stmts and terminators in MIR dumps only with -Zverbose

r? @eddyb

as per rust-lang#70755 (comment)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
merged-by-bors This PR was explicitly merged by bors. S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants