From b6eeb4ee90e31f7846e94e4f639f44bc5f623ca0 Mon Sep 17 00:00:00 2001 From: Jubilee Young Date: Wed, 13 Dec 2023 17:46:46 -0800 Subject: [PATCH] Assume masks are correct This allows miri to detect when they are not, and may be exploited by LLVM during optimization. --- crates/core_simd/src/lib.rs | 1 + crates/core_simd/src/masks.rs | 5 ++++- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/crates/core_simd/src/lib.rs b/crates/core_simd/src/lib.rs index 64ba9705ef523..e974e7aa25a44 100644 --- a/crates/core_simd/src/lib.rs +++ b/crates/core_simd/src/lib.rs @@ -4,6 +4,7 @@ const_maybe_uninit_as_mut_ptr, const_mut_refs, convert_float_to_int, + core_intrinsics, decl_macro, inline_const, intra_doc_pointers, diff --git a/crates/core_simd/src/masks.rs b/crates/core_simd/src/masks.rs index 0623d2bf3d121..b95c070d09c35 100644 --- a/crates/core_simd/src/masks.rs +++ b/crates/core_simd/src/masks.rs @@ -175,7 +175,10 @@ where #[must_use = "method returns a new mask and does not mutate the original value"] pub unsafe fn from_int_unchecked(value: Simd) -> Self { // Safety: the caller must confirm this invariant - unsafe { Self(mask_impl::Mask::from_int_unchecked(value)) } + unsafe { + core::intrinsics::assume(::valid(value)); + Self(mask_impl::Mask::from_int_unchecked(value)) + } } /// Converts a vector of integers to a mask, where 0 represents `false` and -1