-
Notifications
You must be signed in to change notification settings - Fork 13.3k
MIR-OPT: Make SimplifyBranchSame able to remove identity match with fieldless variant #74748
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
Conversation
Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @petrochenkov (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. |
src/test/mir-opt/simplify-arm/rustc.id.SimplifyDiscriminantArm.diff
Outdated
Show resolved
Hide resolved
@@ -1,9 +1,12 @@ | |||
// compile-flags: -Z mir-opt-level=1 | |||
// compile-flags: -Z mir-opt-level=2 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I changed this to 2 since that is the level that SimplifyArmIdentity runs at
I wonder if converting a SetDiscriminant to an assignment is actually a pessimisation if SimplifyBranchSame for some reason cannot unify the branches. If the size difference of enum variants are sufficiently big, it seems that it could be an issue. One way to deal with this would be to build the checks for the SimplifyDiscriminantArm pass directly into SimplifyBranchSame, allowing it to simply union the branches of the conditions meet, such that SetDiscriminant is the same behavior as an assignment. Then SimplifyDiscriminantArm would not exist and would therefore not be able to create a pessimisation. Any thoughts? |
r? @oli-obk |
Yea, I think making the |
Do you mean making the SimplifyBranchSame optimization smarter would be a better idea? |
oops yea. |
I agree, I think we should work on improving the |
☔ The latest upstream changes (presumably #74837) made this pull request unmergeable. Please resolve the merge conflicts. |
4b92f89
to
f362a0b
Compare
Hi @wesleywiser and @oli-obk |
So i'm a bit unsure of what's going on in the failed tests. "set descriminant on adt that is not enum" It arrives here:
Is my assumption that SetDescriminant only ever has a place of a enum wrong? The above error message seems like the place is a generator |
Generators also use |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you rebase and squash as well? Thanks!
e1a95b4
to
755d6ef
Compare
Hi @wesleywiser |
Sure thing! As I recall, there were some slight wins the last time we enabled this so hopefully we see those again (and larger)! @bors try @rust-timer queue |
Awaiting bors try build completion |
⌛ Trying commit 755d6efa3faa906f1fb6424c390bfc3ce8a2ff3b with merge 9b2742608f990cfe089efec9466a9ca39dce0501... |
☀️ Try build successful - checks-actions, checks-azure |
Queued 9b2742608f990cfe089efec9466a9ca39dce0501 with parent 1275cc1, future comparison URL. |
Finished benchmarking try commit (9b2742608f990cfe089efec9466a9ca39dce0501): 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 |
Perf looks pretty neutral. But i think it’s because SimplifyArmIdentity is not running on mir opt level 1. If it was, a lot more branches would match the optimization. @wesleywiser should we land the current PR? And then I’m wondering if we can lower the opt level for SimplifyArmIdentity. |
scope 5 { | ||
} | ||
} | ||
scope 6 { | ||
debug self => _4; // in scope 6 at $SRC_DIR/core/src/result.rs:LL:COL |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's very strange that this is being added (debug self =>
doesn't' appear at all on the left side)
EDIT: This is probably because we switched -Zmir-opt-level=2
on which means the inliner is running.
Yeah, you're right!
It looks good to me, @oli-obk do you want to review as well?
We had to increase the opt-level last time because of regressions found during the beta period so I was planning on trying again after the next beta branch in about two weeks time. That way we maximize the time it has on the |
the MIR diffs lgtm, I didn't look at the impl. If you want I can try to find some time for it, but imo you can merge at your discretion |
755d6ef
to
d29da9b
Compare
Pushed @wesleywiser 's suggestion about or-patterns |
d29da9b
to
d2fc8b0
Compare
@wesleywiser The 32 bit tests are being annoying again. Would it be feasible to have --bless somehow also update 32bit tests? I always forget to do that |
@simonvandel You can do that by telling |
This just needs the 32-bit tests blessed and then we can merge it. @simonvandel if you need help with that, I'd be happy to pull your branch locally and bless the tests. |
@wesleywiser I won't be able to do it in the next couple of days, so feel free to drive it onwards. |
…= _1` and `discriminant(_0) = discriminant(0)` are considered equal if 0 is a fieldless variant of an enum
d2fc8b0
to
293756c
Compare
Hi @wesleywiser |
Thanks @simonvandel! Since this is a mir-opt, we should avoid rolling up in case there is a perf impact or we need to do a bisection. @bors r+ rollup=never |
📌 Commit 293756c has been approved by |
☀️ Test successful - checks-actions, checks-azure |
Modifies SimplifyBranchSame so that it can see that the statements can be considered equal in the following example
_0 = _1
anddiscriminant(_0) = discriminant(0)
are considered equal if 0 is a fieldless variant of an enum.