Repository navigation
Missed optimization when using split_first #109328
Copy link
Copy link
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.C-enhancementCategory: An issue proposing an enhancement or a PR with one.Category: An issue proposing an enhancement or a PR with one.C-optimizationCategory: An issue highlighting optimization opportunities or PRs implementing suchCategory: An issue highlighting optimization opportunities or PRs implementing suchE-needs-testCall for participation: An issue has been fixed and does not reproduce, but no test has been added.Call for participation: An issue has been fixed and does not reproduce, but no test has been added.I-slowIssue: Problems and improvements with respect to performance of generated code.Issue: Problems and improvements with respect to performance of generated code.T-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.
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.
Reactions are currently unavailable
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.C-enhancementCategory: An issue proposing an enhancement or a PR with one.Category: An issue proposing an enhancement or a PR with one.C-optimizationCategory: An issue highlighting optimization opportunities or PRs implementing suchCategory: An issue highlighting optimization opportunities or PRs implementing suchE-needs-testCall for participation: An issue has been fixed and does not reproduce, but no test has been added.Call for participation: An issue has been fixed and does not reproduce, but no test has been added.I-slowIssue: Problems and improvements with respect to performance of generated code.Issue: Problems and improvements with respect to performance of generated code.T-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.
Activity
JakobDegen commentedon Mar 18, 2023
Quoting myself on Zulip:
nikic commentedon Mar 19, 2023
This is a metadata preservation failure during SimplifyCFG speculation: https://llvm.godbolt.org/z/frs8o853f
Preserving
!nonnullhere used to be illegal, but thanks to https://reviews.llvm.org/D141386 we are allowed to preserve it now. Only need to drop!noundef.nikic commentedon Mar 22, 2023
Upstream patch: https://reviews.llvm.org/D146629
nikic commentedon Aug 14, 2023
Fixed by #114048, needs codegen test.
add codegen test for rust-lang#109328
add codegen test for rust-lang#109328
add codegen test for rust-lang#109328
Auto merge of rust-lang#125347 - tesuji:needtests, r=nikic
Auto merge of rust-lang#125347 - tesuji:needtests, r=nikic
Auto merge of rust-lang#125347 - tesuji:needtests, r=nikic
Auto merge of rust-lang#125347 - tesuji:needtests, r=nikic
Auto merge of rust-lang#125347 - tesuji:needtests, r=nikic
Rollup merge of rust-lang#126906 - GrigorenkoPV:fixme-split_at_first,…
Rollup merge of rust-lang#126906 - GrigorenkoPV:fixme-split_at_first,…
Rollup merge of rust-lang#126906 - GrigorenkoPV:fixme-split_at_first,…
Unrolled build for rust-lang#126906