Open
Description
When creating a structure which has a variant type, and that this type is wrapped as an Option<T>
, the unwrap
branch cannot be removed by LLVM, even after proving that the only path reachable is the Some(…)
case and never the None
case.
I tried this code:
Calling the previous function as:
assert!(self.top != 0);
let v = self.pop().unwrap();
This hint LLVM that the self.top == 0
branch does not need to be generated. However, the unwrap condition remains as the None
value is folded within the variant and that LLVM does not know about it.
I think the Rust compiler should give range analysis information that the None
value would never be part of the variant, and as such let LLVM remove the unwrapping condition from the generated code.
Meta
Tested with both rustc --version --verbose
:
rustc 1.42.0 (b8cedc004 2020-03-09)
binary: rustc
commit-hash: b8cedc00407a4c56a3bda1ed605c6fc166655447
commit-date: 2020-03-09
host: x86_64-unknown-linux-gnu
release: 1.42.0
LLVM version: 9.0
and
rustc 1.44.0-nightly (7f3df5772 2020-04-16)
binary: rustc
commit-hash: 7f3df5772439eee1c512ed2eb540beef1124d236
commit-date: 2020-04-16
host: x86_64-unknown-linux-gnu
release: 1.44.0-nightly
LLVM version: 9.0
Metadata
Metadata
Assignees
Labels
Area: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues.Category: This is a bug.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.Status: A Minimal Complete and Verifiable Example has been found for this issueRelevant to the compiler team, which will review and decide on the PR/issue.