GeezerVisonThe World Wide Web, restored to 800 pixels of glory. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Home|About|Gaming cabinet|Archives|How it works|Starter sites | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
GeezerVison is showing github.com — [mir-opt] asking `?`s in a more optimized fashion by Centril · Pull Request #66282 · rust-lang/rust Conversation
Contributor
This PR works towards #66234 by providing two optimization passes meant to run in sequence:
Together, these are meant to simplify the following into just match res { Ok(x) => Ok(x), Err(x) => Err(x), } It should be noted however that the desugaring of r? @oli-obk -- This is WIP, but I'd appreciate feedback. :)
Sorry, something went wrong. Uh oh!
There was an error while loading. Please reload this page. All reactions
Contributor
Author
All reactions
Sorry, something went wrong. Uh oh!
There was an error while loading. Please reload this page.
Collaborator
All reactions
Sorry, something went wrong. Uh oh!
There was an error while loading. Please reload this page.
Collaborator
All reactions
Sorry, something went wrong. Uh oh!
There was an error while loading. Please reload this page.
Contributor
Author
All reactions
Sorry, something went wrong. Uh oh!
There was an error while loading. Please reload this page.
Contributor
Author
All reactions
Sorry, something went wrong. Uh oh!
There was an error while loading. Please reload this page.
Collaborator
Sorry, something went wrong. Uh oh!
There was an error while loading. Please reload this page.
bors
added a commit
that referenced
this pull request
[WIP] [mir-opt] asking `?`s in a more optimized fashion This PR works towards #66234 by providing two optimization passes meant to run in sequence: - `SimplifyArmIdentity` which transforms something like: ```rust _LOCAL_TMP = ((_LOCAL_1 as Variant ).FIELD: TY ); ((_LOCAL_0 as Variant).FIELD: TY) = move _LOCAL_TMP; discriminant(_LOCAL_0) = VAR_IDX; ``` into: ```rust _LOCAL_0 = move _LOCAL_1 ``` - `SimplifyBranchSame` which transforms `SwitchInt`s to identical basic blocks into a `goto` to the first reachable target. Together, these are meant to simplify the following into just `res`: ```rust match res { Ok(x) => Ok(x), Err(x) => Err(x), } ``` It should be noted however that the desugaring of `?` includes a function call and so the first pass in this PR relies on inlining to substitute that function call for identity on `x`. Inlining requires `mir-opt-level=2` so this might not have any effect in perf-bot but let's find out. r? @oli-obk -- This is WIP, but I'd appreciate feedback. :)
Centril
commented
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is a tad unfortunate that
Sorry, something went wrong. Uh oh!
There was an error while loading. Please reload this page. All reactions
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I thought we had some sort of DCE. If not, open an issue so we create it
Sorry, something went wrong. Uh oh!
There was an error while loading. Please reload this page. All reactions
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think this will be easy to fix. I'll open a PR tonight with that.
Sorry, something went wrong. Uh oh!
There was an error while loading. Please reload this page. All reactions
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There are some ppl at rustfest working on it
Sorry, something went wrong. Uh oh!
There was an error while loading. Please reload this page. All reactions
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Does that refer to #66329 ? -- That won't help in this case since this is an unused, but reachable, local.
Sorry, something went wrong. Uh oh!
There was an error while loading. Please reload this page. All reactions
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No, different optimization, not sure on what repo it's being developed
Sorry, something went wrong. Uh oh!
There was an error while loading. Please reload this page. All reactions
Centril
commented
Uh oh!
There was an error while loading. Please reload this page.
Centril
commented
Uh oh!
There was an error while loading. Please reload this page.
Centril
commented
Uh oh!
There was an error while loading. Please reload this page.
This comment has been minimized.
This comment has been minimized.
Collaborator
All reactions
Sorry, something went wrong. Uh oh!
There was an error while loading. Please reload this page.
Collaborator
All reactions
Sorry, something went wrong. Uh oh!
There was an error while loading. Please reload this page.
oli-obk
reviewed
Uh oh!
There was an error while loading. Please reload this page.
Collaborator
All reactions
Sorry, something went wrong. Uh oh!
There was an error while loading. Please reload this page.
This comment has been minimized.
Centril
force-pushed
the
simplify-try
branch
from
219d24f to
f026031
Compare
?s in a more optimized fashion?s in a more optimized fashion
Contributor
Author
All reactions
Sorry, something went wrong. Uh oh!
There was an error while loading. Please reload this page.
|
There was an error while loading. Please reload this page.
|
Actually, looking at |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
This should be ready now :) |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
⌛ Testing commit 2f00e86 with merge ae731e69b0e519dbf73d4a870a82224b778808de... |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
Your PR failed (pretty log, raw log). Through arcane magic we have determined that the following fragments from the build log may contain information about the problem. Click to expand the log.I'm a bot! I can only do what humans tell me to, so if this was not helpful or you have suggestions for improvements, please ping or otherwise contact |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
💔 Test failed - checks-azure |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
@bors retry spurious |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
[mir-opt] asking `?`s in a more optimized fashion This PR works towards #66234 by providing two optimization passes meant to run in sequence: - `SimplifyArmIdentity` which transforms something like: ```rust _LOCAL_TMP = ((_LOCAL_1 as Variant ).FIELD: TY ); ((_LOCAL_0 as Variant).FIELD: TY) = move _LOCAL_TMP; discriminant(_LOCAL_0) = VAR_IDX; ``` into: ```rust _LOCAL_0 = move _LOCAL_1 ``` - `SimplifyBranchSame` which transforms `SwitchInt`s to identical basic blocks into a `goto` to the first reachable target. Together, these are meant to simplify the following into just `res`: ```rust match res { Ok(x) => Ok(x), Err(x) => Err(x), } ``` It should be noted however that the desugaring of `?` includes a function call and so the first pass in this PR relies on inlining to substitute that function call for identity on `x`. Inlining requires `mir-opt-level=2` so this might not have any effect in perf-bot but let's find out. r? @oli-obk -- This is WIP, but I'd appreciate feedback. :)
|
☀️ Test successful - checks-azure |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
@oli-obk sorry wrong pr 😂 |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| || Some((local_0, vf_s0.var_idx)) != match_set_discr(s2) | ||
| { | ||
| continue; | ||
| } |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
You're not checking that local_0 != local_1, which is another soundness condition.
cc @rust-lang/wg-mir-opt
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| /// | ||
| /// ```rust | ||
| /// _LOCAL_TMP = ((_LOCAL_1 as Variant ).FIELD: TY ); | ||
| /// ((_LOCAL_0 as Variant).FIELD: TY) = move _LOCAL_TMP; |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
This is only sound to collapse if _LOCAL_TMP isn't used anywhere else (see promote_consts for an example of an analysis like that).
But also, there's another issue here... namely, debuginfo.
You need to replace _LOCAL_TMP with ((_LOCAL_1 as Variant ).FIELD: TY) in debuginfo as well, making this a very specialized form of copy-prop, I guess?
cc @rust-lang/wg-mir-opt
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
It would be nice to preserve debuginfo perfectly, but for that we might need a way to merge scopes or something, so that SourceInfo from all 3 statements is combined.
Effectively, the resulting _LOCAL_0 = move _LOCAL_1 needs to be in a superposition of all the scopes.
Which might be hard due to the inlining.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| _ => unreachable!(), | ||
| } | ||
| s1.make_nop(); | ||
| s2.make_nop(); |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
I would replace the third statement and nop the first two. That way, you get the SourceInfo of the Ok(x) rather than the x use (or whatever initialized it).
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| /// Simplifies `SwitchInt(_) -> [targets]`, | ||
| /// where all the `targets` have the same form, | ||
| /// into `goto -> target_first`. | ||
| pub struct SimplifyBranchSame; |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
I don't think we can do this unless there is no debuginfo attached to scopes used only in the arms, or we can convert the debuginfo into a form that switches on the SwitchInt operand (plausible in DWARF, not really exposed in LLVM).
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
But also this optimization can be rephrased as sinking identical statements from predecessors into the start of a block, followed by simplify_cfg.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
simplify_try: address some of eddyb's comments Addresses only rust-lang#66282 (comment) and rust-lang#66282 (comment). r? @eddyb cc @oli-obk
There was an error while loading. Please reload this page.
Successfully merging this pull request may close these issues.
There was an error while loading. Please reload this page.