Skip to content

mir-opt: execute MatchBranchSimplification after GVN #140115

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

Merged
merged 1 commit into from
May 6, 2025

Conversation

dianqk
Copy link
Member

@dianqk dianqk commented Apr 21, 2025

This can provide more opportunities for MatchBranchSimplification.

Currently, rustc does not optimize the following code into a single statement at mir-opt, and this PR fixes the first case.

pub fn match1(c: bool, v1: i32, v2: i32) -> i32 {
    if c { v1 - v2 } else { v1 - v2 }
}

pub fn match2(c: bool, v1: i32) -> i32 {
    if c { v1 - 1 } else { v1 - 1 }
}

https://rust.godbolt.org/z/Y8xPMjrfM

r? mir-opt

This can provide more opportunities for MatchBranchSimplification.
@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 Apr 21, 2025
@rustbot
Copy link
Collaborator

rustbot commented Apr 21, 2025

Some changes occurred to MIR optimizations

cc @rust-lang/wg-mir-opt

@dianqk
Copy link
Member Author

dianqk commented Apr 21, 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 Apr 21, 2025
bors added a commit to rust-lang-ci/rust that referenced this pull request Apr 21, 2025
mir-opt: execute MatchBranchSimplification after GVN

This can provide more opportunities for MatchBranchSimplification.

Currently, rustc does not optimize the following code into a single statement at mir-opt, and this PR fixes the first case.

```rust
pub fn match1(c: bool, v1: i32, v2: i32) -> i32 {
    if c { v1 - v2 } else { v1 - v2 }
}

pub fn match2(c: bool, v1: i32) -> i32 {
    if c { v1 - 1 } else { v1 - 1 }
}
```

https://rust.godbolt.org/z/Y8xPMjrfM

r? mir-opt
@bors
Copy link
Collaborator

bors commented Apr 21, 2025

⌛ Trying commit 5881b7c with merge 1aadc7f...

@bors
Copy link
Collaborator

bors commented Apr 21, 2025

☀️ Try build successful - checks-actions
Build commit: 1aadc7f (1aadc7fccd4d64783aa82b79a6e7df7f08f12787)

@rust-timer

This comment has been minimized.

@rust-timer
Copy link
Collaborator

Finished benchmarking commit (1aadc7f): comparison URL.

Overall result: no relevant changes - no 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.

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

Instruction count

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

Max RSS (memory usage)

Results (primary -0.2%, secondary -2.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)
3.0% [1.0%, 6.1%] 4
Regressions ❌
(secondary)
- - 0
Improvements ✅
(primary)
-2.4% [-6.3%, -0.5%] 6
Improvements ✅
(secondary)
-2.2% [-2.2%, -2.2%] 1
All ❌✅ (primary) -0.2% [-6.3%, 6.1%] 10

Cycles

Results (primary 0.5%)

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.5% [0.5%, 0.5%] 1
Regressions ❌
(secondary)
- - 0
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) 0.5% [0.5%, 0.5%] 1

Binary size

Results (primary 0.1%)

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.3% [0.1%, 0.5%] 6
Regressions ❌
(secondary)
- - 0
Improvements ✅
(primary)
-0.2% [-0.4%, -0.0%] 5
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) 0.1% [-0.4%, 0.5%] 11

Bootstrap: 773.608s -> 771.589s (-0.26%)
Artifact size: 365.05 MiB -> 365.07 MiB (0.01%)

@rustbot rustbot removed the S-waiting-on-perf Status: Waiting on a perf run to be completed. label Apr 21, 2025
@dianqk
Copy link
Member Author

dianqk commented May 5, 2025

r? mir-opt

@rustbot rustbot assigned oli-obk and unassigned wesleywiser May 5, 2025
@oli-obk
Copy link
Contributor

oli-obk commented May 5, 2025

@bors r+ rollup

@bors
Copy link
Collaborator

bors commented May 5, 2025

📌 Commit 5881b7c 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-review Status: Awaiting review from the assignee but also interested parties. labels May 5, 2025
GuillaumeGomez added a commit to GuillaumeGomez/rust that referenced this pull request May 5, 2025
mir-opt: execute MatchBranchSimplification after GVN

This can provide more opportunities for MatchBranchSimplification.

Currently, rustc does not optimize the following code into a single statement at mir-opt, and this PR fixes the first case.

```rust
pub fn match1(c: bool, v1: i32, v2: i32) -> i32 {
    if c { v1 - v2 } else { v1 - v2 }
}

pub fn match2(c: bool, v1: i32) -> i32 {
    if c { v1 - 1 } else { v1 - 1 }
}
```

https://rust.godbolt.org/z/Y8xPMjrfM

r? mir-opt
bors added a commit to rust-lang-ci/rust that referenced this pull request May 5, 2025
…llaumeGomez

Rollup of 11 pull requests

Successful merges:

 - rust-lang#139764 (Consistent trait bounds for ExtractIf Debug impls)
 - rust-lang#140035 (Implement RFC 3503: frontmatters)
 - rust-lang#140080 (mir-opt: Use one MirPatch in MatchBranchSimplification)
 - rust-lang#140115 (mir-opt: execute MatchBranchSimplification after GVN)
 - rust-lang#140357 (bypass linker configuration and cross target check on `x check`)
 - rust-lang#140374 (Resolve instance for SymFn in global/naked asm)
 - rust-lang#140393 (std: get rid of `sys_common::process`)
 - rust-lang#140532 (Fix RustAnalyzer discovery of rustc's `stable_mir` crate)
 - rust-lang#140559 (Removing rustc_type_ir in the rustc_infer codebase)
 - rust-lang#140636 (implement `PanicTracker` to track `t` panics)
 - rust-lang#140661 (Make `-Zfixed-x18` into a target modifier)

r? `@ghost`
`@rustbot` modify labels: rollup
bors added a commit to rust-lang-ci/rust that referenced this pull request May 5, 2025
…llaumeGomez

Rollup of 11 pull requests

Successful merges:

 - rust-lang#140080 (mir-opt: Use one MirPatch in MatchBranchSimplification)
 - rust-lang#140115 (mir-opt: execute MatchBranchSimplification after GVN)
 - rust-lang#140357 (bypass linker configuration and cross target check on `x check`)
 - rust-lang#140374 (Resolve instance for SymFn in global/naked asm)
 - rust-lang#140559 (Removing rustc_type_ir in the rustc_infer codebase)
 - rust-lang#140605 (`fn check_opaque_type_parameter_valid` defer error)
 - rust-lang#140636 (implement `PanicTracker` to track `t` panics)
 - rust-lang#140661 (Make `-Zfixed-x18` into a target modifier)
 - rust-lang#140670 (calculate step duration in a panic-safe way)
 - rust-lang#140672 (Deeply normalize in the new solver in WF)
 - rust-lang#140676 (Update books)

r? `@ghost`
`@rustbot` modify labels: rollup
@bors bors merged commit ab7623e into rust-lang:master May 6, 2025
7 checks passed
@rustbot rustbot added this to the 1.88.0 milestone May 6, 2025
rust-timer added a commit to rust-lang-ci/rust that referenced this pull request May 6, 2025
Rollup merge of rust-lang#140115 - dianqk:gvn-matchbr, r=oli-obk

mir-opt: execute MatchBranchSimplification after GVN

This can provide more opportunities for MatchBranchSimplification.

Currently, rustc does not optimize the following code into a single statement at mir-opt, and this PR fixes the first case.

```rust
pub fn match1(c: bool, v1: i32, v2: i32) -> i32 {
    if c { v1 - v2 } else { v1 - v2 }
}

pub fn match2(c: bool, v1: i32) -> i32 {
    if c { v1 - 1 } else { v1 - 1 }
}
```

https://rust.godbolt.org/z/Y8xPMjrfM

r? mir-opt
@dianqk dianqk deleted the gvn-matchbr branch May 6, 2025 02:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
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.

6 participants