Skip to content

Commit f5b16f6

Browse files
committed
Add codegen test for integers compare
1 parent 96983fc commit f5b16f6

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

src/test/codegen/integer-cmp.rs

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
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+
}

0 commit comments

Comments
 (0)