Skip to content

Commit 3f05cf6

Browse files
authored
Rollup merge of #63992 - lzutao:integer-ord, r=nagisa
Small improvement for Ord implementation of integers Godbolt link: https://godbolt.org/z/tuTDOg ### Before **asm** ```asm example::cmp: mov eax, dword ptr [rdi] xor ecx, ecx cmp eax, dword ptr [rsi] seta cl mov eax, 255 cmovae eax, ecx ret ``` **llvm-mca** ``` Iterations: 100 Instructions: 700 Total Cycles: 217 Total uOps: 1100 Dispatch Width: 6 uOps Per Cycle: 5.07 IPC: 3.23 Block RThroughput: 1.8 ``` ### After **asm** ```asm example::cmp: mov eax, dword ptr [rdi] xor ecx, ecx cmp eax, dword ptr [rsi] setne cl mov eax, 255 cmovae eax, ecx ret ``` **llvm-mca** ``` Iterations: 100 Instructions: 700 Total Cycles: 209 Total uOps: 1000 Dispatch Width: 6 uOps Per Cycle: 4.78 IPC: 3.35 Block RThroughput: 1.7 ``` r? @nagisa
2 parents c94ead7 + ade191c commit 3f05cf6

File tree

2 files changed

+4
-4
lines changed

2 files changed

+4
-4
lines changed

src/libcore/cmp.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1015,8 +1015,8 @@ mod impls {
10151015
// The order here is important to generate more optimal assembly.
10161016
// See <https://github.com/rust-lang/rust/issues/63758> for more info.
10171017
if *self < *other { Less }
1018-
else if *self > *other { Greater }
1019-
else { Equal }
1018+
else if *self == *other { Equal }
1019+
else { Greater }
10201020
}
10211021
}
10221022
)*)

src/test/codegen/integer-cmp.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ use std::cmp::Ordering;
1111
#[no_mangle]
1212
pub fn cmp_signed(a: i64, b: i64) -> Ordering {
1313
// CHECK: icmp slt
14-
// CHECK: icmp sgt
14+
// CHECK: icmp ne
1515
// CHECK: zext i1
1616
// CHECK: select i1
1717
a.cmp(&b)
@@ -21,7 +21,7 @@ pub fn cmp_signed(a: i64, b: i64) -> Ordering {
2121
#[no_mangle]
2222
pub fn cmp_unsigned(a: u32, b: u32) -> Ordering {
2323
// CHECK: icmp ult
24-
// CHECK: icmp ugt
24+
// CHECK: icmp ne
2525
// CHECK: zext i1
2626
// CHECK: select i1
2727
a.cmp(&b)

0 commit comments

Comments
 (0)