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

Add local DSE optimization pass #94118

Closed
wants to merge 4 commits into from
Closed

Conversation

JakobDegen
Copy link
Contributor

This PR adds an optimization pass that eliminates stores that can be proven dead within the basic block in which they appear. The full behavior and arguments for correctness of the optimization are documented in the source.

Making this a pass of its own was almost an afterthought; I originally needed this functionality for another opt I was working. If it turns out that this is bad for perf or something, then the pass can definitely be disabled, and we can just leave the functionality in for other opts to use.

Marking as a draft because the src/test/mir-opt/simplify-locals.rs test is still broken under this. I could not find a way to modify that test in a way that cause simplify locals but not this optimization to fire. Does anyone have more creative ideas? Should the test just be removed? Does simplify locals need to be adjusted somehow?

The `coverage` test checks that all the desired optimizations are performed, while the remaining
tests check that a variety of other cases are not optimized. Unfortunately, const prop makes the
MIR slightly less clear than it could be, but all the intended checks are still intact.
Adding the DSE pass changed the emitted MIR for a bunch of other test. This commit blesses/fixes
these changes. In some cases, this required adding some `black_box` calls to inhibit the DSE
optimizations.
@rustbot rustbot added the T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. label Feb 18, 2022
@rust-highfive
Copy link
Collaborator

r? @nagisa

(rust-highfive has picked a reviewer for you, use r? to override)

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Feb 18, 2022
@rust-log-analyzer
Copy link
Collaborator

The job x86_64-gnu-llvm-12 failed! Check out the build log: (web) (plain)

Click to see the possible cause of the failure (guessed by this bot)
failures:

---- [mir-opt] mir-opt/simplify-locals.rs stdout ----
15   
16       bb0: {
17           StorageLive(_1);                 // scope 0 at $DIR/simplify-locals.rs:14:9: 14:14
-           _1 = [const 0_u8; 10];           // scope 0 at $DIR/simplify-locals.rs:14:17: 14:26
19 -         StorageLive(_2);                 // scope 1 at $DIR/simplify-locals.rs:16:20: 16:26
20 -         StorageLive(_3);                 // scope 1 at $DIR/simplify-locals.rs:16:20: 16:26
21 -         StorageLive(_4);                 // scope 1 at $DIR/simplify-locals.rs:16:20: 16:26

- -         _4 = &_1;                        // scope 1 at $DIR/simplify-locals.rs:16:20: 16:26
- -         _3 = _4;                         // scope 1 at $DIR/simplify-locals.rs:16:20: 16:26
- -         _2 = move _3 as &[u8] (Pointer(Unsize)); // scope 1 at $DIR/simplify-locals.rs:16:20: 16:26
25 -         StorageDead(_3);                 // scope 1 at $DIR/simplify-locals.rs:16:25: 16:26
26 -         StorageDead(_4);                 // scope 1 at $DIR/simplify-locals.rs:16:26: 16:27
27 -         StorageDead(_2);                 // scope 1 at $DIR/simplify-locals.rs:16:26: 16:27

thread '[mir-opt] mir-opt/simplify-locals.rs' panicked at 'Actual MIR output differs from expected MIR output /checkout/src/test/mir-opt/simplify_locals.c.SimplifyLocals.diff', src/tools/compiletest/src/runtest.rs:3375:25


failures:
    [mir-opt] mir-opt/simplify-locals.rs

@jackh726
Copy link
Member

@bors try @rust-timer queue

@rust-timer
Copy link
Collaborator

Awaiting bors try build completion.

@rustbot label: +S-waiting-on-perf

@rustbot rustbot added the S-waiting-on-perf Status: Waiting on a perf run to be completed. label Feb 18, 2022
@bors
Copy link
Contributor

bors commented Feb 18, 2022

⌛ Trying commit 7a30d3e with merge 60bf4a09dcb49ff672dce0a99473714e8a327a74...

@bors
Copy link
Contributor

bors commented Feb 18, 2022

☀️ Try build successful - checks-actions
Build commit: 60bf4a09dcb49ff672dce0a99473714e8a327a74 (60bf4a09dcb49ff672dce0a99473714e8a327a74)

@rust-timer
Copy link
Collaborator

Queued 60bf4a09dcb49ff672dce0a99473714e8a327a74 with parent b8c56fa, future comparison URL.

@rust-timer
Copy link
Collaborator

Finished benchmarking commit (60bf4a09dcb49ff672dce0a99473714e8a327a74): comparison url.

Summary: This benchmark run shows 2 relevant improvements 🎉 but 23 relevant regressions 😿 to instruction counts.

  • Average relevant regression: 0.9%
  • Average relevant improvement: -0.9%
  • Largest improvement in instruction counts: -1.1% on full builds of ripgrep opt
  • Largest regression in instruction counts: 3.8% on incr-patched: b9b3e592dd cherry picked builds of style-servo debug

If you disagree with this performance assessment, please file an issue in rust-lang/rustc-perf.

Benchmarking 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 led to changes in compiler perf.

Next Steps: If you can justify the regressions found in this try perf run, please indicate this with @rustbot label: +perf-regression-triaged along with sufficient written justification. If you cannot justify the regressions please fix the regressions and do another perf run. If the next run shows neutral or positive results, the label will be automatically removed.

@bors rollup=never
@rustbot label: +S-waiting-on-review -S-waiting-on-perf +perf-regression

@rustbot rustbot added perf-regression Performance regression. and removed S-waiting-on-perf Status: Waiting on a perf run to be completed. labels Feb 18, 2022
@JakobDegen
Copy link
Contributor Author

Yeah, this is probably just duplicating work that either simplify locals/LLVM are also trying to do, so the mild regression isn't terribly surprising. I'll let review take a look, and can bump this to mir_opt_level >= 3 if there's nothing that stands out

@JakobDegen
Copy link
Contributor Author

JakobDegen commented Feb 21, 2022

I'm actually going to close this for now, I think I have a more promising idea than this. May re-open if that doesn't pan out

@JakobDegen JakobDegen closed this Feb 21, 2022
@JakobDegen JakobDegen deleted the add-dse branch March 5, 2022 02:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
perf-regression Performance regression. S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants