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

MIR inliner not inlining through is_some_and sometimes #137901

Closed
scottmcm opened this issue Mar 2, 2025 · 1 comment · Fixed by #137907
Closed

MIR inliner not inlining through is_some_and sometimes #137901

scottmcm opened this issue Mar 2, 2025 · 1 comment · Fixed by #137907
Labels
A-mir-opt-inlining Area: MIR inlining

Comments

@scottmcm
Copy link
Member

scottmcm commented Mar 2, 2025

Noticed in 2025-03-01 (which at time of writing isn't on godbolt yet) that the MIR for <= for a generated type still contains

    bb1: {
        _4 = move ((_3 as Some).0: std::cmp::Ordering);
        StorageLive(_5);
        _5 = (copy _4,);
        _0 = <fn(std::cmp::Ordering) -> bool {std::cmp::Ordering::is_le} as FnOnce<(std::cmp::Ordering,)>>::call_once(std::cmp::Ordering::is_le, move _5) -> [return: bb2, unwind continue];
    }

https://play.rust-lang.org/?version=nightly&mode=release&edition=2024&gist=57c2829c1cf0a8778926bd87a0378feb

I can workaround that particular case, but calls to trivial functions like is_le really ought to MIR-inline, even if done through the voldemort function item like this.

@rustbot rustbot added the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Mar 2, 2025
@scottmcm scottmcm added A-mir-opt-inlining Area: MIR inlining and removed needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. labels Mar 2, 2025
@scottmcm scottmcm changed the title MIR inliner not inling through is_some_and sometimes MIR inliner not inlining through is_some_and sometimes Mar 2, 2025
@scottmcm
Copy link
Member Author

scottmcm commented Mar 2, 2025

Weirdly, this seems to be due to using .is_some_and(Ordering::is_le) -- changing it to .is_some_and(|c| c.is_le()) makes it inline again 🤯

bors added a commit to rust-lang-ci/rust that referenced this issue Mar 3, 2025
Improve the generic MIR in the default `PartialOrd::le` and friends

It looks like I regressed this accidentally in rust-lang#137197 due to rust-lang#137901

So this PR does two things:
1. Tweaks the way we're calling `is_some_and` so that it optimizes in the generic MIR (rather than needing to optimize it in every monomorphization) -- the first commit adds a MIR test, so you can see the difference in the second commit.
2. Updates the implementations of `is_le` and friends to be slightly simpler, and parallel how clang does them.
bors added a commit to rust-lang-ci/rust that referenced this issue Mar 3, 2025
Inline `FnOnce`/`FnMut`/`Fn` shims once again

cc rust-lang#137901

r? `@ghost`
bors added a commit to rust-lang-ci/rust that referenced this issue Mar 3, 2025
Inline `FnOnce`/`FnMut`/`Fn` shims once again

cc rust-lang#137901

r? `@ghost`
bors added a commit to rust-lang-ci/rust that referenced this issue Mar 3, 2025
Inline `FnOnce`/`FnMut`/`Fn` shims once again

This PR fixes the argument checking for `extern "rust-call"` ABI functions with a spread arg, which do no expect their arguments to be exploded from a tuple like closures do.

Secondly, it removes the hack that prevented them from being inlined. This results in more work done by the compiler, but it does end up allowing us to inline functions we didn't before.

Fixes rust-lang#137901
@bors bors closed this as completed in 30f168e Mar 5, 2025
workingjubilee added a commit to workingjubilee/rustc that referenced this issue Mar 7, 2025
…ilee

Improve the generic MIR in the default `PartialOrd::le` and friends

It looks like I regressed this accidentally in rust-lang#137197 due to rust-lang#137901

So this PR does two things:
1. Tweaks the way we're calling `is_some_and` so that it optimizes in the generic MIR (rather than needing to optimize it in every monomorphization) -- the first commit adds a MIR test, so you can see the difference in the second commit.
2. Updates the implementations of `is_le` and friends to be slightly simpler, and parallel how clang does them.
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this issue Mar 7, 2025
…ilee

Improve the generic MIR in the default `PartialOrd::le` and friends

It looks like I regressed this accidentally in rust-lang#137197 due to rust-lang#137901

So this PR does two things:
1. Tweaks the way we're calling `is_some_and` so that it optimizes in the generic MIR (rather than needing to optimize it in every monomorphization) -- the first commit adds a MIR test, so you can see the difference in the second commit.
2. Updates the implementations of `is_le` and friends to be slightly simpler, and parallel how clang does them.
rust-timer added a commit to rust-lang-ci/rust that referenced this issue Mar 7, 2025
Rollup merge of rust-lang#137904 - scottmcm:ordering-is, r=workingjubilee

Improve the generic MIR in the default `PartialOrd::le` and friends

It looks like I regressed this accidentally in rust-lang#137197 due to rust-lang#137901

So this PR does two things:
1. Tweaks the way we're calling `is_some_and` so that it optimizes in the generic MIR (rather than needing to optimize it in every monomorphization) -- the first commit adds a MIR test, so you can see the difference in the second commit.
2. Updates the implementations of `is_le` and friends to be slightly simpler, and parallel how clang does them.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-mir-opt-inlining Area: MIR inlining
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants