diff options
| author | bors <bors@rust-lang.org> | 2020-10-01 18:16:02 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2020-10-01 18:16:02 +0000 |
| commit | 8fe73e80d762bc575040239fc05fb1c612873554 (patch) | |
| tree | a0f1265e371692d886598d75e1c2a0f962edf2a6 /src/test/codegen | |
| parent | 2ad6187ce51eb3a304ca448b8676870f95ab5b11 (diff) | |
| parent | de623bfaf77a69d86e1561f6b4e0fdd9d193cf60 (diff) | |
| download | rust-8fe73e80d762bc575040239fc05fb1c612873554.tar.gz rust-8fe73e80d762bc575040239fc05fb1c612873554.zip | |
Auto merge of #76971 - bugadani:issue-75659, r=Amanieu
Refactor memchr to allow optimization Closes #75659 The implementation already uses naive search if the slice if short enough, but the case is complicated enough to not be optimized away. This PR refactors memchr so that it exists early when the slice is short enough. Codegen-wise, as shown in #75659, memchr was not inlined previously so the only way I could find to test this is to check if there is no memchr call. Let me know if there is a more robust solution here.
Diffstat (limited to 'src/test/codegen')
| -rw-r--r-- | src/test/codegen/issue-75659.rs | 63 |
1 files changed, 63 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..d093c841d68 --- /dev/null +++ b/src/test/codegen/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 +// 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) +} |
