about summary refs log tree commit diff
path: root/src/test/codegen
diff options
context:
space:
mode:
authorDániel Buga <bugadani@gmail.com>2020-09-20 14:46:07 +0200
committerDániel Buga <bugadani@gmail.com>2020-09-27 15:10:48 +0200
commit89b8a97aead4aa366eb2587ffdcfa7df39f3815a (patch)
treeaa68710476e7e51620211c8c72f50cc3c39ef898 /src/test/codegen
parent5b9e8864032a3bfefa6f69c33fd99e0383a414af (diff)
downloadrust-89b8a97aead4aa366eb2587ffdcfa7df39f3815a.tar.gz
rust-89b8a97aead4aa366eb2587ffdcfa7df39f3815a.zip
Refactor memchr to allow optimization
Diffstat (limited to 'src/test/codegen')
-rw-r--r--src/test/codegen/issue-75659.rs62
1 files changed, 62 insertions, 0 deletions
diff --git a/src/test/codegen/issue-75659.rs b/src/test/codegen/issue-75659.rs
new file mode 100644
index 00000000000..8a4b7ef8c43
--- /dev/null
+++ b/src/test/codegen/issue-75659.rs
@@ -0,0 +1,62 @@
+// This test checks that the call to memchr/slice_contains is optimized away
+// when searching in small slices.
+
+// compile-flags: -O
+
+#![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)
+}