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

When HIR auto-refs a comparison operator, clean it up in MIR #109292

Closed
wants to merge 1 commit into from

Conversation

scottmcm
Copy link
Member

Today, if you're comparing &&Ts, it ends up auto-reffing in HIR. So the MIR ends up calling PartialEq/Cmp with &&&T, and the MIR inliner can only get that down to &T: https://rust.godbolt.org/z/hje6jd4Yf.

So this adds an always-run pass to look at Calls in MIR with from_hir_call: false to just call the correct Partial{Eq,Cmp} implementation directly, even if it's debug and we're not running the inliner, to avoid needing to ever monomorphize a bunch of useless forwarding impls.

This hopes to avoid ever needing something like #108372 where we'd tell people to manually dereference the sides of their comparisons.

r? @ghost

… MIR

Today, if you're comparing `&&T`s, it ends up auto-reffing in HIR.  So the MIR ends up calling `PartialEq/Cmp` with `&&&T`, and the MIR inliner can only get that down to `&T`: <https://rust.godbolt.org/z/hje6jd4Yf>.

So this adds an always-run pass to look at `Call`s in MIR with `from_hir_call: false` to just call the correct `Partial{Eq,Cmp}` implementation directly, even if it's debug and we're not running the inliner, to avoid needing to ever monomorphize a bunch of useless forwarding impls.

This hopes to avoid ever needing something like rust-lang#108372 where we'd tell people to manually dereference the sides of their comparisons.
@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 Mar 18, 2023
@rustbot
Copy link
Collaborator

rustbot commented Mar 18, 2023

Some changes occurred to MIR optimizations

cc @rust-lang/wg-mir-opt

@scottmcm
Copy link
Member Author

This could go either way, so let's see:
@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 Mar 18, 2023
@bors
Copy link
Contributor

bors commented Mar 18, 2023

⌛ Trying commit 7b74759 with merge d8ac1e4bc289879ff692ef5472e1cebd5c3cc42b...

@JakobDegen
Copy link
Contributor

This doesn't seem correct to me. Could you add something like this as a test:

struct S;

struct T;

impl PartialEq<&&&T> for &&S {
    fn eq(&self, _t: &&&&T) -> bool {
        todo!()
    }
}

fn main() {
    let s = S;
    let t = T;
    dbg!(&&s == &&&t);
}

That having been said, do we know why inlining doesn't cover this? I would very strongly prefer not having to add a special case for this. (I have more review comments but will leave those for later)

@JakobDegen JakobDegen self-assigned this Mar 18, 2023
@bors
Copy link
Contributor

bors commented Mar 18, 2023

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

@rust-timer

This comment has been minimized.

@scottmcm
Copy link
Member Author

Oh, right, that's coherent despite the blanket :(

Guess that means this approach just can't work.

@scottmcm scottmcm added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Mar 18, 2023
@rust-timer
Copy link
Collaborator

Finished benchmarking commit (d8ac1e4bc289879ff692ef5472e1cebd5c3cc42b): comparison URL.

Overall result: ❌✅ regressions and improvements - 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.

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 a highly reliable metric that was used to determine the overall result at the top of this comment.

mean range count
Regressions ❌
(primary)
0.4% [0.4%, 0.4%] 1
Regressions ❌
(secondary)
1.3% [1.3%, 1.3%] 1
Improvements ✅
(primary)
-1.2% [-1.7%, -0.7%] 2
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) -0.7% [-1.7%, 0.4%] 3

Max RSS (memory usage)

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)
1.1% [1.1%, 1.1%] 1
Regressions ❌
(secondary)
- - 0
Improvements ✅
(primary)
-1.8% [-2.1%, -1.5%] 2
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) -0.8% [-2.1%, 1.1%] 3

Cycles

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

@rustbot rustbot added perf-regression Performance regression. and removed S-waiting-on-perf Status: Waiting on a perf run to be completed. labels Mar 18, 2023
@scottmcm
Copy link
Member Author

Well, I like 4% on ripgrep opt-full, but this isn't nearly worth it. I'll try something else instead.

@scottmcm scottmcm closed this Mar 18, 2023
@scottmcm scottmcm deleted the simplify-ops branch March 18, 2023 21:59
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-author Status: This is awaiting some action (such as code changes or more information) from the author. 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.

5 participants