about summary refs log tree commit diff
diff options
context:
space:
mode:
authorDianQK <dianqk@dianqk.net>2024-03-12 22:34:02 +0800
committerDianQK <dianqk@dianqk.net>2024-04-08 19:20:07 +0800
commit166bb1bd463dbf6cd3bade6a6b1434884666f032 (patch)
tree4406c63947bbf13705b1ba2d8dc53a9a7820f211
parent928c57dc9ad4caf66770235aab1a6850acebd649 (diff)
downloadrust-166bb1bd463dbf6cd3bade6a6b1434884666f032.tar.gz
rust-166bb1bd463dbf6cd3bade6a6b1434884666f032.zip
Don't change the otherwise of the switch
-rw-r--r--compiler/rustc_mir_transform/src/early_otherwise_branch.rs3
-rw-r--r--tests/mir-opt/early_otherwise_branch.opt3.EarlyOtherwiseBranch.diff9
-rw-r--r--tests/mir-opt/early_otherwise_branch.opt4.EarlyOtherwiseBranch.diff9
-rw-r--r--tests/mir-opt/early_otherwise_branch_3_element_tuple.opt2.EarlyOtherwiseBranch.diff9
4 files changed, 20 insertions, 10 deletions
diff --git a/compiler/rustc_mir_transform/src/early_otherwise_branch.rs b/compiler/rustc_mir_transform/src/early_otherwise_branch.rs
index 007c98217c0..9edb8bcee6e 100644
--- a/compiler/rustc_mir_transform/src/early_otherwise_branch.rs
+++ b/compiler/rustc_mir_transform/src/early_otherwise_branch.rs
@@ -168,7 +168,8 @@ impl<'tcx> MirPass<'tcx> for EarlyOtherwiseBranch {
                 };
                 (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
             let eq_switch = BasicBlockData::new(Some(Terminator {
diff --git a/tests/mir-opt/early_otherwise_branch.opt3.EarlyOtherwiseBranch.diff b/tests/mir-opt/early_otherwise_branch.opt3.EarlyOtherwiseBranch.diff
index d93c609c051..b41e952d80f 100644
--- a/tests/mir-opt/early_otherwise_branch.opt3.EarlyOtherwiseBranch.diff
+++ b/tests/mir-opt/early_otherwise_branch.opt3.EarlyOtherwiseBranch.diff
@@ -37,7 +37,7 @@
 +         StorageLive(_13);
 +         _13 = Ne(_9, move _12);
 +         StorageDead(_12);
-+         switchInt(move _13) -> [0: bb6, otherwise: bb1];
++         switchInt(move _13) -> [0: bb7, otherwise: bb1];
       }
   
       bb1: {
@@ -95,10 +95,13 @@
       }
   
 -     bb9: {
--         unreachable;
 +     bb6: {
+          unreachable;
++     }
++ 
++     bb7: {
 +         StorageDead(_13);
-+         switchInt(_9) -> [0: bb2, 1: bb3, 2: bb4, otherwise: bb1];
++         switchInt(_9) -> [0: bb2, 1: bb3, 2: bb4, otherwise: bb6];
       }
   }
   
diff --git a/tests/mir-opt/early_otherwise_branch.opt4.EarlyOtherwiseBranch.diff b/tests/mir-opt/early_otherwise_branch.opt4.EarlyOtherwiseBranch.diff
index afdf7d3c576..18dea56f430 100644
--- a/tests/mir-opt/early_otherwise_branch.opt4.EarlyOtherwiseBranch.diff
+++ b/tests/mir-opt/early_otherwise_branch.opt4.EarlyOtherwiseBranch.diff
@@ -37,7 +37,7 @@
 +         StorageLive(_13);
 +         _13 = Ne(_9, move _12);
 +         StorageDead(_12);
-+         switchInt(move _13) -> [0: bb6, otherwise: bb1];
++         switchInt(move _13) -> [0: bb7, otherwise: bb1];
       }
   
       bb1: {
@@ -95,10 +95,13 @@
       }
   
 -     bb9: {
--         unreachable;
 +     bb6: {
+          unreachable;
++     }
++ 
++     bb7: {
 +         StorageDead(_13);
-+         switchInt(_9) -> [0: bb2, 1: bb3, 2: bb4, otherwise: bb1];
++         switchInt(_9) -> [0: bb2, 1: bb3, 2: bb4, otherwise: bb6];
       }
   }
   
diff --git a/tests/mir-opt/early_otherwise_branch_3_element_tuple.opt2.EarlyOtherwiseBranch.diff b/tests/mir-opt/early_otherwise_branch_3_element_tuple.opt2.EarlyOtherwiseBranch.diff
index 89a06a7669d..0ea7a10baaa 100644
--- a/tests/mir-opt/early_otherwise_branch_3_element_tuple.opt2.EarlyOtherwiseBranch.diff
+++ b/tests/mir-opt/early_otherwise_branch_3_element_tuple.opt2.EarlyOtherwiseBranch.diff
@@ -47,7 +47,7 @@
 +         StorageLive(_19);
 +         _19 = Ne(_14, move _18);
 +         StorageDead(_18);
-+         switchInt(move _19) -> [0: bb9, otherwise: bb1];
++         switchInt(move _19) -> [0: bb10, otherwise: bb1];
       }
   
       bb1: {
@@ -129,10 +129,13 @@
       }
   
 -     bb12: {
--         unreachable;
 +     bb9: {
+          unreachable;
++     }
++ 
++     bb10: {
 +         StorageDead(_19);
-+         switchInt(_14) -> [0: bb2, 1: bb3, 2: bb4, otherwise: bb1];
++         switchInt(_14) -> [0: bb2, 1: bb3, 2: bb4, otherwise: bb9];
       }
   }