]> git.lizzy.rs Git - rust.git/blob - tests/codegen/issue-75659.rs
Rollup merge of #107731 - RalfJung:interpret-discriminant, r=cjgillot
[rust.git] / tests / codegen / issue-75659.rs
1 // This test checks that the call to memchr/slice_contains is optimized away
2 // when searching in small slices.
3
4 // compile-flags: -O -Zinline-mir=no
5 // only-x86_64
6
7 #![crate_type = "lib"]
8
9 // CHECK-LABEL: @foo1
10 #[no_mangle]
11 pub fn foo1(x: u8, data: &[u8; 1]) -> bool {
12     // CHECK-NOT: memchr
13     // CHECK-NOT: slice_contains
14     data.contains(&x)
15 }
16
17 // CHECK-LABEL: @foo2
18 #[no_mangle]
19 pub fn foo2(x: u8, data: &[u8; 2]) -> bool {
20     // CHECK-NOT: memchr
21     // CHECK-NOT: slice_contains
22     data.contains(&x)
23 }
24
25 // CHECK-LABEL: @foo3
26 #[no_mangle]
27 pub fn foo3(x: u8, data: &[u8; 3]) -> bool {
28     // CHECK-NOT: memchr
29     // CHECK-NOT: slice_contains
30     data.contains(&x)
31 }
32
33 // CHECK-LABEL: @foo4
34 #[no_mangle]
35 pub fn foo4(x: u8, data: &[u8; 4]) -> bool {
36     // CHECK-NOT: memchr
37     // CHECK-NOT: slice_contains
38     data.contains(&x)
39 }
40
41 // CHECK-LABEL: @foo8
42 #[no_mangle]
43 pub fn foo8(x: u8, data: &[u8; 8]) -> bool {
44     // CHECK-NOT: memchr
45     // CHECK-NOT: slice_contains
46     data.contains(&x)
47 }
48
49 // CHECK-LABEL: @foo8_i8
50 #[no_mangle]
51 pub fn foo8_i8(x: i8, data: &[i8; 8]) -> bool {
52     // CHECK-NOT: memchr
53     // CHECK-NOT: slice_contains
54     !data.contains(&x)
55 }
56
57 // Check that the general case isn't inlined
58 // CHECK-LABEL: @foo80
59 #[no_mangle]
60 pub fn foo80(x: u8, data: &[u8; 80]) -> bool {
61     // CHECK: call core::slice::memchr
62     data.contains(&x)
63 }