Skip to content

Conversation

dianqk
Copy link
Member

@dianqk dianqk commented Oct 18, 2025

Fixes #141313 and #141313 (comment).

We should always use VnIndex when dereferencing an address in GVN.

r? cjgillot
r? tmiasko (since you found that)

@rustbot
Copy link
Collaborator

rustbot commented Oct 18, 2025

Some changes occurred to MIR optimizations

cc @rust-lang/wg-mir-opt

@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 Oct 18, 2025
if let Value::Address { base, projection, .. } = self.get(value)
&& let Some(value) = self.dereference_address(base, projection)
{
if let Value::Address { base, projection, .. } = self.get(value) {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't have a test for projection, but projection should also be able to invalidate values.

@dianqk
Copy link
Member Author

dianqk commented Oct 18, 2025

@bors try @rust-timer queue

@rust-timer

This comment has been minimized.

@rust-bors

This comment has been minimized.

rust-bors bot added a commit that referenced this pull request Oct 18, 2025
GVN: Bail out if the address cannot be dereferenced.
@rustbot rustbot added the S-waiting-on-perf Status: Waiting on a perf run to be completed. label Oct 18, 2025
@rust-bors
Copy link

rust-bors bot commented Oct 18, 2025

☀️ Try build successful (CI)
Build commit: c5a0b2c (c5a0b2c28ca4b44acfc5036fac4e8a95025e5fe4, parent: c8a31b780d5415358566a20b94912620a3f27067)

@rust-timer

This comment has been minimized.

@cjgillot
Copy link
Contributor

I'm a bit worried we are not addressing the root issue.

We can reason with the value behind a reference because it is UB to directly assign to the underlying local while the reference is live. We allow creating new derefs, this means extending the liveness of references, so we are creating UB.

Should we just ban introducing new derefs?

@rust-timer
Copy link
Collaborator

Finished benchmarking commit (c5a0b2c): comparison URL.

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

Benchmarking this pull request means it may be perf-sensitive – we'll automatically label it not fit for rolling up. You can override this, but we strongly advise not to, due to possible changes in compiler perf.

Next Steps: If you can justify the regressions found in this try perf run, please do so in sufficient writing along with @rustbot label: +perf-regression-triaged. If not, please fix the regressions and do another perf run. If its results are neutral or positive, the label will be automatically removed.

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

Instruction count

Our most reliable metric. Used to determine the overall result above. However, even this metric can be noisy.

mean range count
Regressions ❌
(primary)
- - 0
Regressions ❌
(secondary)
0.2% [0.0%, 0.3%] 2
Improvements ✅
(primary)
-0.5% [-0.5%, -0.5%] 1
Improvements ✅
(secondary)
-0.4% [-1.1%, -0.1%] 4
All ❌✅ (primary) -0.5% [-0.5%, -0.5%] 1

Max RSS (memory usage)

Results (secondary 3.3%)

A less reliable metric. May be of interest, but not used to determine the overall result above.

mean range count
Regressions ❌
(primary)
- - 0
Regressions ❌
(secondary)
4.4% [2.0%, 6.0%] 12
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
-3.0% [-3.0%, -3.0%] 2
All ❌✅ (primary) - - 0

Cycles

Results (secondary -1.2%)

A less reliable metric. May be of interest, but not used to determine the overall result above.

mean range count
Regressions ❌
(primary)
- - 0
Regressions ❌
(secondary)
6.5% [2.5%, 9.7%] 5
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
-5.1% [-10.5%, -1.6%] 10
All ❌✅ (primary) - - 0

Binary size

Results (primary -0.1%)

A less reliable metric. May be of interest, but not used to determine the overall result above.

mean range count
Regressions ❌
(primary)
0.1% [0.0%, 0.1%] 3
Regressions ❌
(secondary)
- - 0
Improvements ✅
(primary)
-0.2% [-0.2%, -0.1%] 4
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) -0.1% [-0.2%, 0.1%] 7

Bootstrap: 473.714s -> 474.328s (0.13%)
Artifact size: 390.54 MiB -> 390.33 MiB (-0.05%)

@rustbot rustbot added perf-regression Performance regression. and removed S-waiting-on-perf Status: Waiting on a perf run to be completed. labels Oct 18, 2025
@dianqk
Copy link
Member Author

dianqk commented Oct 19, 2025

I'm a bit worried we are not addressing the root issue.

We can reason with the value behind a reference because it is UB to directly assign to the underlying local while the reference is live. We allow creating new derefs, this means extending the liveness of references, so we are creating UB.

Should we just ban introducing new derefs?

Closing in favor of #147886.

@dianqk dianqk closed this Oct 19, 2025
@rustbot rustbot removed the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Oct 19, 2025
@dianqk dianqk deleted the gvn-deref-ssa branch October 19, 2025 13:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

perf-regression Performance regression. 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.

GVN misunderstands aliasing, can create overlapping assignments (again)

5 participants