Open
Description
As discussed in this thread, Rust does not provide LLVM any information about possible lengths of slices, vectors, and other types. In some cases it prevents LLVM from applying optimizations since it has to account for invalid lengths.
I suggest updating length getters of slice-like types to something like this:
#[inline]
pub const fn len(&self) -> usize {
let len = ...;
let size = core::mem::size_of::<T>();
// on most arches we can use `isize::MAX as usize`
// instead of `usize::MAX`, but IIRC not everywhere
if size != 0 && len > usize::MAX / size {
unsafe { core::hint::unreachable_unchecked() }
}
len
}