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

Extend uninhabited enum variant branch elimination to also affect fallthrough #93387

Merged
merged 2 commits into from
Feb 20, 2022

Conversation

JakobDegen
Copy link
Contributor

The uninhabited_enum_branching mir opt eliminates branches on variants where the data is uninhabited. This change extends this pass to also ensure that the otherwise case points to a trivially unreachable bb if all inhabited variants are present in the non-otherwise branches.

I believe it was @scottmcm who said that LLVM eliminates some of this information in its SimplifyCFG pass. This is unfortunate, but this change should still be at least a small improvement in principle (I don't think it will show up on any benchmarks)

@rustbot rustbot added the T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. label Jan 27, 2022
@rust-highfive
Copy link
Collaborator

r? @jackh726

(rust-highfive has picked a reviewer for you, use r? to override)

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Jan 27, 2022
@rust-log-analyzer

This comment has been minimized.

@scottmcm
Copy link
Member

Here's the comment from the person who looked into why LLVM loses this info sometimes: #85133 (comment)

That said, I do agree that making things obviously-unreachable in MIR is a good thing to do.

I'm not really qualified to review this, but I can kick off a
@bors try @rust-timer queue

@rust-timer
Copy link
Collaborator

Awaiting bors try build completion.

@rustbot label: +S-waiting-on-perf

@rustbot rustbot added the S-waiting-on-perf Status: Waiting on a perf run to be completed. label Jan 27, 2022
@bors
Copy link
Contributor

bors commented Jan 27, 2022

⌛ Trying commit 27fa2feeb89a79f0b595199e5e5052d36c81335b with merge e8eeaa2ec2ea8a30bafceccf825f0ab85c50eaa0...

let otherwise = targets.otherwise();
let bb = &body.basic_blocks()[otherwise];
if bb.statements.len() == 0
&& bb.terminator().kind == TerminatorKind::Unreachable
Copy link
Member

Choose a reason for hiding this comment

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

I always wonder about StorageLive/Dead in these.

Would it make sense for this to be, say,

    if bb.terminator().kind == TerminatorKind::Unreachable
        && !bb.is_cleanup
        && bb.statements.iter().all(|s| matches!(&s.kind, StatementKind::StorageDead(_))) {

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Probably? I'll wait for Wesley to take a look

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I've changed this for now since I was fixing the other thing, but can revert this if there's a reason to prefer the other way around

@jackh726
Copy link
Member

Also not qualified to review this. r? rust-lang/mir-opt

@bors
Copy link
Contributor

bors commented Jan 27, 2022

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

@rust-timer
Copy link
Collaborator

Queued e8eeaa2ec2ea8a30bafceccf825f0ab85c50eaa0 with parent 21b4a9c, future comparison URL.

@rust-timer
Copy link
Collaborator

Finished benchmarking commit (e8eeaa2ec2ea8a30bafceccf825f0ab85c50eaa0): comparison url.

Summary: This benchmark run did not return any relevant results. 2 results were found to be statistically significant but too small to be relevant.

If you disagree with this performance assessment, please file an issue in rust-lang/rustc-perf.

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 led to changes in compiler perf.

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

@rustbot rustbot removed the S-waiting-on-perf Status: Waiting on a perf run to be completed. label Jan 27, 2022
@rust-log-analyzer

This comment has been minimized.

…ugh.

The `uninhabited_enum_branch` miropt now also checks whether the fallthrough
case is inhabited, and if not will ensure that it points to an unreachable
block.
@tmiasko
Copy link
Contributor

tmiasko commented Feb 18, 2022

Thanks.

@bors r+ rollup=never

@bors
Copy link
Contributor

bors commented Feb 18, 2022

📌 Commit 0783009 has been approved by tmiasko

@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 Feb 18, 2022
@bors
Copy link
Contributor

bors commented Feb 19, 2022

⌛ Testing commit 0783009 with merge 26381c0af57c9f901af488e59a0c2bee8de610f1...

@rust-log-analyzer
Copy link
Collaborator

A job failed! Check out the build log: (web) (plain)

Click to see the possible cause of the failure (guessed by this bot)

@bors
Copy link
Contributor

bors commented Feb 19, 2022

💔 Test failed - checks-actions

@bors bors added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. labels Feb 19, 2022
@tmiasko
Copy link
Contributor

tmiasko commented Feb 19, 2022

@bors retry x86_64-apple-2 failure without logs

@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 Feb 19, 2022
@bors
Copy link
Contributor

bors commented Feb 20, 2022

⌛ Testing commit 0783009 with merge a6fe969...

@bors
Copy link
Contributor

bors commented Feb 20, 2022

☀️ Test successful - checks-actions
Approved by: tmiasko
Pushing a6fe969 to master...

@bors bors added the merged-by-bors This PR was explicitly merged by bors. label Feb 20, 2022
@bors bors merged commit a6fe969 into rust-lang:master Feb 20, 2022
@rustbot rustbot added this to the 1.61.0 milestone Feb 20, 2022
@rust-timer
Copy link
Collaborator

Finished benchmarking commit (a6fe969): comparison url.

Summary: This benchmark run did not return any relevant results. 3 results were found to be statistically significant but too small to be relevant.

If you disagree with this performance assessment, please file an issue in rust-lang/rustc-perf.

@rustbot label: -perf-regression

@JakobDegen JakobDegen deleted the improve_partialeq branch March 5, 2022 02:26
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.

10 participants