-
Notifications
You must be signed in to change notification settings - Fork 12.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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!
- Loading branch information
Showing
2 changed files
with
58 additions
and
91 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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(); | ||
} |