File tree Expand file tree Collapse file tree 2 files changed +33
-3
lines changed Expand file tree Collapse file tree 2 files changed +33
-3
lines changed Original file line number Diff line number Diff line change @@ -1012,9 +1012,11 @@ mod impls {
1012
1012
impl Ord for $t {
1013
1013
#[ inline]
1014
1014
fn cmp( & self , other: & $t) -> Ordering {
1015
- if * self == * other { Equal }
1016
- else if * self < * other { Less }
1017
- else { Greater }
1015
+ // The order here is important to generate more optimal assembly.
1016
+ // See <https://github.com/rust-lang/rust/issues/63758> for more info.
1017
+ if * self < * other { Less }
1018
+ else if * self > * other { Greater }
1019
+ else { Equal }
1018
1020
}
1019
1021
}
1020
1022
) * )
Original file line number Diff line number Diff line change
1
+ // This is test for more optimal Ord implementation for integers.
2
+ // See <https://github.com/rust-lang/rust/issues/63758> for more info.
3
+
4
+ // compile-flags: -C opt-level=3
5
+
6
+ #![ crate_type = "lib" ]
7
+
8
+ use std:: cmp:: Ordering ;
9
+
10
+ // CHECK-LABEL: @cmp_signed
11
+ #[ no_mangle]
12
+ pub fn cmp_signed ( a : i64 , b : i64 ) -> Ordering {
13
+ // CHECK: icmp slt
14
+ // CHECK: icmp sgt
15
+ // CHECK: zext i1
16
+ // CHECK: select i1
17
+ a. cmp ( & b)
18
+ }
19
+
20
+ // CHECK-LABEL: @cmp_unsigned
21
+ #[ no_mangle]
22
+ pub fn cmp_unsigned ( a : u32 , b : u32 ) -> Ordering {
23
+ // CHECK: icmp ult
24
+ // CHECK: icmp ugt
25
+ // CHECK: zext i1
26
+ // CHECK: select i1
27
+ a. cmp ( & b)
28
+ }
You can’t perform that action at this time.
0 commit comments