Closed
Description
Impl 1:
pub fn f(input: &mut &[u64]) -> Option<u64> {
match input {
[] => None,
[first, rest @ ..] => {
*input = rest;
Some(*first)
}
}
}
Impl 2:
pub fn f(input: &mut &[u64]) -> Option<u64> {
let (first, rest) = input.split_first()?;
*input = rest;
Some(*first)
}
Godbolt: https://godbolt.org/z/aasq15z7a
These functions should be equivalent, but the second function generates one more if than the first one. This also happens when using .get(0)
and then doing the slicing manually. I expected the impls to generate the same code.
Metadata
Metadata
Assignees
Labels
Area: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues.Category: An issue proposing an enhancement or a PR with one.Category: An issue highlighting optimization opportunities or PRs implementing suchCall for participation: An issue has been fixed and does not reproduce, but no test has been added.Issue: Problems and improvements with respect to performance of generated code.Relevant to the compiler team, which will review and decide on the PR/issue.