about summary refs log tree commit diff
diff options
context:
space:
mode:
authorDianQK <dianqk@dianqk.net>2024-03-09 11:58:36 +0800
committerDianQK <dianqk@dianqk.net>2024-03-13 22:35:11 +0800
commit102bda49b1889cf7c42d9338b797d301f54256a5 (patch)
tree106d25993ae6623719f4b50b9c4837021e11dd41
parentf8656ef6e9f4d5f2a05c1a76af21bd201eebd123 (diff)
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.
-rw-r--r--compiler/rustc_mir_transform/src/unreachable_enum_branching.rs5
1 files changed, 4 insertions, 1 deletions
diff --git a/compiler/rustc_mir_transform/src/unreachable_enum_branching.rs b/compiler/rustc_mir_transform/src/unreachable_enum_branching.rs
index 52bd0bea37d..66b6235eb93 100644
--- a/compiler/rustc_mir_transform/src/unreachable_enum_branching.rs
+++ b/compiler/rustc_mir_transform/src/unreachable_enum_branching.rs
@@ -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());