-
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.A-iteratorsArea: IteratorsArea: IteratorsC-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.P-mediumMedium priorityMedium priorityT-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.WG-llvmWorking group: LLVM backend code generationWorking group: LLVM backend code generationregression-from-stable-to-stablePerformance or correctness regression from one stable version to another.Performance or correctness regression from one stable version to another.
Description
Consider these three functions:
pub fn in_range1(x: [usize; 3], m: usize) -> bool {
(x[0] < m) && (x[1] < m) && (x[2] < m)
}
pub fn in_range2(x: [usize; 3], m: usize) -> bool {
for k in &x {
if *k >= m {
return false;
}
}
true
}
pub fn in_range3(x: [usize; 3], m: usize) -> bool {
x.iter().cloned().all(|k| k < m)
}
I'd expect all of them to generate roughly the same code since our array x
has a fixed compile-time size. With rustc 1.27.1 it does, but after that it seems there was a regression that causes the compiler to forget the size of the array and generate generic code rather than code specific for the array size when an iterator is used.
Particularly damning is that the compiler generates an unrolled loop which is dead code as our array isn't large enough to ever qualify for unrolling.
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.A-iteratorsArea: IteratorsArea: IteratorsC-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.P-mediumMedium priorityMedium priorityT-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.WG-llvmWorking group: LLVM backend code generationWorking group: LLVM backend code generationregression-from-stable-to-stablePerformance or correctness regression from one stable version to another.Performance or correctness regression from one stable version to another.