Closed
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
Area: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues.Area: IteratorsCategory: This is a bug.Issue: Problems and improvements with respect to performance of generated code.Medium priorityRelevant to the compiler team, which will review and decide on the PR/issue.Working group: LLVM backend code generationPerformance or correctness regression from one stable version to another.