Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Emit dereferenceable assumptions for slices #137568

Open
Kmeakin opened this issue Feb 24, 2025 · 1 comment
Open

Emit dereferenceable assumptions for slices #137568

Kmeakin opened this issue Feb 24, 2025 · 1 comment
Labels
A-codegen Area: Code generation A-LLVM Area: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues. C-bug Category: This is a bug. I-slow Issue: Problems and improvements with respect to performance of generated code. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@Kmeakin
Copy link
Contributor

Kmeakin commented Feb 24, 2025

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 assumes.

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
}
@Kmeakin Kmeakin added the C-bug Category: This is a bug. label Feb 24, 2025
@rustbot rustbot added the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Feb 24, 2025
@Kmeakin
Copy link
Contributor Author

Kmeakin commented Feb 24, 2025

@rustbot label +I-slow +A-llvm

@rustbot rustbot added A-LLVM Area: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues. I-slow Issue: Problems and improvements with respect to performance of generated code. labels Feb 24, 2025
@saethlin saethlin added A-codegen Area: Code generation T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. and removed needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. labels Feb 24, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-codegen Area: Code generation A-LLVM Area: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues. C-bug Category: This is a bug. I-slow Issue: Problems and improvements with respect to performance of generated code. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

3 participants