Uh oh!
There was an error while loading. Please reload this page.
New pass to optimize ifconditions on integrals to switches on the integer - #75370
Conversation
rust-highfive
commented
Aug 10, 2020
Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @oli-obk (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. |
There was a problem hiding this comment.
A further optimization would be to fold the targets of this switch into the terminator of bb0. That could be a separate PR though?
There was a problem hiding this comment.
yes, please leave it to a separate PR
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
oli-obk
commented
Aug 11, 2020
I'm amazed this didn't touch any other tests. Let's see what the effect of this optimization has on perf, I think it should save us from doing this dance in LLVM everywhere. @bors try @rust-timer queue |
rust-timer
commented
Aug 11, 2020
Awaiting bors try build completion |
bors
commented
Aug 11, 2020
⌛ Trying commit e80c2609f5619e9b06f0f18864c60fc507578ce1 with merge 1aa291e337fc2d554250e6d7160484f473e4e131... |
bors
commented
Aug 11, 2020
☀️ Try build successful - checks-actions, checks-azure |
rust-timer
commented
Aug 11, 2020
Queued 1aa291e337fc2d554250e6d7160484f473e4e131 with parent 441fd22, future comparison URL. |
rust-timer
commented
Aug 11, 2020
Finished benchmarking try commit (1aa291e337fc2d554250e6d7160484f473e4e131): 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 |
oli-obk
commented
Aug 11, 2020
looks like many smaller (< 1%) improvements. Not sure what's up with |
e80c260 to
a53a2b8Compare@oli-obk Fixed all but your comment about moving the match to a function, which I didn't understand. Can you expand on that? |
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
a53a2b8 to
97eb1c2Comparesimonvandel
commented
Aug 18, 2020
I have fixed everything pointed out in the review, but the scalar_to_u128 function, which I don't know how to resolve, help needed. |
There was a problem hiding this comment.
Make sure that previous SwitchInt used move operand before removing the comparison statement, since it might be used in other place:
pubfnf(a:i8) -> i32{let b = a == 17;match b {false => 10 + b asi32,true => 100 + b asi32,}}There was a problem hiding this comment.
Thanks, fixed this and added test for it. Interestingly enough, looking at the opt-diffs, the value being switched on is not being moved into the switch even if it is not being used later on. Is that a bug?
There was a problem hiding this comment.
Yea, we may be able to fix MIR building here to use a move instead of a copy, but let's do that in a separate PR
There was a problem hiding this comment.
I created issue #75993 to track fixing MIR building
97eb1c2 to
7c6d7f3CompareUh oh!
There was an error while loading. Please reload this page.
simonvandel
commented
Aug 23, 2020
Hi @oli-obk To resolve @tmiasko 's comment about not removing the comparison statement (Eq/Ne), I only remove it if the place of comparison result is being moved into the switchInt. That does leave the comparison undeleted in e.g. https://github.com/rust-lang/rust/pull/75370/files#diff-6577b789c4b8ff0d4a014be7009d43afR14 . Is it a problem that my current optimization actually leaves the MIR in a place where _3 is being moved twice? If it is indeed a problem, I suggest either
What do you think? |
simonvandel
commented
Aug 23, 2020
PR failed probably because MIR comments are being removed. I will rebase on master when @oli-obk have had time to review my latest commits |
oli-obk
commented
Aug 26, 2020
We haven't really specified the semantics yet, but I believe we'll want to enforce that you can't move things twice some time in the future. One thing you could do is to replace the moves with copies and then leave any further cleanups to later mir optimizations |
simonvandel
commented
Aug 27, 2020
This is now implemented in the latest commit |
oli-obk
commented
Aug 28, 2020
Thanks! It looks like CI is failing now due to a change in our mir printing. Please rebase again and rebless the tests (for 32 bit and 64 bit both). @bors delegate+ You can now |
bors
commented
Aug 28, 2020
✌️ @simonvandel can now approve this pull request |
c8d92ef to
1073901Comparesimonvandel
commented
Aug 28, 2020
Rebased, squashed and CI green. |
bors
commented
Aug 28, 2020
📌 Commit 10739016390affa75934f12bb876a85fa57d2500 has been approved by |
bors
commented
Aug 28, 2020
⌛ Testing commit 10739016390affa75934f12bb876a85fa57d2500 with merge 765fa323886208e51383cdb65b45931d74ff5b11... |
bors
commented
Aug 28, 2020
💔 Test failed - checks-actions |
1073901 to
23dda1bComparesimonvandel
commented
Aug 29, 2020
Tests failed in the noopt tester that expected CheckedAdd in the MIR output instead of Add. I added |
bors
commented
Aug 29, 2020
📌 Commit 23dda1b has been approved by |
bors
commented
Aug 29, 2020
bors
commented
Aug 29, 2020
☀️ Test successful - checks-actions, checks-azure |
nikic
commented
Aug 29, 2020
FWIW, this change is actually non-canonical, and LLVM will undo it (replace the switch with an icmp+br). |
Fixes#75144
Pass to convert
ifconditions on integrals into switches on the integral.For an example, it turns something like
into: