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

Do not unify dereferences of shared borrows in GVN #133474

Merged
merged 3 commits into from
Nov 27, 2024

Conversation

RalfJung
Copy link
Member

Repost of #132461, the last commit applies my suggestions.

Fixes #130853

@rustbot
Copy link
Collaborator

rustbot commented Nov 25, 2024

r? @Nadrieril

rustbot has assigned @Nadrieril.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

@rustbot rustbot added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Nov 25, 2024
@rustbot
Copy link
Collaborator

rustbot commented Nov 25, 2024

Some changes occurred to MIR optimizations

cc @rust-lang/wg-mir-opt

Some changes occurred in coverage tests.

cc @Zalathar

@rustbot rustbot added the T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. label Nov 25, 2024
@RalfJung
Copy link
Member Author

@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 Nov 25, 2024
@bors
Copy link
Contributor

bors commented Nov 25, 2024

⌛ Trying commit 906f66f with merge 16c1019...

bors added a commit to rust-lang-ci/rust that referenced this pull request Nov 25, 2024
Do not unify dereferences of shared borrows in GVN

Repost of rust-lang#132461, the last commit applies my suggestions.

Fixes rust-lang#130853
@compiler-errors
Copy link
Member

r=me after try build is done :D

@bors
Copy link
Contributor

bors commented Nov 25, 2024

☀️ Try build successful - checks-actions
Build commit: 16c1019 (16c101943b84f24b28a1a713b06e961002c2440b)

@rust-timer

This comment has been minimized.

@rust-timer
Copy link
Collaborator

Finished benchmarking commit (16c1019): comparison URL.

Overall result: ❌✅ regressions and improvements - please read the text below

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 the most reliable metric that we have; it was used to determine the overall result at the top of this comment. However, even this metric can sometimes exhibit noise.

mean range count
Regressions ❌
(primary)
0.3% [0.2%, 0.7%] 8
Regressions ❌
(secondary)
0.2% [0.1%, 0.4%] 13
Improvements ✅
(primary)
-1.9% [-6.7%, -0.3%] 8
Improvements ✅
(secondary)
-0.2% [-0.3%, -0.1%] 5
All ❌✅ (primary) -0.8% [-6.7%, 0.7%] 16

Max RSS (memory usage)

Results (primary -1.4%, secondary 3.4%)

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.8% [1.2%, 4.1%] 3
Regressions ❌
(secondary)
3.4% [3.4%, 3.4%] 1
Improvements ✅
(primary)
-5.6% [-6.6%, -4.1%] 3
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) -1.4% [-6.6%, 4.1%] 6

Cycles

Results (primary -3.4%)

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)
1.5% [1.5%, 1.5%] 1
Regressions ❌
(secondary)
- - 0
Improvements ✅
(primary)
-5.9% [-6.5%, -5.2%] 2
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) -3.4% [-6.5%, 1.5%] 3

Binary size

Results (primary 0.0%, secondary 0.0%)

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%, 2.6%] 32
Regressions ❌
(secondary)
0.5% [0.1%, 1.1%] 7
Improvements ✅
(primary)
-0.3% [-2.0%, -0.0%] 28
Improvements ✅
(secondary)
-0.1% [-0.3%, -0.0%] 41
All ❌✅ (primary) 0.0% [-2.0%, 2.6%] 60

Bootstrap: 796.592s -> 797.482s (0.11%)
Artifact size: 336.27 MiB -> 336.00 MiB (-0.08%)

@rustbot rustbot added perf-regression Performance regression. and removed S-waiting-on-perf Status: Waiting on a perf run to be completed. labels Nov 25, 2024
@RalfJung
Copy link
Member Author

@bors r=compiler-errors

@bors
Copy link
Contributor

bors commented Nov 26, 2024

📌 Commit 906f66f has been approved by compiler-errors

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 Nov 26, 2024
@bors
Copy link
Contributor

bors commented Nov 27, 2024

⌛ Testing commit 906f66f with merge 6b6a867...

@bors
Copy link
Contributor

bors commented Nov 27, 2024

☀️ Test successful - checks-actions
Approved by: compiler-errors
Pushing 6b6a867 to master...

@bors bors added the merged-by-bors This PR was explicitly merged by bors. label Nov 27, 2024
@bors bors merged commit 6b6a867 into rust-lang:master Nov 27, 2024
7 checks passed
@rustbot rustbot added this to the 1.85.0 milestone Nov 27, 2024
@rust-timer
Copy link
Collaborator

Finished benchmarking commit (6b6a867): comparison URL.

Overall result: ❌✅ regressions and improvements - please read the text below

Our benchmarks found a performance regression caused by this PR.
This might be an actual regression, but it can also be just noise.

Next Steps:

  • If the regression was expected or you think it can be justified,
    please write a comment with sufficient written justification, and add
    @rustbot label: +perf-regression-triaged to it, to mark the regression as triaged.
  • If you think that you know of a way to resolve the regression, try to create
    a new PR with a fix for the regression.
  • If you do not understand the regression or you think that it is just noise,
    you can ask the @rust-lang/wg-compiler-performance working group for help (members of this group
    were already notified of this PR).

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

Instruction count

This is the most reliable metric that we have; it was used to determine the overall result at the top of this comment. However, even this metric can sometimes exhibit noise.

mean range count
Regressions ❌
(primary)
0.2% [0.1%, 0.6%] 14
Regressions ❌
(secondary)
0.2% [0.1%, 0.4%] 10
Improvements ✅
(primary)
-1.7% [-6.7%, -0.2%] 9
Improvements ✅
(secondary)
-0.2% [-0.3%, -0.1%] 6
All ❌✅ (primary) -0.5% [-6.7%, 0.6%] 23

Max RSS (memory usage)

Results (primary 2.0%)

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)
5.3% [3.1%, 7.3%] 4
Regressions ❌
(secondary)
- - 0
Improvements ✅
(primary)
-4.4% [-4.6%, -4.2%] 2
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) 2.0% [-4.6%, 7.3%] 6

Cycles

Results (primary -3.6%, secondary 2.5%)

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)
1.7% [1.7%, 1.7%] 1
Regressions ❌
(secondary)
2.5% [2.5%, 2.5%] 1
Improvements ✅
(primary)
-6.2% [-6.7%, -5.7%] 2
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) -3.6% [-6.7%, 1.7%] 3

Binary size

Results (primary -0.0%, secondary 0.0%)

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%, 2.6%] 28
Regressions ❌
(secondary)
0.5% [0.1%, 1.1%] 7
Improvements ✅
(primary)
-0.3% [-2.1%, -0.0%] 28
Improvements ✅
(secondary)
-0.1% [-0.3%, -0.0%] 41
All ❌✅ (primary) -0.0% [-2.1%, 2.6%] 56

Bootstrap: 795.759s -> 793.974s (-0.22%)
Artifact size: 336.16 MiB -> 335.91 MiB (-0.07%)

@RalfJung RalfJung deleted the gvn-miscompile branch November 28, 2024 06:39
@rylev
Copy link
Member

rylev commented Dec 4, 2024

@RalfJung I'm doing perf triage and noticed you ran perf, had regressions, but didn't come on why this regressions are acceptable in this case. Could you indicate why the regression here is acceptable?

@compiler-errors
Copy link
Member

@rylev: this fixes a miscompilation due to an unsound MIR optimization which is disabled in this PR.

@rylev
Copy link
Member

rylev commented Dec 4, 2024

Figured that the answer was "correctness over performance", but I just wanted to double check 😄

@rustbot label: +perf-regression-triaged

@rustbot rustbot added the perf-regression-triaged The performance regression has been triaged. label Dec 4, 2024
@RalfJung
Copy link
Member Author

RalfJung commented Dec 4, 2024

Well also overall this was an improvement, no?

@Kobzol
Copy link
Contributor

Kobzol commented Dec 4, 2024

The regex win seems genuine, the html5ever was perhaps only codegen noise, as it bumped back soon after (in #123244, which had a large perf. effect though, so it could have been truly caused by that PR).
image

Numerically it was a win, yeah :)

bors added a commit to rust-lang-ci/rust that referenced this pull request Dec 20, 2024
Invalidate all dereferences when encountering non-local assignments

Fixes rust-lang#132353.

This PR removes the computation value by traversing SSA locals through `for_each_assignment_mut`.

Because the `for_each_assignment_mut` traversal skips statements which have side effects, such as dereference assignments, the computation may be unsound. Instead of `for_each_assignment_mut`, we compute values by traversing in reverse postorder.

Because we compute and use the symbolic representation of values on the fly, I invalidate all old values when encountering a dereference assignment. The current approach does not prevent the optimization of a clone to a copy.

In the future, we may add an alias model, or dominance information for dereference assignments, or SSA form to help GVN.

r? cjgillot

cc `@jieyouxu` rust-lang#132356
cc `@RalfJung` rust-lang#133474
bors added a commit to rust-lang-ci/rust that referenced this pull request Dec 21, 2024
Invalidate all dereferences when encountering non-local assignments

Fixes rust-lang#132353.

This PR removes the computation value by traversing SSA locals through `for_each_assignment_mut`.

Because the `for_each_assignment_mut` traversal skips statements which have side effects, such as dereference assignments, the computation may be unsound. Instead of `for_each_assignment_mut`, we compute values by traversing in reverse postorder.

Because we compute and use the symbolic representation of values on the fly, I invalidate all old values when encountering a dereference assignment. The current approach does not prevent the optimization of a clone to a copy.

In the future, we may add an alias model, or dominance information for dereference assignments, or SSA form to help GVN.

r? cjgillot

cc `@jieyouxu` rust-lang#132356
cc `@RalfJung` rust-lang#133474

try-job: x86_64-mingw-1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
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.

Miscompile in the GVN transform
9 participants