add inline attribute and codegen test
This commit is contained in:
parent
311c3b71f0
commit
fb3d1d0c4b
2 changed files with 34 additions and 0 deletions
|
@ -10,6 +10,7 @@ type BufType = [usize; 32];
|
|||
/// # Safety
|
||||
///
|
||||
/// The specified range must be valid for reading and writing.
|
||||
#[inline]
|
||||
pub(super) unsafe fn ptr_rotate<T>(left: usize, mid: *mut T, right: usize) {
|
||||
if T::IS_ZST {
|
||||
return;
|
||||
|
@ -43,6 +44,7 @@ pub(super) unsafe fn ptr_rotate<T>(left: usize, mid: *mut T, right: usize) {
|
|||
/// # Safety
|
||||
///
|
||||
/// The specified range must be valid for reading and writing.
|
||||
#[inline]
|
||||
unsafe fn ptr_rotate_memmove<T>(left: usize, mid: *mut T, right: usize) {
|
||||
// The `[T; 0]` here is to ensure this is appropriately aligned for T
|
||||
let mut rawarray = MaybeUninit::<(BufType, [T; 0])>::uninit();
|
||||
|
@ -114,6 +116,7 @@ unsafe fn ptr_rotate_memmove<T>(left: usize, mid: *mut T, right: usize) {
|
|||
/// # Safety
|
||||
///
|
||||
/// The specified range must be valid for reading and writing.
|
||||
#[inline]
|
||||
unsafe fn ptr_rotate_gcd<T>(left: usize, mid: *mut T, right: usize) {
|
||||
// Algorithm 2
|
||||
// Microbenchmarks indicate that the average performance for random shifts is better all
|
||||
|
@ -218,6 +221,7 @@ unsafe fn ptr_rotate_gcd<T>(left: usize, mid: *mut T, right: usize) {
|
|||
/// # Safety
|
||||
///
|
||||
/// The specified range must be valid for reading and writing.
|
||||
#[inline]
|
||||
unsafe fn ptr_rotate_swap<T>(mut left: usize, mut mid: *mut T, mut right: usize) {
|
||||
loop {
|
||||
if left >= right {
|
||||
|
|
30
tests/codegen/lib-optimizations/slice_rotate.rs
Normal file
30
tests/codegen/lib-optimizations/slice_rotate.rs
Normal file
|
@ -0,0 +1,30 @@
|
|||
//@ compile-flags: -O
|
||||
|
||||
#![crate_type = "lib"]
|
||||
|
||||
// Ensure that the simple case of rotating by a constant 1 optimizes to the obvious thing
|
||||
|
||||
// CHECK-LABEL: @rotate_left_by_one
|
||||
#[no_mangle]
|
||||
pub fn rotate_left_by_one(slice: &mut [i32]) {
|
||||
// CHECK-NOT: phi
|
||||
// CHECK-NOT: call
|
||||
// CHECK-NOT: load
|
||||
// CHECK-NOT: store
|
||||
// CHECK-NOT: getelementptr
|
||||
// CHECK: %[[END:.+]] = getelementptr
|
||||
// CHECK-NEXT: %[[DIM:.+]] = getelementptr
|
||||
// CHECK-NEXT: %[[LAST:.+]] = load
|
||||
// CHECK-NEXT: %[[FIRST:.+]] = shl
|
||||
// CHECK-NEXT: call void @llvm.memmove
|
||||
// CHECK-NEXT: store i32 %[[LAST]], ptr %[[DIM:.+]]
|
||||
// CHECK-NOT: phi
|
||||
// CHECK-NOT: call
|
||||
// CHECK-NOT: load
|
||||
// CHECK-NOT: store
|
||||
// CHECK-NOT: getelementptr
|
||||
// CHECK: ret void
|
||||
if !slice.is_empty() {
|
||||
slice.rotate_left(1);
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue