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

Avoid lowering code under dead SwitchInt targets #121421

Merged
merged 1 commit into from
Mar 13, 2024

Conversation

saethlin
Copy link
Member

@saethlin saethlin commented Feb 22, 2024

The objective of this PR is to detect and eliminate code which is guarded by an if false, even if that false is a constant which is not known until monomorphization, or is intrinsics::debug_assertions().

The effect of this is that we generate no LLVM IR the standard library's unsafe preconditions, when they are compiled in a build where they should be immediately optimized out. This mono-time optimization ensures that builds which disable debug assertions do not grow a linkage requirement against core, which compiler-builtins currently needs: #121552

This revives the codegen side of #91222 as planned in #120848.

@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 22, 2024
@saethlin
Copy link
Member Author

@bors try @rust-timer queue

@saethlin saethlin removed the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Feb 22, 2024
@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 22, 2024
bors added a commit to rust-lang-ci/rust that referenced this pull request Feb 22, 2024
Avoid lowering code under dead SwitchInt targets

r? `@ghost`

Reviving rust-lang#91222 per rust-lang#120848
@bors
Copy link
Contributor

bors commented Feb 22, 2024

⌛ Trying commit 2dcf095 with merge 3f638e0...

@rust-log-analyzer

This comment has been minimized.

@rust-log-analyzer

This comment has been minimized.

@bors
Copy link
Contributor

bors commented Feb 22, 2024

💔 Test failed - checks-actions

@bors bors added the S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. label Feb 22, 2024
@rust-log-analyzer

This comment has been minimized.

@saethlin
Copy link
Member Author

@bors try @rust-timer queue

@rust-timer

This comment has been minimized.

@bors
Copy link
Contributor

bors commented Feb 22, 2024

⌛ Trying commit 6b3d152 with merge b39e4ca...

bors added a commit to rust-lang-ci/rust that referenced this pull request Feb 22, 2024
Avoid lowering code under dead SwitchInt targets

r? `@ghost`

Reviving rust-lang#91222 per rust-lang#120848
@rust-log-analyzer

This comment has been minimized.

@rust-log-analyzer

This comment has been minimized.

@bors
Copy link
Contributor

bors commented Feb 22, 2024

💔 Test failed - checks-actions

@saethlin
Copy link
Member Author

@bors try @rust-timer queue

@rust-timer

This comment has been minimized.

@bors
Copy link
Contributor

bors commented Feb 22, 2024

⌛ Trying commit 127cb45 with merge b183b7a...

bors added a commit to rust-lang-ci/rust that referenced this pull request Feb 22, 2024
Avoid lowering code under dead SwitchInt targets

r? `@ghost`

Reviving rust-lang#91222 per rust-lang#120848
@rust-log-analyzer

This comment has been minimized.

@bors
Copy link
Contributor

bors commented Feb 22, 2024

☀️ Try build successful - checks-actions
Build commit: b183b7a (b183b7a248fcc8f8102bd2d19782bea9de6e3546)

@oli-obk
Copy link
Contributor

oli-obk commented Mar 13, 2024

@bors r+

@bors
Copy link
Contributor

bors commented Mar 13, 2024

📌 Commit 81d6304 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-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Mar 13, 2024
@saethlin
Copy link
Member Author

I just checked to see if this PR optimizes out all the panic calls from a compiler-builtins build with debug assertions off and optimizations off, and it looks to me like since #121662 landed, it does not. It isn't entirely clear to me how to fix this. I'll put up a PR in a bit with some suggestions, but I do not like them.

@bors
Copy link
Contributor

bors commented Mar 13, 2024

⌛ Testing commit 81d6304 with merge 5a6c1aa...

@bors
Copy link
Contributor

bors commented Mar 13, 2024

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

@bors bors added the merged-by-bors This PR was explicitly merged by bors. label Mar 13, 2024
@bors bors merged commit 5a6c1aa into rust-lang:master Mar 13, 2024
12 checks passed
@rustbot rustbot added this to the 1.78.0 milestone Mar 13, 2024
@rust-timer
Copy link
Collaborator

Finished benchmarking commit (5a6c1aa): comparison URL.

Overall result: ✅ improvements - no action needed

@rustbot label: -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
Regressions ❌
(secondary)
- - 0
Improvements ✅
(primary)
-0.8% [-0.8%, -0.8%] 1
Improvements ✅
(secondary)
-0.4% [-0.7%, -0.3%] 5
All ❌✅ (primary) -0.8% [-0.8%, -0.8%] 1

Max RSS (memory usage)

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

Cycles

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

Binary size

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.0% [-0.0%, -0.0%] 20
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) -0.0% [-0.0%, -0.0%] 20

Bootstrap: 674.552s -> 676.304s (0.26%)
Artifact size: 310.77 MiB -> 310.79 MiB (0.01%)

if reachable_blocks.contains(bb) {
fx.codegen_block(bb);
} else {
// This may have references to things we didn't monomorphize, so we
Copy link
Member

Choose a reason for hiding this comment

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

This may have references to things we didn't monomorphize

How is that possible? The collector should ensure that we monomorphize everything referenced in the MIR, even in unreachable parts of the MIR.

However it could be interesting to make use of reachable_blocks_in_mono in the collector, and thus avoid collecting the functions in dead basic blocks.

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 didn't fully update the comment from scottmcm's PR that I stole this from

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'm fixing this in #123272

Copy link
Contributor

@cjgillot cjgillot left a comment

Choose a reason for hiding this comment

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

Just saw a comment was never sent.

let mut set = BitSet::new_empty(self.basic_blocks.len());
self.reachable_blocks_in_mono_from(tcx, instance, &mut set, START_BLOCK);
set
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Could you move this to traversal.rs, and refactor the computation to use the standard worklist/visited set algo?

Copy link
Member Author

Choose a reason for hiding this comment

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

Implemented in #123272

bors added a commit to rust-lang-ci/rust that referenced this pull request Mar 31, 2024
…try>

Only collect mono items from reachable blocks

Fixes the wrong commented pointed out in: rust-lang#121421 (comment)
Moves the analysis to use the worklist strategy: rust-lang#121421 (comment)
Also fixes rust-lang#85836, using the same reachability analysis
bors added a commit to rust-lang-ci/rust that referenced this pull request Apr 1, 2024
…try>

Only collect mono items from reachable blocks

Fixes the wrong commented pointed out in: rust-lang#121421 (comment)
Moves the analysis to use the worklist strategy: rust-lang#121421 (comment)
Also fixes rust-lang#85836, using the same reachability analysis
bors added a commit to rust-lang-ci/rust that referenced this pull request Apr 1, 2024
…try>

Only collect mono items from reachable blocks

Fixes the wrong commented pointed out in: rust-lang#121421 (comment)
Moves the analysis to use the worklist strategy: rust-lang#121421 (comment)
Also fixes rust-lang#85836, using the same reachability analysis
bors added a commit to rust-lang-ci/rust that referenced this pull request Apr 2, 2024
…try>

Only collect mono items from reachable blocks

Fixes the wrong commented pointed out in: rust-lang#121421 (comment)
Moves the analysis to use the worklist strategy: rust-lang#121421 (comment)
Also fixes rust-lang#85836, using the same reachability analysis
bors added a commit to rust-lang-ci/rust that referenced this pull request Apr 2, 2024
…try>

Only collect mono items from reachable blocks

Fixes the wrong commented pointed out in: rust-lang#121421 (comment)
Moves the analysis to use the worklist strategy: rust-lang#121421 (comment)
Also fixes rust-lang#85836, using the same reachability analysis
bors added a commit to rust-lang-ci/rust that referenced this pull request Apr 2, 2024
…try>

Only collect mono items from reachable blocks

Fixes the wrong commented pointed out in: rust-lang#121421 (comment)
Moves the analysis to use the worklist strategy: rust-lang#121421 (comment)
Also fixes rust-lang#85836, using the same reachability analysis
bors added a commit to rust-lang-ci/rust that referenced this pull request Apr 7, 2024
…jgillot

Only collect mono items from reachable blocks

Fixes the wrong comment pointed out in: rust-lang#121421 (comment)
Moves the analysis to use the worklist strategy: rust-lang#121421 (comment)
Also fixes rust-lang#85836, using the same reachability analysis
bors added a commit to rust-lang-ci/rust that referenced this pull request Apr 9, 2024
…jgillot

Only collect mono items from reachable blocks

Fixes the wrong comment pointed out in: rust-lang#121421 (comment)
Moves the analysis to use the worklist strategy: rust-lang#121421 (comment)
Also fixes rust-lang#85836, using the same reachability analysis
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.

Debug builds of compiler_builtins fail to link due to references to precondition_check in libcore