-
Notifications
You must be signed in to change notification settings - Fork 13.6k
Open
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.C-optimizationCategory: An issue highlighting optimization opportunities or PRs implementing suchCategory: An issue highlighting optimization opportunities or PRs implementing suchI-slowIssue: Problems and improvements with respect to performance of generated code.Issue: Problems and improvements with respect to performance of generated code.
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
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.C-optimizationCategory: An issue highlighting optimization opportunities or PRs implementing suchCategory: An issue highlighting optimization opportunities or PRs implementing suchI-slowIssue: Problems and improvements with respect to performance of generated code.Issue: Problems and improvements with respect to performance of generated code.