Skip to content
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

Account for immutably borrowed locals in MIR copy-prop and GVN #123602

Merged
merged 7 commits into from
May 3, 2024

Conversation

cjgillot
Copy link
Contributor

@cjgillot cjgillot commented Apr 7, 2024

For the most part, we consider that immutably borrowed Freeze locals still fulfill SSA conditions. As the borrow is immutable, any use of the local will have the value given by the single assignment, and there can be no surprise.

This allows copy-prop to merge a non-borrowed local with a borrowed local. We chose to keep copy-classes heads unborrowed, as those may be easier to optimize in later passes.

This also allows to GVN the value behind an immutable borrow. If a SSA local is borrowed, dereferencing that borrow is equivalent to copying the local's value: re-executing the assignment between the borrow and the dereference would be UB.

r? @ghost for perf

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Apr 7, 2024
@cjgillot
Copy link
Contributor Author

cjgillot commented Apr 7, 2024

@bors try @rust-timer queue

@rust-timer

This comment has been minimized.

@rustbot rustbot added the S-waiting-on-perf Status: Waiting on a perf run to be completed. label Apr 7, 2024
@bors
Copy link
Contributor

bors commented Apr 7, 2024

⌛ Trying commit fd856c7 with merge 5d2ef83...

bors added a commit to rust-lang-ci/rust that referenced this pull request Apr 7, 2024
Account for immutably borrowed locals in MIR copy-prop and GVN

For the most part, we consider that immutably borrowed `Freeze` locals still fulfill SSA conditions. As the borrow is immutable, any use of the local will have the value given by the single assignment, and there can be no surprise.

This allows copy-prop to merge a non-borrowed local with a borrowed local. We chose to keep copy-classes heads unborrowed, as those may be easier to optimize in later passes.

This also allows to GVN the value behind an immutable borrow. If a SSA local is borrowed, dereferencing that borrow is equivalent to copying the local's value: re-executing the assignment between the borrow and the dereference would be UB.

r? `@ghost` for perf
@rust-log-analyzer

This comment has been minimized.

@bors
Copy link
Contributor

bors commented Apr 7, 2024

☀️ Try build successful - checks-actions
Build commit: 5d2ef83 (5d2ef83d9fbd186559a2618781c405a364bce787)

@rust-timer

This comment has been minimized.

@rust-timer
Copy link
Collaborator

Finished benchmarking commit (5d2ef83): comparison URL.

Overall result: ❌✅ regressions and improvements - ACTION NEEDED

Benchmarking 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 @rustbot label: +perf-regression-triaged along with sufficient written justification. If you cannot justify the regressions please fix the regressions and do another perf run. If the next run shows neutral or positive results, the label will be automatically removed.

@bors rollup=never
@rustbot label: -S-waiting-on-perf +perf-regression

Instruction count

This is a highly reliable metric that was used to determine the overall result at the top of this comment.

mean range count
Regressions ❌
(primary)
0.6% [0.2%, 2.2%] 8
Regressions ❌
(secondary)
0.3% [0.2%, 0.4%] 8
Improvements ✅
(primary)
-0.6% [-1.2%, -0.4%] 7
Improvements ✅
(secondary)
-0.6% [-1.3%, -0.2%] 7
All ❌✅ (primary) 0.0% [-1.2%, 2.2%] 15

Max RSS (memory usage)

Results

This 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.

mean range count
Regressions ❌
(primary)
4.7% [2.7%, 8.1%] 3
Regressions ❌
(secondary)
- - 0
Improvements ✅
(primary)
-3.6% [-5.4%, -2.1%] 12
Improvements ✅
(secondary)
-3.2% [-7.1%, -0.8%] 86
All ❌✅ (primary) -1.9% [-5.4%, 8.1%] 15

Cycles

Results

This 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.

mean range count
Regressions ❌
(primary)
2.2% [2.2%, 2.2%] 1
Regressions ❌
(secondary)
1.9% [1.9%, 1.9%] 1
Improvements ✅
(primary)
-1.3% [-1.3%, -1.3%] 1
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) 0.4% [-1.3%, 2.2%] 2

Binary size

Results

This 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.

mean range count
Regressions ❌
(primary)
0.3% [0.0%, 1.5%] 22
Regressions ❌
(secondary)
0.1% [0.1%, 0.1%] 4
Improvements ✅
(primary)
-0.3% [-1.5%, -0.0%] 40
Improvements ✅
(secondary)
-0.8% [-1.9%, -0.2%] 12
All ❌✅ (primary) -0.1% [-1.5%, 1.5%] 62

Bootstrap: 667.569s -> 666.983s (-0.09%)
Artifact size: 318.50 MiB -> 318.41 MiB (-0.03%)

@rustbot rustbot added perf-regression Performance regression. and removed S-waiting-on-perf Status: Waiting on a perf run to be completed. labels Apr 8, 2024
@cjgillot cjgillot added the A-mir-opt Area: MIR optimizations label Apr 8, 2024
@cjgillot
Copy link
Contributor Author

cjgillot commented Apr 9, 2024

Perf report: weak effect on the benchmark suite in average. Crate metadata size is reduced up to 2 %. Binary size are slightly reduced too, up to 1.9%, but with some increases.

r? @oli-obk
cc @rust-lang/wg-mir-opt

@cjgillot cjgillot marked this pull request as ready for review April 9, 2024 00:17
@rustbot
Copy link
Collaborator

rustbot commented Apr 9, 2024

Some changes occurred to MIR optimizations

cc @rust-lang/wg-mir-opt

Some changes occurred in coverage tests.

cc @Zalathar

@oli-obk
Copy link
Contributor

oli-obk commented Apr 16, 2024

@bors r+

@bors
Copy link
Contributor

bors commented Apr 16, 2024

📌 Commit 8ce8fbf has been approved by oli-obk

It is now in the queue for this repository.

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Apr 16, 2024
bors added a commit to rust-lang-ci/rust that referenced this pull request Apr 17, 2024
Account for immutably borrowed locals in MIR copy-prop and GVN

For the most part, we consider that immutably borrowed `Freeze` locals still fulfill SSA conditions. As the borrow is immutable, any use of the local will have the value given by the single assignment, and there can be no surprise.

This allows copy-prop to merge a non-borrowed local with a borrowed local. We chose to keep copy-classes heads unborrowed, as those may be easier to optimize in later passes.

This also allows to GVN the value behind an immutable borrow. If a SSA local is borrowed, dereferencing that borrow is equivalent to copying the local's value: re-executing the assignment between the borrow and the dereference would be UB.

r? `@ghost` for perf
@bors
Copy link
Contributor

bors commented Apr 17, 2024

⌛ Testing commit 8ce8fbf with merge 30b6c13...

@bors
Copy link
Contributor

bors commented Apr 17, 2024

⌛ Testing commit 8ce8fbf with merge 92b015f...

bors added a commit to rust-lang-ci/rust that referenced this pull request Apr 17, 2024
Account for immutably borrowed locals in MIR copy-prop and GVN

For the most part, we consider that immutably borrowed `Freeze` locals still fulfill SSA conditions. As the borrow is immutable, any use of the local will have the value given by the single assignment, and there can be no surprise.

This allows copy-prop to merge a non-borrowed local with a borrowed local. We chose to keep copy-classes heads unborrowed, as those may be easier to optimize in later passes.

This also allows to GVN the value behind an immutable borrow. If a SSA local is borrowed, dereferencing that borrow is equivalent to copying the local's value: re-executing the assignment between the borrow and the dereference would be UB.

r? `@ghost` for perf
@rust-log-analyzer

This comment has been minimized.

@rust-log-analyzer

This comment has been minimized.

@bors
Copy link
Contributor

bors commented Apr 17, 2024

💔 Test failed - checks-actions

@bors
Copy link
Contributor

bors commented Apr 17, 2024

💔 Test failed - checks-actions

@Zalathar
Copy link
Contributor

Zalathar commented Apr 17, 2024

According to #111883 (comment) that ICE test maybe shouldn't exist either way?

It was only recently added by #122997.

@oli-obk
Copy link
Contributor

oli-obk commented May 2, 2024

@bors r+

@bors
Copy link
Contributor

bors commented May 2, 2024

📌 Commit c19866f has been approved by oli-obk

It is now in the queue for this repository.

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels May 2, 2024
@bors
Copy link
Contributor

bors commented May 3, 2024

⌛ Testing commit c19866f with merge 460356f...

bors added a commit to rust-lang-ci/rust that referenced this pull request May 3, 2024
Account for immutably borrowed locals in MIR copy-prop and GVN

For the most part, we consider that immutably borrowed `Freeze` locals still fulfill SSA conditions. As the borrow is immutable, any use of the local will have the value given by the single assignment, and there can be no surprise.

This allows copy-prop to merge a non-borrowed local with a borrowed local. We chose to keep copy-classes heads unborrowed, as those may be easier to optimize in later passes.

This also allows to GVN the value behind an immutable borrow. If a SSA local is borrowed, dereferencing that borrow is equivalent to copying the local's value: re-executing the assignment between the borrow and the dereference would be UB.

r? `@ghost` for perf
@fmease
Copy link
Member

fmease commented May 3, 2024

⌛ Testing commit c19866f with merge 460356f...

That's a zombie.

@bors retry for good measure

@RalfJung
Copy link
Member

RalfJung commented May 3, 2024

How does this treat addr_of!(local)? This should be treated as allowing mutation of the local via the pointer.

@bors
Copy link
Contributor

bors commented May 3, 2024

⌛ Testing commit c19866f with merge d2d24e3...

@bors
Copy link
Contributor

bors commented May 3, 2024

☀️ Test successful - checks-actions
Approved by: oli-obk
Pushing d2d24e3 to master...

@bors bors added the merged-by-bors This PR was explicitly merged by bors. label May 3, 2024
@bors bors merged commit d2d24e3 into rust-lang:master May 3, 2024
13 checks passed
@rustbot rustbot added this to the 1.80.0 milestone May 3, 2024
@rust-timer
Copy link
Collaborator

Finished benchmarking commit (d2d24e3): comparison URL.

Overall result: ❌✅ regressions and improvements - ACTION NEEDED

Next Steps: If you can justify the regressions found in this perf run, please indicate this with @rustbot label: +perf-regression-triaged along with sufficient written justification. If you cannot justify the regressions please open an issue or create a new PR that fixes the regressions, add a comment linking to the newly created issue or PR, and then add the perf-regression-triaged label to this PR.

@rustbot label: +perf-regression
cc @rust-lang/wg-compiler-performance

Instruction count

This is a highly reliable metric that was used to determine the overall result at the top of this comment.

mean range count
Regressions ❌
(primary)
0.3% [0.2%, 0.9%] 10
Regressions ❌
(secondary)
0.8% [0.2%, 2.6%] 4
Improvements ✅
(primary)
-0.5% [-1.1%, -0.2%] 6
Improvements ✅
(secondary)
-0.5% [-1.0%, -0.3%] 8
All ❌✅ (primary) 0.0% [-1.1%, 0.9%] 16

Max RSS (memory usage)

Results

This 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.

mean range count
Regressions ❌
(primary)
2.9% [1.7%, 4.7%] 3
Regressions ❌
(secondary)
- - 0
Improvements ✅
(primary)
-5.3% [-6.8%, -3.6%] 4
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) -1.8% [-6.8%, 4.7%] 7

Cycles

Results

This 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.

mean range count
Regressions ❌
(primary)
0.8% [0.8%, 0.9%] 2
Regressions ❌
(secondary)
- - 0
Improvements ✅
(primary)
-0.7% [-0.7%, -0.7%] 1
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) 0.3% [-0.7%, 0.9%] 3

Binary size

Results

This 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.

mean range count
Regressions ❌
(primary)
0.1% [0.0%, 0.2%] 23
Regressions ❌
(secondary)
0.1% [0.1%, 0.1%] 4
Improvements ✅
(primary)
-0.3% [-1.2%, -0.0%] 44
Improvements ✅
(secondary)
-0.6% [-1.9%, -0.1%] 14
All ❌✅ (primary) -0.2% [-1.2%, 0.2%] 67

Bootstrap: 674.658s -> 674.126s (-0.08%)
Artifact size: 315.94 MiB -> 315.84 MiB (-0.03%)

@cjgillot cjgillot deleted the gvn-borrowed branch May 4, 2024 18:36
@pnkfelix
Copy link
Member

pnkfelix commented May 7, 2024

How does this treat addr_of!(local)? This should be treated as allowing mutation of the local via the pointer.

Did this Q from @RalfJung get addressed, @cjgillot ?

@pnkfelix
Copy link
Member

pnkfelix commented May 7, 2024

Visiting for perf triage

  • html5ever opt-full regressed by 0.92%; libc in various incremental scenarios regressed by 0.30% to 0.39%.
  • the libc changes were anticipated in the perf build prior to merge; html5ever opt-full was not predicted there.
  • pnkfelix hypothesizes that this just reflects some extra-work from the compiler attempting to do the copy-propagation and global-value-numbering mir-optimizations on a larger set of immutably-borrowed locals, and is acceptable given the expected benefits.
  • marking as triaged

@rustbot label: +perf-regression-triaged

@rustbot rustbot added the perf-regression-triaged The performance regression has been triaged. label May 7, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-mir-opt Area: MIR optimizations merged-by-bors This PR was explicitly merged by bors. perf-regression Performance regression. perf-regression-triaged The performance regression has been triaged. S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

10 participants