]> git.lizzy.rs Git - rust.git/blob - tests/codegen/slice-ref-equality.rs
Auto merge of #107778 - weihanglo:update-cargo, r=weihanglo
[rust.git] / tests / codegen / slice-ref-equality.rs
1 // compile-flags: -C opt-level=3 -Zmerge-functions=disabled
2
3 #![crate_type = "lib"]
4
5 // #71602 reported a simple array comparison just generating a loop.
6 // This was originally fixed by ensuring it generates a single bcmp,
7 // but we now generate it as a load+icmp instead. `is_zero_slice` was
8 // tweaked to still test the case of comparison against a slice,
9 // and `is_zero_array` tests the new array-specific behaviour.
10 // The optimization was then extended to short slice-to-array comparisons,
11 // so the first test here now has a long slice to still get the bcmp.
12
13 // CHECK-LABEL: @is_zero_slice_long
14 #[no_mangle]
15 pub fn is_zero_slice_long(data: &[u8; 456]) -> bool {
16     // CHECK: %[[BCMP:.+]] = tail call i32 @{{bcmp|memcmp}}({{.+}})
17     // CHECK-NEXT: %[[EQ:.+]] = icmp eq i32 %[[BCMP]], 0
18     // CHECK-NEXT: ret i1 %[[EQ]]
19     &data[..] == [0; 456]
20 }
21
22 // CHECK-LABEL: @is_zero_slice_short
23 #[no_mangle]
24 pub fn is_zero_slice_short(data: &[u8; 4]) -> bool {
25     // CHECK: %[[LOAD:.+]] = load i32, {{i32\*|ptr}} %{{.+}}, align 1
26     // CHECK-NEXT: %[[EQ:.+]] = icmp eq i32 %[[LOAD]], 0
27     // CHECK-NEXT: ret i1 %[[EQ]]
28     &data[..] == [0; 4]
29 }
30
31 // CHECK-LABEL: @is_zero_array
32 #[no_mangle]
33 pub fn is_zero_array(data: &[u8; 4]) -> bool {
34     // CHECK: %[[LOAD:.+]] = load i32, {{i32\*|ptr}} %{{.+}}, align 1
35     // CHECK-NEXT: %[[EQ:.+]] = icmp eq i32 %[[LOAD]], 0
36     // CHECK-NEXT: ret i1 %[[EQ]]
37     *data == [0; 4]
38 }