-
Notifications
You must be signed in to change notification settings - Fork 12.9k
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
Do array-slice equality via array equality, rather than always via slices #91838
Do array-slice equality via array equality, rather than always via slices #91838
Conversation
r? @dtolnay (rust-highfive has picked a reviewer for you, use r? to override) |
This comment has been minimized.
This comment has been minimized.
41664e8
to
363987b
Compare
This comment has been minimized.
This comment has been minimized.
363987b
to
97553c0
Compare
I had to update a codegen test, so preemptively |
Cool optimization, but all of these "hacks" are starting to worrying me. They all feels too targeted. It seems to me that they could benefit to way much code rather than just the one that are in core. It's seems to me that the compiler is missing some optimization for the general case. |
This'll still go via slices eventually for large arrays, but this way slice comparisons to short arrays can use the same memcmp-avoidance tricks. Added some tests for all the combinations to make sure I didn't accidentally infinitely-recurse something.
97553c0
to
a0b9690
Compare
@Urgau I went and filed an LLVM issue (llvm/llvm-project#52701) for the core thing that #85828 was made to avoid. I think this PR is actually reasonable even if the LLVM issue is fixed, though -- there's no reason to lose the "hey, this is only ever fixed-length" part of slice-array comparisons by always dropping to slice-slice immediately. For example, MIR optimizations would have a much easier time folding things if it doesn't need to inspect slice lengths to know what's happening. And I think The whole rust/compiler/rustc_middle/src/ty/util.rs Lines 849 to 861 in 3e21768
|
@bors r+ rollup=never |
📌 Commit a0b9690 has been approved by |
☀️ Test successful - checks-actions |
Finished benchmarking commit (7abab1e): comparison url. Summary: This change led to moderate relevant mixed results 🤷 in compiler performance.
If you disagree with this performance assessment, please file an issue in rust-lang/rustc-perf. Next Steps: If you can justify the regressions found in this perf run, please indicate this with @rustbot label: +perf-regression |
Draft because it needs a rebase after #91766 eventually gets through bors.This enables the optimizations from #85828 to be used for array-to-slice comparisons too, not just array-to-array.
For example, https://play.rust-lang.org/?version=nightly&mode=release&edition=2021&gist=5f9ba69b3d5825a782f897c830d3a6aa
Currently writes the array to stack for no reason:
Whereas with the change in this PR it just compares it directly: