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 consider &mut *x as mutating x in CopyProp #108178

Merged
merged 2 commits into from
Mar 9, 2023

Conversation

cjgillot
Copy link
Contributor

@cjgillot cjgillot commented Feb 17, 2023

This PR removes an unfortunate overly cautious case from the current implementation.

Found by #105274 cc @saethlin

@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 Feb 17, 2023
@rustbot
Copy link
Collaborator

rustbot commented Feb 17, 2023

Some changes occurred to MIR optimizations

cc @rust-lang/wg-mir-opt

@saethlin
Copy link
Member

Nobody got assigned automatically 🤔 should someone be?

@cjgillot
Copy link
Contributor 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 Feb 17, 2023
@bors
Copy link
Contributor

bors commented Feb 17, 2023

⌛ Trying commit 69a2d71e17b2821a445730d2360331e38229af2e with merge 0e92e4b96312299b07d11647a466dc737e5207c3...

@bors
Copy link
Contributor

bors commented Feb 18, 2023

☀️ Try build successful - checks-actions
Build commit: 0e92e4b96312299b07d11647a466dc737e5207c3 (0e92e4b96312299b07d11647a466dc737e5207c3)

@rust-timer

This comment has been minimized.

@saethlin
Copy link
Member

FYI this perf run does not include #105274 which might be relevant.

@rust-timer
Copy link
Collaborator

Finished benchmarking commit (0e92e4b96312299b07d11647a466dc737e5207c3): comparison URL.

Overall result: no relevant changes - no 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.

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

Instruction count

This benchmark run did not return any relevant results for this metric.

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)
3.8% [3.8%, 3.8%] 1
Regressions ❌
(secondary)
3.6% [3.6%, 3.6%] 1
Improvements ✅
(primary)
-3.1% [-3.1%, -3.1%] 2
Improvements ✅
(secondary)
-2.6% [-3.8%, -1.0%] 19
All ❌✅ (primary) -0.8% [-3.1%, 3.8%] 3

Cycles

This benchmark run did not return any relevant results for this metric.

@rustbot rustbot removed the S-waiting-on-perf Status: Waiting on a perf run to be completed. label Feb 18, 2023
@cjgillot
Copy link
Contributor Author

Now that #105274 is merged.
@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 Feb 18, 2023
@bors
Copy link
Contributor

bors commented Feb 18, 2023

⌛ Trying commit 69a2d71e17b2821a445730d2360331e38229af2e with merge 2894f9ae226ad439e75cb76ad98f6811eb326247...

@bors
Copy link
Contributor

bors commented Feb 18, 2023

☀️ Try build successful - checks-actions
Build commit: 2894f9ae226ad439e75cb76ad98f6811eb326247 (2894f9ae226ad439e75cb76ad98f6811eb326247)

@rust-timer

This comment has been minimized.

@rust-timer
Copy link
Collaborator

Finished benchmarking commit (2894f9ae226ad439e75cb76ad98f6811eb326247): 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.9% [0.8%, 1.0%] 2
Regressions ❌
(secondary)
1.3% [1.3%, 1.3%] 1
Improvements ✅
(primary)
-0.3% [-0.4%, -0.3%] 3
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) 0.1% [-0.4%, 1.0%] 5

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)
5.0% [3.4%, 6.6%] 2
Regressions ❌
(secondary)
4.2% [4.2%, 4.2%] 1
Improvements ✅
(primary)
-2.2% [-3.3%, -0.1%] 4
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) 0.2% [-3.3%, 6.6%] 6

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
Regressions ❌
(secondary)
- - 0
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
-6.3% [-7.1%, -5.6%] 6
All ❌✅ (primary) - - 0

@rustbot rustbot added perf-regression Performance regression. and removed S-waiting-on-perf Status: Waiting on a perf run to be completed. labels Feb 18, 2023
@cjgillot
Copy link
Contributor Author

r? compiler

@saethlin
Copy link
Member

Does &raw mut *x deserve the same treatment?

@cjgillot
Copy link
Contributor Author

This patch handles both cases by considering that a mutation of '*x' is not a mutation of 'x'.

@eholk
Copy link
Contributor

eholk commented Feb 21, 2023

@RalfJung - Does this change have any stacked borrows implications?

@bors r? @JakobDegen

@rustbot
Copy link
Collaborator

rustbot commented Feb 21, 2023

Failed to set assignee to JakobDegen: invalid assignee

Note: Only org members, users with write permissions, or people who have commented on the PR may be assigned.

@eholk
Copy link
Contributor

eholk commented Feb 21, 2023

I took a quick look over the PR, and it seems reasonable to me, but I'd rather someone who knows this code better sign off.

@bors r? @wesleywiser

@rustbot rustbot assigned wesleywiser and unassigned eholk Feb 21, 2023
@RalfJung
Copy link
Member

RalfJung commented Mar 1, 2023

Does this change have any stacked borrows implications?

That's hard to say without reverse engineering CopyProp. @cjgillot could you describe with some examples which new transformations this entails?

Stacked Borrows currently does consider &mut *x to be a write to x. Tree Borrows does not. But this is a pretty fundamental trade-off; Tree Borrows loses some optimizations due to this choice. However it's hard for me to say whether that is even relevant for CopyProp.

@cjgillot
Copy link
Contributor Author

cjgillot commented Mar 1, 2023

Basically, this allows to transform

_2 = _1
_3 = &mut *_1
_4 = _1
anything(_2, _4)

Into

_3 = &mut *_1
anything(_1, _1)

This would be allowed whatever the type of _1, either a reference or a raw pointer.
I don't see how SB considers &mut *x to write to x. I understand it changes the borrow stack global state, but I don't see where it writes to x, neither address nor provenance.

If we consider &mut *x to write to x, ie by modifying provenance, this transformation is incorrect.

@JakobDegen
Copy link
Contributor

Yeah, I feel pretty strongly that we need to allow this opt. The scenario in which it risks being wrong is if the _2 = _1 actually modifies the value - that can be the result of implicit retags, but we should just not do those.

@oli-obk
Copy link
Contributor

oli-obk commented Mar 8, 2023

@bors r+

r? @oli-obk

@rustbot rustbot assigned oli-obk and unassigned wesleywiser Mar 8, 2023
@bors
Copy link
Contributor

bors commented Mar 8, 2023

📌 Commit 209eb8a 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 Mar 8, 2023
@bors
Copy link
Contributor

bors commented Mar 9, 2023

⌛ Testing commit 209eb8a with merge 66a2d62...

@bors
Copy link
Contributor

bors commented Mar 9, 2023

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

@bors bors added the merged-by-bors This PR was explicitly merged by bors. label Mar 9, 2023
@bors bors merged commit 66a2d62 into rust-lang:master Mar 9, 2023
@rustbot rustbot added this to the 1.70.0 milestone Mar 9, 2023
@cjgillot cjgillot deleted the ssa-deref branch March 9, 2023 08:38
@rust-timer
Copy link
Collaborator

Finished benchmarking commit (66a2d62): 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.4% [0.2%, 1.0%] 18
Regressions ❌
(secondary)
0.4% [0.3%, 0.5%] 11
Improvements ✅
(primary)
-0.3% [-0.3%, -0.3%] 2
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) 0.3% [-0.3%, 1.0%] 20

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.1% [1.9%, 2.2%] 2
Regressions ❌
(secondary)
1.5% [1.5%, 1.5%] 2
Improvements ✅
(primary)
-4.0% [-4.8%, -3.3%] 2
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) -1.0% [-4.8%, 2.2%] 4

Cycles

This benchmark run did not return any relevant results for this metric.

@cjgillot
Copy link
Contributor Author

cjgillot commented Mar 9, 2023

The regression in opt builds comes from LLVM doing more work, which is expected.

The regression for serde_derive check is a change in how btree's search_tree over region constraints is codegened, and in the stable hasher.

@RalfJung
Copy link
Member

RalfJung commented Mar 9, 2023

Yeah, I feel pretty strongly that we need to allow this opt. The scenario in which it risks being wrong is if the _2 = _1 actually modifies the value - that can be the result of implicit retags, but we should just not do those.

Implicit retags on assignments specifically. I agree we shouldn't have those.

Retags on Rvalue::Ref are a different matter IMO. But those should be fine here.

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.