Uh oh!
There was an error while loading. Please reload this page.
Implement SSA-based reference propagation - #106285
Conversation
rustbot
commented
Dec 30, 2022
(rustbot has picked a reviewer for you, use r? to override) |
petrochenkov
commented
Dec 30, 2022
r? rust-lang/compiler |
cjgillot
commented
Jan 1, 2023
@bors try @rust-timer queue |
This comment has been minimized.
This comment has been minimized.
bors
commented
Jan 1, 2023
⌛ Trying commit 46516095d7a9cb208c8f17a01574a9a8bc180833 with merge fea7409a5e37c7f115c6b24d93e12e52fe364c27... |
This comment has been minimized.
This comment has been minimized.
bors
commented
Jan 1, 2023
☀️ Try build successful - checks-actions |
This comment has been minimized.
This comment has been minimized.
rust-timer
commented
Jan 1, 2023
Finished benchmarking commit (fea7409a5e37c7f115c6b24d93e12e52fe364c27): comparison URL. Overall result: ❌✅ regressions and improvements - ACTION NEEDEDBenchmarking 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 may lead to changes in compiler perf. Next Steps: If you can justify the regressions found in this try perf run, please indicate this with @bors rollup=never Instruction countThis is a highly reliable metric that was used to determine the overall result at the top of this comment.
Max RSS (memory usage)ResultsThis is a less reliable metric that may be of interest but was not used to determine the overall result at the top of this comment.
CyclesResultsThis is a less reliable metric that may be of interest but was not used to determine the overall result at the top of this comment.
|
This comment has been minimized.
This comment has been minimized.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
For immutable borrows and AddressOf, we probably don't need to mark the local as non-SSA: that borrow cannot be used, even indirectly to modify the local. Recording a direct use should be enough.
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.
00ae1c3 to
a70ab55Comparerustbot
commented
Jan 7, 2023
Some changes occurred to MIR optimizations cc @rust-lang/wg-mir-opt |
bors
commented
May 9, 2023
⌛ Testing commit d30bbe1857fbdac2f4c03a974b22419b02b3c514 with merge bdd6f2fd486b691ba79fff426393a0a45417becb... |
This comment has been minimized.
This comment has been minimized.
bors
commented
May 9, 2023
💔 Test failed - checks-actions |
cjgillot
commented
May 9, 2023
@bors r=JakobDegen |
bors
commented
May 9, 2023
bors
commented
May 9, 2023
bors
commented
May 10, 2023
☀️ Test successful - checks-actions |
rust-timer
commented
May 10, 2023
Finished benchmarking commit (50dff95): comparison URL. Overall result: ❌✅ regressions and improvements - ACTION NEEDEDNext Steps: If you can justify the regressions found in this perf run, please indicate this with @rustbot label: +perf-regression Instruction countThis is a highly reliable metric that was used to determine the overall result at the top of this comment.
Max RSS (memory usage)ResultsThis is a less reliable metric that may be of interest but was not used to determine the overall result at the top of this comment.
CyclesResultsThis is a less reliable metric that may be of interest but was not used to determine the overall result at the top of this comment.
Binary sizeResultsThis is a less reliable metric that may be of interest but was not used to determine the overall result at the top of this comment.
Bootstrap: 657.982s -> 659.227s (0.19%) |
Mark-Simulacrum
commented
May 16, 2023
Regressions appear to mostly be bimodality. |
| /// # Uniqueness | ||
| /// | ||
| /// For `&mut` borrows, we also need to preserve the uniqueness property: | ||
| /// we must avoid creating a state where we interleave uses of `*_1` and `_2`. |
There was a problem hiding this comment.
There is no _2 is the examples above so I don't understand what this comment refers to.
| /// Into | ||
| /// _1 = &raw? mut? PLACE; | ||
| /// _3 = PLACE; | ||
| /// _4 = &raw? mut? PLACE; |
There was a problem hiding this comment.
This seems to be incomplete -- the transformation also kicks in when _3 or _4 apply extra projections to *_1. This is causing some trouble with Stacked Borrows, though arguably that's a SB bug.
Rust has a tendency to create a lot of short-lived borrows, in particular for method calls. This PR aims to remove those short-lived borrows with a const-propagation dedicated to pointers to local places.
This pass aims to transform the following pattern:
Into
where
PLACEis a direct or an indirect place expression.By removing indirection, this pass should help both dest-prop and const-prop to handle more cases.
This optimization is distinct from const-prop and dataflow const-prop since the borrow-reborrow patterns needs to preserve borrowck invariants, especially the uniqueness property of mutable references.
The pointed-to places are computed using a SSA analysis. We suppose that removable borrows are typically temporaries from autoref, so they are by construction assigned only once, and a SSA analysis is enough to catch them. For each local, we store both where and how it is used, in order to efficiently compute the all-or-nothing property. Thanks to
Derefer, we only have to track locals, not places in general.There are 3 properties that need to be upheld for this transformation to be legal:
PLACEmust refer to the same memory wherever it appears;&mutborrow uniqueness.Constness
If
PLACEis an indirect projection, if its of the form(*LOCAL).PROJECTIONSwhere:LOCALis SSA;PROJECTIONSare constant (no dereference and no indexing).If
PLACEis a direct projection of a local, we consider it as constant if:StorageLivethat dominates all uses;Liveness
When performing a substitution, we must take care not to introduce uses of dangling locals.
Using a dangling borrow is UB. Therefore, we assume that for any use of
*x, wherexis a borrow, the pointed-to memory is live.Limitations:
*xin an&raw mut? *xare accepted;In those 2 case, we do not substitute anything, to be on the safe side.
Open question: we do not differentiate borrows of ZST and non-ZST. The UB rules may be
different depending on the layout. Having a different treatment would effectively prevent this
pass from running on polymorphic MIR, which defeats the purpose of MIR opts.
Uniqueness
For
&mutborrows, we also need to preserve the uniqueness property:we must avoid creating a state where we interleave uses of
*_1and_2.To do it, we only perform full substitution of mutable borrows:
we replace either all or none of the occurrences of
*_1.Some care has to be taken when
_1is copied in other locals.In such cases, fully substituting
_1means fully substituting all of the copies.For immutable borrows, we do not need to preserve such uniqueness property,
so we perform all the possible substitutions without removing the
_1 = &_2statement.