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

Don't alloca for unused locals #129283

Merged
merged 3 commits into from
Sep 21, 2024
Merged

Conversation

saethlin
Copy link
Member

@saethlin saethlin commented Aug 19, 2024

We already have a concept of mono-unreachable basic blocks; this is primarily useful for ensuring that we do not compile code under an if false. But since we never gave locals the same analysis, a large local only used under an if false will still have stack space allocated for it.

There are 3 places we traverse MIR during monomorphization: Inside the collector, non_ssa_locals, and the walk to generate code. Unfortunately, #129283 (comment) indicates that we cannot afford the expense of tracking reachable locals during the collector's traversal, so we do need at least two mono-reachable traversals. And of course caching is of no help here because the benchmarks that regress are incr-unchanged; they don't do any codegen.

This fixes the second problem in #129282, and brings us anther step toward const if at home.

@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 Aug 19, 2024
@saethlin
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 Aug 19, 2024
@bors
Copy link
Contributor

bors commented Aug 19, 2024

⌛ Trying commit 8df3ccc with merge f383908...

bors added a commit to rust-lang-ci/rust that referenced this pull request Aug 19, 2024
Don't alloca for unused locals

This fixes the second problem in rust-lang#129282

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

This comment has been minimized.

@rust-log-analyzer

This comment has been minimized.

@bors
Copy link
Contributor

bors commented Aug 19, 2024

💔 Test failed - checks-actions

@bors bors added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Aug 19, 2024
@saethlin
Copy link
Member Author

@bors try @rust-timer queue

@rust-timer

This comment has been minimized.

@bors
Copy link
Contributor

bors commented Aug 20, 2024

⌛ Trying commit f98c04d with merge 2d91c0b...

bors added a commit to rust-lang-ci/rust that referenced this pull request Aug 20, 2024
Don't alloca for unused locals

This fixes the second problem in rust-lang#129282

r? `@ghost`
@bors
Copy link
Contributor

bors commented Aug 20, 2024

☀️ Try build successful - checks-actions
Build commit: 2d91c0b (2d91c0b2cd023747941053983f33c4f2753436cd)

@rust-timer

This comment has been minimized.

@rust-timer
Copy link
Collaborator

Finished benchmarking commit (2d91c0b): comparison URL.

Overall result: ❌ regressions - 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.5% [0.2%, 0.9%] 29
Regressions ❌
(secondary)
1.0% [0.4%, 2.4%] 4
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) 0.5% [0.2%, 0.9%] 29

Max RSS (memory usage)

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

Cycles

Results (primary 1.5%, secondary 1.7%)

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)
1.7% [1.7%, 1.7%] 1
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) 1.5% [1.5%, 1.5%] 1

Binary size

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

Bootstrap: 751.143s -> 748.981s (-0.29%)
Artifact size: 338.64 MiB -> 338.75 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 Aug 20, 2024
@saethlin saethlin force-pushed the unreachable-allocas branch 2 times, most recently from 8f4ba1a to 66653dc Compare August 21, 2024 01:16
@saethlin
Copy link
Member Author

The code definitely needs a lot of cleaning-up, but I want to know if this is faster. It should be.

@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 Aug 21, 2024
@bors
Copy link
Contributor

bors commented Aug 21, 2024

⌛ Trying commit 66653dc with merge 6eddbec...

bors added a commit to rust-lang-ci/rust that referenced this pull request Aug 21, 2024
Don't alloca for unused locals

We already have a concept of mono-unreachable basic blocks; this is primarily useful for ensuring that we do not compile code under an `if false`. But since we never gave locals the same analysis, a large local only used under an `if false` will still have stack space allocated for it.

There are 3 places we traverse MIR during monomorphization: Inside the collector, `non_ssa_locals`, and the walk to generate code. Unfortunately, rust-lang#129283 (comment) indicates that we cannot afford the expense of tracking reachable locals during the collector's traversal, so we do need at least two mono-reachable traversals. And of course caching is of no help here because the benchmarks that regress are incr-unchanged; they don't do any codegen.

This fixes the second problem in rust-lang#129282, and brings us anther step toward `const if` at home.
@bors bors added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Sep 21, 2024
@saethlin
Copy link
Member Author

@bors try

@bors
Copy link
Contributor

bors commented Sep 21, 2024

⌛ Trying commit 338965b with merge 2f48442...

bors added a commit to rust-lang-ci/rust that referenced this pull request Sep 21, 2024
Don't alloca for unused locals

We already have a concept of mono-unreachable basic blocks; this is primarily useful for ensuring that we do not compile code under an `if false`. But since we never gave locals the same analysis, a large local only used under an `if false` will still have stack space allocated for it.

There are 3 places we traverse MIR during monomorphization: Inside the collector, `non_ssa_locals`, and the walk to generate code. Unfortunately, rust-lang#129283 (comment) indicates that we cannot afford the expense of tracking reachable locals during the collector's traversal, so we do need at least two mono-reachable traversals. And of course caching is of no help here because the benchmarks that regress are incr-unchanged; they don't do any codegen.

This fixes the second problem in rust-lang#129282, and brings us anther step toward `const if` at home.

try-job: test-various
@rust-log-analyzer

This comment has been minimized.

@rust-log-analyzer

This comment has been minimized.

@bors
Copy link
Contributor

bors commented Sep 21, 2024

💔 Test failed - checks-actions

@bors bors added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Sep 21, 2024
@saethlin
Copy link
Member Author

@bors try

@bors
Copy link
Contributor

bors commented Sep 21, 2024

⌛ Trying commit aa28ee1 with merge bcce48a...

bors added a commit to rust-lang-ci/rust that referenced this pull request Sep 21, 2024
Don't alloca for unused locals

We already have a concept of mono-unreachable basic blocks; this is primarily useful for ensuring that we do not compile code under an `if false`. But since we never gave locals the same analysis, a large local only used under an `if false` will still have stack space allocated for it.

There are 3 places we traverse MIR during monomorphization: Inside the collector, `non_ssa_locals`, and the walk to generate code. Unfortunately, rust-lang#129283 (comment) indicates that we cannot afford the expense of tracking reachable locals during the collector's traversal, so we do need at least two mono-reachable traversals. And of course caching is of no help here because the benchmarks that regress are incr-unchanged; they don't do any codegen.

This fixes the second problem in rust-lang#129282, and brings us anther step toward `const if` at home.

try-job: test-various
@bors
Copy link
Contributor

bors commented Sep 21, 2024

☀️ Try build successful - checks-actions
Build commit: bcce48a (bcce48ade5140371744b528196923f97b58a3d1c)

@saethlin
Copy link
Member Author

@bors r=scottmcm

@bors
Copy link
Contributor

bors commented Sep 21, 2024

📌 Commit aa28ee1 has been approved by scottmcm

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-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Sep 21, 2024
@bors
Copy link
Contributor

bors commented Sep 21, 2024

⌛ Testing commit aa28ee1 with merge 2836482...

@bors
Copy link
Contributor

bors commented Sep 21, 2024

☀️ Test successful - checks-actions
Approved by: scottmcm
Pushing 2836482 to master...

@bors bors added the merged-by-bors This PR was explicitly merged by bors. label Sep 21, 2024
@bors bors merged commit 2836482 into rust-lang:master Sep 21, 2024
7 checks passed
@rustbot rustbot added this to the 1.83.0 milestone Sep 21, 2024
@saethlin saethlin deleted the unreachable-allocas branch September 21, 2024 16:29
@rust-timer
Copy link
Collaborator

Finished benchmarking commit (2836482): comparison URL.

Overall result: no relevant changes - no action needed

@rustbot label: -perf-regression

Instruction count

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

Max RSS (memory usage)

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

Cycles

Results (secondary -1.9%)

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)
-1.9% [-1.9%, -1.9%] 1
All ❌✅ (primary) - - 0

Binary size

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

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.1% [-0.1%, -0.0%] 35
Improvements ✅
(secondary)
-0.3% [-0.4%, -0.1%] 6
All ❌✅ (primary) -0.1% [-0.1%, -0.0%] 35

Bootstrap: 768.677s -> 767.545s (-0.15%)
Artifact size: 341.36 MiB -> 341.42 MiB (0.02%)

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

8 participants