-
Notifications
You must be signed in to change notification settings - Fork 13.7k
Closed
Labels
A-LLVMArea: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues.Area: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues.C-bugCategory: This is a bug.Category: This is a bug.I-slowIssue: Problems and improvements with respect to performance of generated code.Issue: Problems and improvements with respect to performance of generated code.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.
Description
When using a loop and checking exact bounds upfront, vectorized instructions are used:
pub fn xorl(a: &[u8], b: &[u8], c: &mut [u8]) {
let (a_bound, b_bound, c_bound) = (&a[..1024], &b[..1024], &mut c[..1024]);
for i in 0..1024 {
c[i] = a[i] ^ b[i];
}
}
However when the upfront checks actually tests for a bigger slice size, the same optimizations are not applied:
pub fn xorl(a: &[u8], b: &[u8], c: &mut [u8]) {
let (a_bound, b_bound, c_bound) = (&a[..2048], &b[..2048], &mut c[..2048]);
for i in 0..1024 {
c[i] = a[i] ^ b[i];
}
}
Since slices of size 2048 are always also at least of size 1024, I would expect the generated code to be equivalent.
Meta
rustc --version --verbose
:
Happens on nightly as well as 1.40 - as seen in Godbolt
leonardo-m and HadrienG2
Metadata
Metadata
Assignees
Labels
A-LLVMArea: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues.Area: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues.C-bugCategory: This is a bug.Category: This is a bug.I-slowIssue: Problems and improvements with respect to performance of generated code.Issue: Problems and improvements with respect to performance of generated code.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.