diff options
| author | Scott McMurray <scottmcm@users.noreply.github.com> | 2021-12-11 15:29:52 -0800 | 
|---|---|---|
| committer | Scott McMurray <scottmcm@users.noreply.github.com> | 2021-12-14 13:15:15 -0800 | 
| commit | a0b96902e4c622d40c7186fc0c7ba13efc1fc912 (patch) | |
| tree | c19077465a770d87052fce16fefe419ab3036c0c /src/test/codegen/slice-ref-equality.rs | |
| parent | 404c8471aba60c2d837fa728e7c729a0f52d5830 (diff) | |
| download | rust-a0b96902e4c622d40c7186fc0c7ba13efc1fc912.tar.gz rust-a0b96902e4c622d40c7186fc0c7ba13efc1fc912.zip | |
Do array-slice equality via arrays, rather than always via slices
This'll still go via slices eventually for large arrays, but this way slice comparisons to short arrays can use the same memcmp-avoidance tricks. Added some tests for all the combinations to make sure I didn't accidentally infinitely-recurse something.
Diffstat (limited to 'src/test/codegen/slice-ref-equality.rs')
| -rw-r--r-- | src/test/codegen/slice-ref-equality.rs | 19 | 
1 files changed, 16 insertions, 3 deletions
| diff --git a/src/test/codegen/slice-ref-equality.rs b/src/test/codegen/slice-ref-equality.rs index 1f99ac7342b..c06554ecdec 100644 --- a/src/test/codegen/slice-ref-equality.rs +++ b/src/test/codegen/slice-ref-equality.rs @@ -4,18 +4,31 @@ // #71602 reported a simple array comparison just generating a loop. // This was originally fixed by ensuring it generates a single bcmp, -// but we now generate it as a load instead. `is_zero_slice` was +// but we now generate it as a load+icmp instead. `is_zero_slice` was // tweaked to still test the case of comparison against a slice, // and `is_zero_array` tests the new array-specific behaviour. +// The optimization was then extended to short slice-to-array comparisons, +// so the first test here now has a long slice to still get the bcmp. -// CHECK-LABEL: @is_zero_slice +// CHECK-LABEL: @is_zero_slice_long #[no_mangle] -pub fn is_zero_slice(data: &[u8; 4]) -> bool { +pub fn is_zero_slice_long(data: &[u8; 456]) -> bool { // CHECK: : // CHECK-NEXT: %{{.+}} = getelementptr {{.+}} // CHECK-NEXT: %[[BCMP:.+]] = tail call i32 @{{bcmp|memcmp}}({{.+}}) // CHECK-NEXT: %[[EQ:.+]] = icmp eq i32 %[[BCMP]], 0 // CHECK-NEXT: ret i1 %[[EQ]] + &data[..] == [0; 456] +} + +// CHECK-LABEL: @is_zero_slice_short +#[no_mangle] +pub fn is_zero_slice_short(data: &[u8; 4]) -> bool { + // CHECK: : + // CHECK-NEXT: %[[PTR:.+]] = bitcast [4 x i8]* {{.+}} to i32* + // CHECK-NEXT: %[[LOAD:.+]] = load i32, i32* %[[PTR]], align 1 + // CHECK-NEXT: %[[EQ:.+]] = icmp eq i32 %[[LOAD]], 0 + // CHECK-NEXT: ret i1 %[[EQ]] &data[..] == [0; 4] } | 
