- Notifications
You must be signed in to change notification settings - Fork 13.8k
Use the chaining methods on PartialOrd for slices too #138881
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
Conversation
| ||
// CHECK-LABEL: @array_of_tuple_le | ||
#[no_mangle] | ||
pub fn array_of_tuple_le(a: &[(i16, u16); 2], b: &[(i16, u16); 2]) -> bool { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nightly, note the setl
+setg
from the cmp
methods:
array_of_tuple_le: movzwl (%rdi), %eax movzwl (%rsi), %ecx cmpw %cx, %ax setl %cl setg %al jne .LBB0_1 movzwl 2(%rdi), %eax cmpw 2(%rsi), %ax seta %al sbbb $0, %al testb %al, %al jne .LBB0_7 jmp .LBB0_4 .LBB0_1: subb %cl, %al testb %al, %al jne .LBB0_7 .LBB0_4: movzwl 4(%rdi), %eax movzwl 4(%rsi), %ecx cmpw %cx, %ax setl %cl setg %al jne .LBB0_5 movzwl 6(%rdi), %eax cmpw 6(%rsi), %ax seta %al sbbb $0, %al jmp .LBB0_7 .LBB0_5: subb %cl, %al .LBB0_7: testb %al, %al setle %al retq
With this PR:
array_of_tuple_le: movzwl (%rcx), %eax movzwl (%rdx), %r8d cmpw %r8w, %ax jne.LBB1_1 movzwl2(%rcx), %r8d movzwl2(%rdx), %r9d cmpw %r9w, %r8w jne.LBB1_2 movzwl4(%rcx), %eax movzwl4(%rdx), %r8d cmpw %r8w, %ax jne.LBB1_1 movzwl6(%rcx), %r8d movzwl6(%rdx), %r9d movb$1, %al cmpw %r9w, %r8w jne.LBB1_2 retq .LBB1_1: cmpw %r8w, %ax setle %al retq .LBB1_2: cmpw %r9w, %r8w setb %al retq
That's so nice -- straight line with no jumps taken if they're equal, otherwise jumps to the check it needs (dedup'd by consistent register choices), saves that, and returns.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note that even with #133984 landed, we still don't optimize away the [su]cmp
s in nightly today: https://rust.godbolt.org/z/ss5E7q6PT.
// This is certainly not the obvious way to implement these methods. | ||
// Unfortunately, using anything that looks at the discriminant means that | ||
// LLVM sees a check for `2` (aka `ControlFlow<bool>::Continue(())`) and | ||
// gets very distracted by that, ending up generating extraneous code. | ||
// This should be changed to something simpler once either LLVM is smarter, | ||
// see <https://github.com/llvm/llvm-project/issues/132678>, or we generate | ||
// niche discriminant checks in a way that doesn't trigger it. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So there's a backlink: llvm/llvm-project#132678
Oh, I'm glad this passes in LLVM18 too. As the one with context from #138135, |
☔ The latest upstream changes (presumably #138956) made this pull request unmergeable. Please resolve the merge conflicts. |
17ab2d3
to 877f8de
Compare This comment has been minimized.
This comment has been minimized.
877f8de
to cf991d9
Compare @bors r+ |
…-Simulacrum Use the chaining methods on PartialOrd for slices too rust-lang#138135 added these doc-hidden trait methods to improve the tuple codegen. This PR adds more implementations and callers so that the codegen for slice (and array) comparisons also improves.
…enton Rollup of 9 pull requests Successful merges: - rust-lang#137494 (libstd: init(): dup() subsequent /dev/nulls instead of opening them again) - rust-lang#138881 (Use the chaining methods on PartialOrd for slices too) - rust-lang#138972 (std: Fix build for NuttX targets) - rust-lang#139107 (std: make `cmath` functions safe) - rust-lang#139607 (Add regression test for rust-lang#127424) - rust-lang#139691 (Document that `opt-dist` requires metrics to be enabled) - rust-lang#139707 (Fix comment in bootstrap) - rust-lang#139708 (Fix name of field in doc comment) - rust-lang#139709 (bootstrap: fix typo in doc string) r? `@ghost` `@rustbot` modify labels: rollup
…-Simulacrum Use the chaining methods on PartialOrd for slices too rust-lang#138135 added these doc-hidden trait methods to improve the tuple codegen. This PR adds more implementations and callers so that the codegen for slice (and array) comparisons also improves.
…enton Rollup of 8 pull requests Successful merges: - rust-lang#138881 (Use the chaining methods on PartialOrd for slices too) - rust-lang#138972 (std: Fix build for NuttX targets) - rust-lang#139107 (std: make `cmath` functions safe) - rust-lang#139607 (Add regression test for rust-lang#127424) - rust-lang#139691 (Document that `opt-dist` requires metrics to be enabled) - rust-lang#139707 (Fix comment in bootstrap) - rust-lang#139708 (Fix name of field in doc comment) - rust-lang#139709 (bootstrap: fix typo in doc string) r? `@ghost` `@rustbot` modify labels: rollup
Looks like this failed in rollup #139723 (comment) @bors r- |
cf991d9
to 756670f
Compare Doh, I hard-coded |
@bors r=Mark-Simulacrum rollup=iffy (I think I fixed the codegen test, but who knows if there's something else I missed) |
☀️ Test successful - checks-actions |
What is this?This is an experimental post-merge analysis report that shows differences in test outcomes between the merged PR and its parent PR.Comparing 65fa0ab (parent) -> 53d4476 (this PR) Test differencesShow 2 test diffsStage 1
Stage 2
Job group index Job duration changes
How to interpret the job duration changes?Job durations can vary a lot, based on the actual runner instance |
Finished benchmarking commit (53d4476): comparison URL. Overall result: no relevant changes - no action needed@rustbot label: -perf-regression Instruction countThis benchmark run did not return any relevant results for this metric. Max RSS (memory usage)Results (primary 2.8%, secondary 8.3%)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.
CyclesThis benchmark run did not return any relevant results for this metric. Binary sizeResults (primary -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.
Bootstrap: 779.489s -> 780.32s (0.11%) |
…imulacrum Use the chaining methods on PartialOrd for slices too rust-lang#138135 added these doc-hidden trait methods to improve the tuple codegen. This PR adds more implementations and callers so that the codegen for slice (and array) comparisons also improves.
#138135 added these doc-hidden trait methods to improve the tuple codegen. This PR adds more implementations and callers so that the codegen for slice (and array) comparisons also improves.