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

Missed optimization with reserve and extend_from_slice #123944

Open
SUPERCILEX opened this issue Apr 14, 2024 · 0 comments
Open

Missed optimization with reserve and extend_from_slice #123944

SUPERCILEX opened this issue Apr 14, 2024 · 0 comments
Labels
A-codegen Area: Code generation A-LLVM Area: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues. C-optimization Category: An issue highlighting optimization opportunities or PRs implementing such T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@SUPERCILEX
Copy link
Contributor

SUPERCILEX commented Apr 14, 2024

I tried this code:

pub fn zzz(v: &mut Vec<u8>, s: &[u8]) {
    v.reserve(s.len());
    v.extend_from_slice(s);
}

I expected to see this happen: only one do_reserve_and_handle call.

Instead, this happened: extend_from_slice stills checks the capacity and calls reserve. It seems like LLVM assumes aren't able to bubble up out of multiple functions. I was able to get the optimization to work in #119465 but it required putting assumes in every function along the reserve chain.

@SUPERCILEX SUPERCILEX added the C-bug Category: This is a bug. label Apr 14, 2024
@rustbot rustbot added the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Apr 14, 2024
@jieyouxu jieyouxu added A-LLVM Area: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues. A-codegen Area: Code generation T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. C-optimization Category: An issue highlighting optimization opportunities or PRs implementing such and removed C-bug Category: This is a bug. needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. labels Apr 15, 2024
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-optimization Category: An issue highlighting optimization opportunities or PRs implementing such 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