Remove restrictions on small enum statements such as Order, Option or Result

`early-tailduplication` is only a problem when there are a significant number of branches.
This commit is contained in:
DianQK 2024-03-09 11:58:36 +08:00
parent f8656ef6e9
commit 102bda49b1
No known key found for this signature in database
GPG key ID: 46BDB1AC96C48912

View file

@ -175,7 +175,10 @@ impl<'tcx> MirPass<'tcx> for UnreachableEnumBranching {
// ```
let otherwise_is_last_variant = !otherwise_is_empty_unreachable
&& allowed_variants.len() == 1
&& check_successors(&body.basic_blocks, targets.otherwise());
// Despite the LLVM issue, we hope that small enum can still be transformed.
// This is valuable for both `a <= b` and `if let Some/Ok(v)`.
&& (targets.all_targets().len() <= 3
|| check_successors(&body.basic_blocks, targets.otherwise()));
let replace_otherwise_to_unreachable = otherwise_is_last_variant
|| (!otherwise_is_empty_unreachable && allowed_variants.is_empty());