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

Consider empty-unreachable otherwise branches in MatchBranchSimplification #131244

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

clubby789
Copy link
Contributor

@clubby789 clubby789 commented Oct 4, 2024

Fixes #131219

@rustbot
Copy link
Collaborator

rustbot commented Oct 4, 2024

r? @jieyouxu

rustbot has assigned @jieyouxu.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

@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 4, 2024
@rustbot
Copy link
Collaborator

rustbot commented Oct 4, 2024

Some changes occurred to MIR optimizations

cc @rust-lang/wg-mir-opt

@clubby789 clubby789 changed the title Add diff test for MatchBranchSimplification Consider empty-unreachable otherwise branches in MatchBranchSimplification Oct 4, 2024
@jieyouxu
Copy link
Member

jieyouxu commented Oct 4, 2024

r? wg-mir-opt

@rustbot rustbot assigned wesleywiser and unassigned jieyouxu Oct 4, 2024
@clubby789
Copy link
Contributor Author

clubby789 commented Oct 4, 2024

Hmm, while I think this change is useful (given the improvement in another test), while checking the diffs I noticed that (on current master) the motivating example emits

fn my_is_some(_1: &Option<T>) -> bool {
    debug bar => _1;
    let mut _0: bool;
    let mut _2: isize;

    bb0: {
        _2 = discriminant((*_1));
        switchInt(move _2) -> [1: bb2, otherwise: bb1];   // two-branch SwitchInt, not 3
    }

    bb1: {
        _0 = const false;
        goto -> bb3;
    }

    bb2: {
        _0 = const true;
        goto -> bb3;
    }

    bb3: {
        return;
    }
}

And is therefore simplified by MatchBranchSimplification to the Eq version
Ah I see. At normal opt-levels, UnreachableEnumBranching adds the unreachable branch which inhibits this opt. Presumably the test runs with no other opts enabled, so the two-branch switch is simplified to an Eq

@rust-cloud-vms rust-cloud-vms bot force-pushed the match-branches-unreachable branch 3 times, most recently from e6f54ee to ba723e6 Compare October 4, 2024 20:34
- bb4: {
+ StorageLive(_3);
+ _3 = copy _2;
+ _0 = Ne(copy _3, const 0_isize);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Custom MIR limitations meant I couldn't have the branches in the same order, so this creates an Ne instead (unlike an Eq like the original demo)

@rust-log-analyzer

This comment has been minimized.

@rust-log-analyzer

This comment has been minimized.

@clubby789
Copy link
Contributor 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 Oct 27, 2024
bors added a commit to rust-lang-ci/rust that referenced this pull request Oct 27, 2024
…, r=<try>

Consider empty-unreachable otherwise branches in MatchBranchSimplification

Fixes rust-lang#131219
@bors
Copy link
Contributor

bors commented Oct 27, 2024

⌛ Trying commit 7cd33b8 with merge 20e541a...

@bors
Copy link
Contributor

bors commented Oct 27, 2024

☀️ Try build successful - checks-actions
Build commit: 20e541a (20e541ae5fc472867330cb73999e8ec1ffcb7b83)

@rust-timer

This comment has been minimized.

@rust-timer
Copy link
Collaborator

Finished benchmarking commit (20e541a): comparison URL.

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

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 the most reliable metric that we have; it was used to determine the overall result at the top of this comment. However, even this metric can sometimes exhibit noise.

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

Max RSS (memory usage)

Results (primary 4.7%, secondary -3.8%)

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)
4.7% [2.1%, 8.9%] 3
Regressions ❌
(secondary)
- - 0
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
-3.8% [-3.8%, -3.8%] 1
All ❌✅ (primary) 4.7% [2.1%, 8.9%] 3

Cycles

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

Binary size

Results (primary -0.0%, secondary -0.2%)

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.2% [0.0%, 1.0%] 11
Regressions ❌
(secondary)
- - 0
Improvements ✅
(primary)
-0.1% [-0.6%, -0.0%] 31
Improvements ✅
(secondary)
-0.2% [-0.3%, -0.0%] 5
All ❌✅ (primary) -0.0% [-0.6%, 1.0%] 42

Bootstrap: 783.769s -> 780.785s (-0.38%)
Artifact size: 333.67 MiB -> 333.62 MiB (-0.02%)

@rustbot rustbot added perf-regression Performance regression. and removed S-waiting-on-perf Status: Waiting on a perf run to be completed. labels Oct 27, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
perf-regression Performance regression. 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.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[MIR-opt] matches!(x, Some(_)) should simplify to Eq(Discriminant, Const)
7 participants