diff --git a/crates/core_simd/src/vector.rs b/crates/core_simd/src/vector.rs index 8c6c7036081..92984f55e45 100644 --- a/crates/core_simd/src/vector.rs +++ b/crates/core_simd/src/vector.rs @@ -184,12 +184,15 @@ impl Swizzle<1, N> for Splat { /// # Safety /// Reading `ptr` must be safe, as if by `<*const [T; N]>::read_unaligned`. const unsafe fn load(ptr: *const [T; N]) -> Self { - let mut tmp = core::mem::MaybeUninit::uninit(); + // There are potentially simpler ways to write this function, but this should result in + // LLVM `load ` + + let mut tmp = core::mem::MaybeUninit::::uninit(); // SAFETY: `Simd` always contains `N` elements of type `T`. It may have padding // which does not need to be initialized. The safety of reading `ptr` is ensured by the // caller. unsafe { - core::ptr::copy_nonoverlapping(ptr, tmp.as_mut_ptr() as *mut _, 1); + core::ptr::copy_nonoverlapping(ptr, tmp.as_mut_ptr().cast(), 1); tmp.assume_init() } } @@ -201,9 +204,14 @@ impl Swizzle<1, N> for Splat { /// # Safety /// Writing to `ptr` must be safe, as if by `<*mut [T; N]>::write_unaligned`. const unsafe fn store(self, ptr: *mut [T; N]) { + // There are potentially simpler ways to write this function, but this should result in + // LLVM `store ` + + // Creating a temporary helps LLVM turn the memcpy into a store. + let tmp = self; // SAFETY: `Simd` always contains `N` elements of type `T`. The safety of writing // `ptr` is ensured by the caller. - unsafe { core::ptr::copy_nonoverlapping(self.as_array(), ptr, 1) } + unsafe { core::ptr::copy_nonoverlapping(tmp.as_array(), ptr, 1) } } /// Converts an array to a SIMD vector.