MIRI says reverse is UB, so replace it with an implementation that LLVM can vectorize
For small types with padding, the current implementation is UB because it does integer operations on uninit values. But LLVM has gotten smarter since I wrote the previous implementation in 2017, so remove all the manual magic and just write it in such a way that LLVM will vectorize. This code is much simpler (albeit nuanced) and has very little `unsafe`, and is actually faster to boot!
This commit is contained in:
parent
14a2fd640e
commit
71f5cfb21f
2 changed files with 58 additions and 91 deletions
26
src/test/codegen/slice-reverse.rs
Normal file
26
src/test/codegen/slice-reverse.rs
Normal file
|
|
@ -0,0 +1,26 @@
|
|||
// compile-flags: -O
|
||||
// only-x86_64
|
||||
|
||||
#![crate_type = "lib"]
|
||||
|
||||
// CHECK-LABEL: @slice_reverse_u8
|
||||
#[no_mangle]
|
||||
pub fn slice_reverse_u8(slice: &mut [u8]) {
|
||||
// CHECK-NOT: panic_bounds_check
|
||||
// CHECK-NOT: slice_end_index_len_fail
|
||||
// CHECK: shufflevector <{{[0-9]+}} x i8>
|
||||
// CHECK-NOT: panic_bounds_check
|
||||
// CHECK-NOT: slice_end_index_len_fail
|
||||
slice.reverse();
|
||||
}
|
||||
|
||||
// CHECK-LABEL: @slice_reverse_i32
|
||||
#[no_mangle]
|
||||
pub fn slice_reverse_i32(slice: &mut [i32]) {
|
||||
// CHECK-NOT: panic_bounds_check
|
||||
// CHECK-NOT: slice_end_index_len_fail
|
||||
// CHECK: shufflevector <{{[0-9]+}} x i32>
|
||||
// CHECK-NOT: panic_bounds_check
|
||||
// CHECK-NOT: slice_end_index_len_fail
|
||||
slice.reverse();
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue