Open
Description
From a conversation on the Discord Rust Community Server:
Impl 1:
pub fn f1(x: i32, y: i32, z: i32) -> i32 {
[x, y, z].into_iter().max().unwrap()
}
Impl 2:
pub fn f2(x: i32, y: i32, z: i32) -> i32 {
*[x, y, z].iter().max().unwrap()
}
Godbolt: https://godbolt.org/z/G37cqbfdE
These functions should be equivalent, but the first function generates way more code than it needs to. I expected the code to be equivalent.
There is another interesting combination: for u64
, the code on 1.68 looks identical, but on nightly it's even bigger.
Metadata
Metadata
Assignees
Labels
Area: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues.Area: IteratorsCategory: This is a bug.Category: An issue highlighting optimization opportunities or PRs implementing suchIssue: Problems and improvements with respect to performance of generated code.