Skip to content

[TOY] Extend GVN to perform local value numbering. #143333

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

Draft
wants to merge 14 commits into
base: master
Choose a base branch
from

Conversation

cjgillot
Copy link
Contributor

@cjgillot cjgillot commented Jul 2, 2025

This PR is more a toy than anything else, but I still think the implementation is sound.

Current GVN MIR opt can be easily extended to track values that change inside a basic block. This PR attempts that.

r? @ghost for perf

@rustbot rustbot added the T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. label Jul 2, 2025
@rust-log-analyzer

This comment has been minimized.

@cjgillot cjgillot force-pushed the local-value-numbering branch from c7dac45 to 62766e3 Compare July 2, 2025 22:11
@rust-log-analyzer

This comment has been minimized.

@rust-log-analyzer

This comment has been minimized.

@cjgillot cjgillot added the A-mir-opt-GVN Area: MIR opt Global Value Numbering (GVN) label Jul 5, 2025
@cjgillot
Copy link
Contributor Author

cjgillot commented Jul 5, 2025

@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 Jul 5, 2025
bors added a commit that referenced this pull request Jul 5, 2025
[TOY] Extend GVN to perform local value numbering.

This PR is more a toy than anything else, but I still think the implementation is sound.

Current GVN MIR opt can be easily extended to track values that change inside a basic block. This PR attempts that.

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

bors commented Jul 5, 2025

⌛ Trying commit c3be10b with merge faceb52...

@bors
Copy link
Collaborator

bors commented Jul 5, 2025

☀️ Try build successful - checks-actions
Build commit: faceb52 (faceb52e72c06f94883ba351a73c83544ab4154b)

@rust-timer

This comment has been minimized.

@rust-timer
Copy link
Collaborator

Finished benchmarking commit (faceb52): 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)
15.4% [0.2%, 937.4%] 227
Regressions ❌
(secondary)
10.3% [0.2%, 569.6%] 237
Improvements ✅
(primary)
-1.1% [-1.8%, -0.4%] 2
Improvements ✅
(secondary)
-1.3% [-4.1%, -0.3%] 16
All ❌✅ (primary) 15.3% [-1.8%, 937.4%] 229

Max RSS (memory usage)

Results (primary 9.1%, secondary 2.4%)

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

mean range count
Regressions ❌
(primary)
71.9% [1.6%, 377.4%] 14
Regressions ❌
(secondary)
28.4% [2.2%, 134.5%] 15
Improvements ✅
(primary)
-2.0% [-7.5%, -0.7%] 79
Improvements ✅
(secondary)
-2.5% [-3.5%, -0.8%] 80
All ❌✅ (primary) 9.1% [-7.5%, 377.4%] 93

Cycles

Results (primary 44.8%, secondary 29.7%)

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

mean range count
Regressions ❌
(primary)
46.5% [2.3%, 299.4%] 27
Regressions ❌
(secondary)
40.6% [2.4%, 263.2%] 28
Improvements ✅
(primary)
-2.1% [-2.1%, -2.1%] 1
Improvements ✅
(secondary)
-4.2% [-6.7%, -2.4%] 9
All ❌✅ (primary) 44.8% [-2.1%, 299.4%] 28

Binary size

Results (primary -0.1%, secondary 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.2% [0.0%, 0.6%] 37
Regressions ❌
(secondary)
0.5% [0.0%, 1.7%] 70
Improvements ✅
(primary)
-0.3% [-1.3%, -0.0%] 54
Improvements ✅
(secondary)
-1.0% [-12.8%, -0.0%] 24
All ❌✅ (primary) -0.1% [-1.3%, 0.6%] 91

Bootstrap: 458.797s -> 582.037s (26.86%)
Artifact size: 372.11 MiB -> 361.76 MiB (-2.78%)

@rustbot rustbot added perf-regression Performance regression. and removed S-waiting-on-perf Status: Waiting on a perf run to be completed. labels Jul 5, 2025
@cjgillot cjgillot force-pushed the local-value-numbering branch from c3be10b to e521268 Compare July 6, 2025 08:54
@cjgillot
Copy link
Contributor Author

cjgillot commented Jul 6, 2025

@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 Jul 6, 2025
bors added a commit that referenced this pull request Jul 6, 2025
[TOY] Extend GVN to perform local value numbering.

This PR is more a toy than anything else, but I still think the implementation is sound.

Current GVN MIR opt can be easily extended to track values that change inside a basic block. This PR attempts that.

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

bors commented Jul 6, 2025

⌛ Trying commit e521268 with merge dc4aa90...

@cjgillot cjgillot force-pushed the local-value-numbering branch from e521268 to 0293254 Compare July 6, 2025 08:55
@cjgillot
Copy link
Contributor Author

cjgillot commented Jul 6, 2025

@bors try @rust-timer queue

@rust-timer

This comment has been minimized.

bors added a commit that referenced this pull request Jul 6, 2025
[TOY] Extend GVN to perform local value numbering.

This PR is more a toy than anything else, but I still think the implementation is sound.

Current GVN MIR opt can be easily extended to track values that change inside a basic block. This PR attempts that.

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

bors commented Jul 6, 2025

⌛ Trying commit 0293254 with merge 4d16c54...

@rust-log-analyzer
Copy link
Collaborator

The job pr-check-2 failed! Check out the build log: (web) (plain enhanced) (plain)

Click to see the possible cause of the failure (guessed by this bot)
    Checking rustc_mir_transform v0.0.0 (/checkout/compiler/rustc_mir_transform)
[RUSTC-TIMING] rustc_codegen_llvm test:false 3.796
    Checking rustc_passes v0.0.0 (/checkout/compiler/rustc_passes)
[RUSTC-TIMING] rustc_passes test:false 1.696
error[E0609]: no field `non_ssa` on type `(&VnIndex, &SmallVec<[(rustc_middle::mir::Local, rustc_middle::mir::Location); 1]>)`
   --> compiler/rustc_mir_transform/src/gvn.rs:398:45
    |
398 |                 for (other, _) in local_vec.non_ssa {
    |                                             ^^^^^^^ unknown field

For more information about this error, try `rustc --explain E0609`.
[RUSTC-TIMING] rustc_mir_transform test:false 3.904
error: could not compile `rustc_mir_transform` (lib) due to 1 previous error

@bors
Copy link
Collaborator

bors commented Jul 6, 2025

☀️ Try build successful - checks-actions
Build commit: 4d16c54 (4d16c544e50b0f84cc5347467c108e93106aa8f9)

@rust-timer

This comment has been minimized.

@Kobzol
Copy link
Member

Kobzol commented Jul 6, 2025

Note: we had some network issues on the collector and this benchmark was restarted multiple times. I hope that it didn't affect the results, but in case it comes out weirdly, I'd rerun it (this PR would probably have "weird" results anyway though 😆).

@rust-timer
Copy link
Collaborator

Finished benchmarking commit (4d16c54): 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)
3.1% [0.1%, 24.5%] 33
Regressions ❌
(secondary)
3.2% [0.0%, 21.9%] 27
Improvements ✅
(primary)
-0.4% [-2.1%, -0.2%] 12
Improvements ✅
(secondary)
-0.4% [-0.9%, -0.1%] 55
All ❌✅ (primary) 2.2% [-2.1%, 24.5%] 45

Max RSS (memory usage)

Results (primary 48.7%, secondary 33.4%)

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

mean range count
Regressions ❌
(primary)
57.1% [1.0%, 382.4%] 18
Regressions ❌
(secondary)
51.3% [2.8%, 136.0%] 8
Improvements ✅
(primary)
-1.8% [-2.5%, -1.4%] 3
Improvements ✅
(secondary)
-2.3% [-2.6%, -2.1%] 4
All ❌✅ (primary) 48.7% [-2.5%, 382.4%] 21

Cycles

Results (primary 8.6%, secondary 14.5%)

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

mean range count
Regressions ❌
(primary)
10.9% [1.4%, 36.5%] 10
Regressions ❌
(secondary)
14.5% [2.8%, 34.4%] 7
Improvements ✅
(primary)
-2.5% [-2.7%, -2.3%] 2
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) 8.6% [-2.7%, 36.5%] 12

Binary size

Results (primary -0.1%, secondary -0.7%)

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

mean range count
Regressions ❌
(primary)
0.4% [0.0%, 1.0%] 3
Regressions ❌
(secondary)
0.2% [0.1%, 0.5%] 4
Improvements ✅
(primary)
-0.1% [-0.7%, -0.0%] 51
Improvements ✅
(secondary)
-0.9% [-13.0%, -0.0%] 17
All ❌✅ (primary) -0.1% [-0.7%, 1.0%] 54

Bootstrap: 460.756s -> 480.789s (4.35%)
Artifact size: 372.14 MiB -> 371.68 MiB (-0.12%)

@rustbot rustbot removed the S-waiting-on-perf Status: Waiting on a perf run to be completed. label Jul 6, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-mir-opt-GVN Area: MIR opt Global Value Numbering (GVN) 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.

6 participants