Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 5428a15

Browse files
committedApr 7, 2024
Don't change the otherwise of the switch
1 parent bef50f1 commit 5428a15

4 files changed

+20
-10
lines changed
 

‎compiler/rustc_mir_transform/src/early_otherwise_branch.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,8 @@ impl<'tcx> MirPass<'tcx> for EarlyOtherwiseBranch {
168168
};
169169
(value, targets.target_for_value(value))
170170
});
171-
let eq_targets = SwitchTargets::new(eq_new_targets, opt_data.destination);
171+
// The otherwise either is the same target branch or an unreachable.
172+
let eq_targets = SwitchTargets::new(eq_new_targets, parent_targets.otherwise());
172173

173174
// Create `bbEq` in example above
174175
let eq_switch = BasicBlockData::new(Some(Terminator {

‎tests/mir-opt/early_otherwise_branch.opt3.EarlyOtherwiseBranch.diff

+6-3
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
+ StorageLive(_13);
3838
+ _13 = Ne(_9, move _12);
3939
+ StorageDead(_12);
40-
+ switchInt(move _13) -> [0: bb6, otherwise: bb1];
40+
+ switchInt(move _13) -> [0: bb7, otherwise: bb1];
4141
}
4242

4343
bb1: {
@@ -95,10 +95,13 @@
9595
}
9696

9797
- bb9: {
98-
- unreachable;
9998
+ bb6: {
99+
unreachable;
100+
+ }
101+
+
102+
+ bb7: {
100103
+ StorageDead(_13);
101-
+ switchInt(_9) -> [0: bb2, 1: bb3, 2: bb4, otherwise: bb1];
104+
+ switchInt(_9) -> [0: bb2, 1: bb3, 2: bb4, otherwise: bb6];
102105
}
103106
}
104107

‎tests/mir-opt/early_otherwise_branch.opt4.EarlyOtherwiseBranch.diff

+6-3
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
+ StorageLive(_13);
3838
+ _13 = Ne(_9, move _12);
3939
+ StorageDead(_12);
40-
+ switchInt(move _13) -> [0: bb6, otherwise: bb1];
40+
+ switchInt(move _13) -> [0: bb7, otherwise: bb1];
4141
}
4242

4343
bb1: {
@@ -95,10 +95,13 @@
9595
}
9696

9797
- bb9: {
98-
- unreachable;
9998
+ bb6: {
99+
unreachable;
100+
+ }
101+
+
102+
+ bb7: {
100103
+ StorageDead(_13);
101-
+ switchInt(_9) -> [0: bb2, 1: bb3, 2: bb4, otherwise: bb1];
104+
+ switchInt(_9) -> [0: bb2, 1: bb3, 2: bb4, otherwise: bb6];
102105
}
103106
}
104107

‎tests/mir-opt/early_otherwise_branch_3_element_tuple.opt2.EarlyOtherwiseBranch.diff

+6-3
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@
4747
+ StorageLive(_19);
4848
+ _19 = Ne(_14, move _18);
4949
+ StorageDead(_18);
50-
+ switchInt(move _19) -> [0: bb9, otherwise: bb1];
50+
+ switchInt(move _19) -> [0: bb10, otherwise: bb1];
5151
}
5252

5353
bb1: {
@@ -129,10 +129,13 @@
129129
}
130130

131131
- bb12: {
132-
- unreachable;
133132
+ bb9: {
133+
unreachable;
134+
+ }
135+
+
136+
+ bb10: {
134137
+ StorageDead(_19);
135-
+ switchInt(_14) -> [0: bb2, 1: bb3, 2: bb4, otherwise: bb1];
138+
+ switchInt(_14) -> [0: bb2, 1: bb3, 2: bb4, otherwise: bb9];
136139
}
137140
}
138141

0 commit comments

Comments
 (0)
Failed to load comments.