Uh oh!
There was an error while loading. Please reload this page.
New MIR optimization pass to reduce branches on match of tuples of enums - #75119
Conversation
rust-highfive
commented
Aug 3, 2020
Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @varkor (or someone else) soon. If any changes to this PR are deemed necessary, please add them as extra commits. This ensures that the reviewer can see what has changed since they last reviewed the code. Due to the way GitHub handles out-of-date commits, this should also make it reasonably obvious what issues have or haven't been addressed. Large or tricky changes may require several passes of review and changes. Please see the contribution instructions for more information. |
varkor
commented
Aug 3, 2020
This looks great, but unfortunately I don't have time to review something of this size at the moment. r? @eddyb @bors try @rust-timer queue |
rust-timer
commented
Aug 3, 2020
Awaiting bors try build completion |
bors
commented
Aug 3, 2020
⌛ Trying commit c6982e36a893aeb5647d1c7773bff287acc43a38 with merge e42444c82f1bdc51f3bd1abadcf3f7b2a9e87159... |
bors
commented
Aug 3, 2020
☀️ Try build successful - checks-actions, checks-azure |
rust-timer
commented
Aug 3, 2020
Queued e42444c82f1bdc51f3bd1abadcf3f7b2a9e87159 with parent 829d69b, future comparison URL. |
rust-timer
commented
Aug 4, 2020
Finished benchmarking try commit (e42444c82f1bdc51f3bd1abadcf3f7b2a9e87159): comparison url. Benchmarking this pull request likely means that it is perf-sensitive, so we're automatically marking it as not fit for rolling up. Please note that if the perf results are neutral, you should likely undo the rollup=never given below by specifying Importantly, though, if the results of this run are non-neutral do not roll this PR up -- it will mask other regressions or improvements in the roll up. @bors rollup=never |
simonvandel
commented
Aug 4, 2020
The pass is gated on Mir opt level 3 right now, so I don't think a perf run makes sense without removing that check. @eddyb do you want me to remove it so we can check the impact of perf? |
c6982e3 to
8ef3624Comparesimonvandel
commented
Aug 4, 2020
I don't quite understand how to solve the tests failing. Running bless locally does not change anything |
You likely need to edit the 32-bit test outputs ( |
You also have to add |
bors
commented
Aug 11, 2020
☔ The latest upstream changes (presumably #73656) made this pull request unmergeable. Please resolve the merge conflicts. |
wesleywiser
commented
Aug 11, 2020
cc @rust-lang/wg-mir-opt |
61056c8 to
e083d97Comparesimonvandel
commented
Aug 11, 2020
Rebased on master and squashed |
oli-obk
commented
Aug 12, 2020
r? @oli-obk |
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
instead of doing a switch and going to a block that does another switch, you can also compute another comparison:
_42 = Eq(_7,1_isize)
_43 = BitAnd(_42, _11)and then switch on _43 to directly go to bb3
There was a problem hiding this comment.
@oli-obk Hmm that works when we have only have 2 targets in the switch, but what if we have 3 targets in the switch like match (x,y,z)? See the 3_element_tuple test. Correct me if I am wrong though
There was a problem hiding this comment.
That test makes bb2 dead code, and doesn't affect the match part on z at all, so it all seems to work out to me? You aren't optimizing chains longer than 2 elements with your optimization, and even if the optimization is extended to support that, we'd just end up with more of these BitAnds I think.
There was a problem hiding this comment.
It's been a while, but I finally looked at it again. I don't think it is that easy to use BitAnd to avoid the extra bb. See https://github.com/rust-lang/rust/pull/75119/files#diff-37f80fe71480f2b22fb8fd1fc103fda4R88 where we need to check both 0 and 1.
Uh oh!
There was an error while loading. Please reload this page.
bors
commented
Aug 29, 2020
☔ The latest upstream changes (presumably #75370) made this pull request unmergeable. Please resolve the merge conflicts. |
6e45568 to
048c233CompareUh oh!
There was an error while loading. Please reload this page.
048c233 to
13e8e20Compareoli-obk
commented
Sep 20, 2020
@bors r+ |
bors
commented
Sep 20, 2020
📌 Commit 13e8e20df3307d8eaf8b6f86e73f313fcaab39b2 has been approved by |
Uh oh!
There was an error while loading. Please reload this page.
oli-obk
commented
Sep 20, 2020
@bors r- |
13e8e20 to
0363694Compareoli-obk
commented
Sep 20, 2020
@bors r+ |
bors
commented
Sep 20, 2020
📌 Commit 0363694 has been approved by |
bors
commented
Sep 20, 2020
bors
commented
Sep 20, 2020
☀️ Test successful - checks-actions, checks-azure |
ecstatic-morse
commented
Sep 21, 2020
Hi! This PR showed up in the weekly perf triage report. It showed mixed results in instruction counts. While It's possible that there's some improvement in the generated code, although I'd be a bit surprised if LLVM couldn't manage this. If there's no runtime speedup, I think we should consider disabling this by default. |
simonvandel
commented
Sep 22, 2020
Hi @ecstatic-morse |
wesleywiser
commented
Sep 23, 2020
It sounds like this might be a good fit for mir-opt-level=2 then as (eventually) we want to make that the default for optimized builds while mir-opt-level=1 will remain the default for non optimized builds. |
ecstatic-morse
commented
Oct 4, 2020
@wesleywiser@simonvandel Was this ever moved to |
simonvandel
commented
Oct 5, 2020
Hi @ecstatic-morse, no this pass is still running at opt-level=1. Should I create a pr to gate it at 2? |
…ise-branch, r=wesleywiser Move `EarlyOtherwiseBranch` to mir-opt-level 2 cc rust-lang#75119 This didn't have an [effect in most cases](https://perf.rust-lang.org/compare.html?start=81e02708f1f4760244756548981277d5199baa9a&end=2e0edc0f28c5647141bedba02e7a222d3a5dc9c3&stat=instructions:u), and is not trivially sound. Let it bake at `mir-opt-level=2` for a while. Also, this missed the cutoff for beta, so we'll have to backport this. r? @wesleywiser
Fixes#68867 by adding a new pass that turns something like
into something like
The opt-diffs still have the old basic blocks like
These do get removed on later passes. I'm not sure if I should include those passes in the test to make it clear?