Open
Description
Rust currently emits dereferenceable
attributes/metadata for pointers to Sized
types. The number of bytes in dereferenceable
attributes/metadata must be a constant, so cannot be used for pointers to dynamically sized types like [T]
, str
. But assume
operand bundles can be non-constants. So for pointers to DSTs, Rust should emit appropriate assume
s.
Currently LLVM does not make use of variable-sized dereferenceable
assumptions, but that may be changing soon, so it would be good if Rust could exploit this once it is added.
fn ptr_to_slice_u8(xs: &[u8]) {}
fn ptr_to_slice_u16(xs: &[u16]) {}
define void @ptr_to_slice_u8(ptr noalias nocapture noundef nonnull readonly align 1 %xs.0, i64 noundef %xs.1) unnamed_addr #0 {
call void @llvm.assume(i1 true) [ "dereferenceable"(ptr %xs.0, i64 %xs.1) ]
ret void
}
define void @ptr_to_slice_u16(ptr noalias nocapture noundef nonnull readonly align 2 %xs.0, i64 noundef %xs.1) unnamed_addr #0 {
%len_bytes = mul nsw nuw i64 %xs.1, 2
call void @llvm.assume(i1 true) [ "dereferenceable"(ptr %xs.0, i64 %len_bytes) ]
ret void
}
Metadata
Metadata
Assignees
Labels
Area: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues.Area: Code generationCategory: This is a bug.Issue: Problems and improvements with respect to performance of generated code.Relevant to the compiler team, which will review and decide on the PR/issue.