-
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.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.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
See the following code:
pub struct ListNode {
next: Option<Box<ListNode>>
}
pub fn foo(mut head: Box<ListNode>) -> Box<ListNode> {
let mut cur = &mut head;
while let Some(next) = std::mem::replace(&mut cur.next, None) {
cur.next = Some(next);
cur = cur.next.as_mut().unwrap();
}
head
}
Apparently the unwrap
should never panic given the assignment in the previous line. However, based on the assembly output, that check isn't optimized away.
(The while let
statement seems to be generating useless function calls for drop as well, btw.)
LifeIsStrange, drrlvn, anyputer, ondj, scottmcm and 8 moreRudxain
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-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.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.