summaryrefslogtreecommitdiffstats
path: root/tests/codegen/issues/issue-75659.rs
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-17 12:20:29 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-17 12:20:29 +0000
commit631cd5845e8de329d0e227aaa707d7ea228b8f8f (patch)
treea1b87c8f8cad01cf18f7c5f57a08f102771ed303 /tests/codegen/issues/issue-75659.rs
parentAdding debian version 1.69.0+dfsg1-1. (diff)
downloadrustc-631cd5845e8de329d0e227aaa707d7ea228b8f8f.tar.xz
rustc-631cd5845e8de329d0e227aaa707d7ea228b8f8f.zip
Merging upstream version 1.70.0+dfsg1.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'tests/codegen/issues/issue-75659.rs')
-rw-r--r--tests/codegen/issues/issue-75659.rs63
1 files changed, 63 insertions, 0 deletions
diff --git a/tests/codegen/issues/issue-75659.rs b/tests/codegen/issues/issue-75659.rs
new file mode 100644
index 000000000..9394868c0
--- /dev/null
+++ b/tests/codegen/issues/issue-75659.rs
@@ -0,0 +1,63 @@
+// This test checks that the call to memchr/slice_contains is optimized away
+// when searching in small slices.
+
+// compile-flags: -O -Zinline-mir=false
+// only-x86_64
+
+#![crate_type = "lib"]
+
+// CHECK-LABEL: @foo1
+#[no_mangle]
+pub fn foo1(x: u8, data: &[u8; 1]) -> bool {
+ // CHECK-NOT: memchr
+ // CHECK-NOT: slice_contains
+ data.contains(&x)
+}
+
+// CHECK-LABEL: @foo2
+#[no_mangle]
+pub fn foo2(x: u8, data: &[u8; 2]) -> bool {
+ // CHECK-NOT: memchr
+ // CHECK-NOT: slice_contains
+ data.contains(&x)
+}
+
+// CHECK-LABEL: @foo3
+#[no_mangle]
+pub fn foo3(x: u8, data: &[u8; 3]) -> bool {
+ // CHECK-NOT: memchr
+ // CHECK-NOT: slice_contains
+ data.contains(&x)
+}
+
+// CHECK-LABEL: @foo4
+#[no_mangle]
+pub fn foo4(x: u8, data: &[u8; 4]) -> bool {
+ // CHECK-NOT: memchr
+ // CHECK-NOT: slice_contains
+ data.contains(&x)
+}
+
+// CHECK-LABEL: @foo8
+#[no_mangle]
+pub fn foo8(x: u8, data: &[u8; 8]) -> bool {
+ // CHECK-NOT: memchr
+ // CHECK-NOT: slice_contains
+ data.contains(&x)
+}
+
+// CHECK-LABEL: @foo8_i8
+#[no_mangle]
+pub fn foo8_i8(x: i8, data: &[i8; 8]) -> bool {
+ // CHECK-NOT: memchr
+ // CHECK-NOT: slice_contains
+ !data.contains(&x)
+}
+
+// Check that the general case isn't inlined
+// CHECK-LABEL: @foo80
+#[no_mangle]
+pub fn foo80(x: u8, data: &[u8; 80]) -> bool {
+ // CHECK: call core::slice::memchr
+ data.contains(&x)
+}