Don't change the otherwise of the switch

This commit is contained in:
DianQK 2024-03-12 22:34:02 +08:00
parent 928c57dc9a
commit 166bb1bd46
No known key found for this signature in database
4 changed files with 20 additions and 10 deletions

View File

@ -168,7 +168,8 @@ fn run_pass(&self, tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) {
}; };
(value, targets.target_for_value(value)) (value, targets.target_for_value(value))
}); });
let eq_targets = SwitchTargets::new(eq_new_targets, opt_data.destination); // The otherwise either is the same target branch or an unreachable.
let eq_targets = SwitchTargets::new(eq_new_targets, parent_targets.otherwise());
// Create `bbEq` in example above // Create `bbEq` in example above
let eq_switch = BasicBlockData::new(Some(Terminator { let eq_switch = BasicBlockData::new(Some(Terminator {

View File

@ -37,7 +37,7 @@
+ StorageLive(_13); + StorageLive(_13);
+ _13 = Ne(_9, move _12); + _13 = Ne(_9, move _12);
+ StorageDead(_12); + StorageDead(_12);
+ switchInt(move _13) -> [0: bb6, otherwise: bb1]; + switchInt(move _13) -> [0: bb7, otherwise: bb1];
} }
bb1: { bb1: {
@ -95,10 +95,13 @@
} }
- bb9: { - bb9: {
- unreachable;
+ bb6: { + bb6: {
unreachable;
+ }
+
+ bb7: {
+ StorageDead(_13); + StorageDead(_13);
+ switchInt(_9) -> [0: bb2, 1: bb3, 2: bb4, otherwise: bb1]; + switchInt(_9) -> [0: bb2, 1: bb3, 2: bb4, otherwise: bb6];
} }
} }

View File

@ -37,7 +37,7 @@
+ StorageLive(_13); + StorageLive(_13);
+ _13 = Ne(_9, move _12); + _13 = Ne(_9, move _12);
+ StorageDead(_12); + StorageDead(_12);
+ switchInt(move _13) -> [0: bb6, otherwise: bb1]; + switchInt(move _13) -> [0: bb7, otherwise: bb1];
} }
bb1: { bb1: {
@ -95,10 +95,13 @@
} }
- bb9: { - bb9: {
- unreachable;
+ bb6: { + bb6: {
unreachable;
+ }
+
+ bb7: {
+ StorageDead(_13); + StorageDead(_13);
+ switchInt(_9) -> [0: bb2, 1: bb3, 2: bb4, otherwise: bb1]; + switchInt(_9) -> [0: bb2, 1: bb3, 2: bb4, otherwise: bb6];
} }
} }

View File

@ -47,7 +47,7 @@
+ StorageLive(_19); + StorageLive(_19);
+ _19 = Ne(_14, move _18); + _19 = Ne(_14, move _18);
+ StorageDead(_18); + StorageDead(_18);
+ switchInt(move _19) -> [0: bb9, otherwise: bb1]; + switchInt(move _19) -> [0: bb10, otherwise: bb1];
} }
bb1: { bb1: {
@ -129,10 +129,13 @@
} }
- bb12: { - bb12: {
- unreachable;
+ bb9: { + bb9: {
unreachable;
+ }
+
+ bb10: {
+ StorageDead(_19); + StorageDead(_19);
+ switchInt(_14) -> [0: bb2, 1: bb3, 2: bb4, otherwise: bb1]; + switchInt(_14) -> [0: bb2, 1: bb3, 2: bb4, otherwise: bb9];
} }
} }