about summary refs log tree commit diff
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/mir-opt/matches_reduce_branches.match_i128_u128.MatchBranchSimplification.diff61
-rw-r--r--tests/mir-opt/matches_reduce_branches.match_i16_i8.MatchBranchSimplification.diff37
-rw-r--r--tests/mir-opt/matches_reduce_branches.match_i8_i16.MatchBranchSimplification.diff37
-rw-r--r--tests/mir-opt/matches_reduce_branches.match_i8_i16_failed.MatchBranchSimplification.diff37
-rw-r--r--tests/mir-opt/matches_reduce_branches.match_sext_i8_i16.MatchBranchSimplification.diff52
-rw-r--r--tests/mir-opt/matches_reduce_branches.match_sext_i8_i16_failed.MatchBranchSimplification.diff47
-rw-r--r--tests/mir-opt/matches_reduce_branches.match_sext_i8_u16.MatchBranchSimplification.diff52
-rw-r--r--tests/mir-opt/matches_reduce_branches.match_sext_i8_u16_failed.MatchBranchSimplification.diff47
-rw-r--r--tests/mir-opt/matches_reduce_branches.match_trunc_i16_i8.MatchBranchSimplification.diff77
-rw-r--r--tests/mir-opt/matches_reduce_branches.match_trunc_i16_i8_failed.MatchBranchSimplification.diff72
-rw-r--r--tests/mir-opt/matches_reduce_branches.match_trunc_i16_u8.MatchBranchSimplification.diff77
-rw-r--r--tests/mir-opt/matches_reduce_branches.match_trunc_i16_u8_failed.MatchBranchSimplification.diff72
-rw-r--r--tests/mir-opt/matches_reduce_branches.match_trunc_u16_i8.MatchBranchSimplification.diff67
-rw-r--r--tests/mir-opt/matches_reduce_branches.match_trunc_u16_i8_failed.MatchBranchSimplification.diff62
-rw-r--r--tests/mir-opt/matches_reduce_branches.match_trunc_u16_u8.MatchBranchSimplification.diff67
-rw-r--r--tests/mir-opt/matches_reduce_branches.match_trunc_u16_u8_failed.MatchBranchSimplification.diff62
-rw-r--r--tests/mir-opt/matches_reduce_branches.match_u8_i16.MatchBranchSimplification.diff32
-rw-r--r--tests/mir-opt/matches_reduce_branches.match_u8_i16_2.MatchBranchSimplification.diff26
-rw-r--r--tests/mir-opt/matches_reduce_branches.match_u8_i16_failed.MatchBranchSimplification.diff32
-rw-r--r--tests/mir-opt/matches_reduce_branches.match_u8_i16_fallback.MatchBranchSimplification.diff31
-rw-r--r--tests/mir-opt/matches_reduce_branches.match_u8_i8.MatchBranchSimplification.diff47
-rw-r--r--tests/mir-opt/matches_reduce_branches.match_u8_i8_2.MatchBranchSimplification.diff80
-rw-r--r--tests/mir-opt/matches_reduce_branches.match_u8_i8_2_failed.MatchBranchSimplification.diff74
-rw-r--r--tests/mir-opt/matches_reduce_branches.match_u8_i8_failed.MatchBranchSimplification.diff42
-rw-r--r--tests/mir-opt/matches_reduce_branches.match_u8_i8_failed_len_1.MatchBranchSimplification.diff42
-rw-r--r--tests/mir-opt/matches_reduce_branches.match_u8_i8_failed_len_2.MatchBranchSimplification.diff42
-rw-r--r--tests/mir-opt/matches_reduce_branches.match_u8_i8_fallback.MatchBranchSimplification.diff38
-rw-r--r--tests/mir-opt/matches_reduce_branches.match_u8_u16.MatchBranchSimplification.diff37
-rw-r--r--tests/mir-opt/matches_reduce_branches.match_u8_u16_2.MatchBranchSimplification.diff37
-rw-r--r--tests/mir-opt/matches_reduce_branches.match_zext_u8_i16.MatchBranchSimplification.diff47
-rw-r--r--tests/mir-opt/matches_reduce_branches.match_zext_u8_i16_failed.MatchBranchSimplification.diff42
-rw-r--r--tests/mir-opt/matches_reduce_branches.match_zext_u8_u16.MatchBranchSimplification.diff47
-rw-r--r--tests/mir-opt/matches_reduce_branches.match_zext_u8_u16_failed.MatchBranchSimplification.diff42
-rw-r--r--tests/mir-opt/matches_reduce_branches.rs579
-rw-r--r--tests/mir-opt/matches_u8.exhaustive_match.MatchBranchSimplification.diff41
-rw-r--r--tests/mir-opt/matches_u8.exhaustive_match_i8.MatchBranchSimplification.diff41
-rw-r--r--tests/mir-opt/matches_u8.rs1
37 files changed, 1856 insertions, 470 deletions
diff --git a/tests/mir-opt/matches_reduce_branches.match_i128_u128.MatchBranchSimplification.diff b/tests/mir-opt/matches_reduce_branches.match_i128_u128.MatchBranchSimplification.diff
index dc50ae95472..fc34ce7125e 100644
--- a/tests/mir-opt/matches_reduce_branches.match_i128_u128.MatchBranchSimplification.diff
+++ b/tests/mir-opt/matches_reduce_branches.match_i128_u128.MatchBranchSimplification.diff
@@ -5,37 +5,42 @@
       debug i => _1;
       let mut _0: u128;
       let mut _2: i128;
++     let mut _3: i128;
   
       bb0: {
           _2 = discriminant(_1);
-          switchInt(move _2) -> [1: bb5, 2: bb4, 3: bb3, 340282366920938463463374607431768211455: bb2, otherwise: bb1];
-      }
-  
-      bb1: {
-          unreachable;
-      }
-  
-      bb2: {
-          _0 = const core::num::<impl u128>::MAX;
-          goto -> bb6;
-      }
-  
-      bb3: {
-          _0 = const 3_u128;
-          goto -> bb6;
-      }
-  
-      bb4: {
-          _0 = const 2_u128;
-          goto -> bb6;
-      }
-  
-      bb5: {
-          _0 = const 1_u128;
-          goto -> bb6;
-      }
-  
-      bb6: {
+-         switchInt(move _2) -> [1: bb5, 2: bb4, 3: bb3, 340282366920938463463374607431768211455: bb2, otherwise: bb1];
+-     }
+- 
+-     bb1: {
+-         unreachable;
+-     }
+- 
+-     bb2: {
+-         _0 = const core::num::<impl u128>::MAX;
+-         goto -> bb6;
+-     }
+- 
+-     bb3: {
+-         _0 = const 3_u128;
+-         goto -> bb6;
+-     }
+- 
+-     bb4: {
+-         _0 = const 2_u128;
+-         goto -> bb6;
+-     }
+- 
+-     bb5: {
+-         _0 = const 1_u128;
+-         goto -> bb6;
+-     }
+- 
+-     bb6: {
++         StorageLive(_3);
++         _3 = move _2;
++         _0 = _3 as u128 (IntToInt);
++         StorageDead(_3);
           return;
       }
   }
diff --git a/tests/mir-opt/matches_reduce_branches.match_i16_i8.MatchBranchSimplification.diff b/tests/mir-opt/matches_reduce_branches.match_i16_i8.MatchBranchSimplification.diff
deleted file mode 100644
index 3514914b8ec..00000000000
--- a/tests/mir-opt/matches_reduce_branches.match_i16_i8.MatchBranchSimplification.diff
+++ /dev/null
@@ -1,37 +0,0 @@
-- // MIR for `match_i16_i8` before MatchBranchSimplification
-+ // MIR for `match_i16_i8` after MatchBranchSimplification
-  
-  fn match_i16_i8(_1: EnumAi16) -> i8 {
-      debug i => _1;
-      let mut _0: i8;
-      let mut _2: i16;
-  
-      bb0: {
-          _2 = discriminant(_1);
-          switchInt(move _2) -> [65535: bb4, 2: bb3, 65533: bb2, otherwise: bb1];
-      }
-  
-      bb1: {
-          unreachable;
-      }
-  
-      bb2: {
-          _0 = const -3_i8;
-          goto -> bb5;
-      }
-  
-      bb3: {
-          _0 = const 2_i8;
-          goto -> bb5;
-      }
-  
-      bb4: {
-          _0 = const -1_i8;
-          goto -> bb5;
-      }
-  
-      bb5: {
-          return;
-      }
-  }
-  
diff --git a/tests/mir-opt/matches_reduce_branches.match_i8_i16.MatchBranchSimplification.diff b/tests/mir-opt/matches_reduce_branches.match_i8_i16.MatchBranchSimplification.diff
deleted file mode 100644
index ff4255ec8cc..00000000000
--- a/tests/mir-opt/matches_reduce_branches.match_i8_i16.MatchBranchSimplification.diff
+++ /dev/null
@@ -1,37 +0,0 @@
-- // MIR for `match_i8_i16` before MatchBranchSimplification
-+ // MIR for `match_i8_i16` after MatchBranchSimplification
-  
-  fn match_i8_i16(_1: EnumAi8) -> i16 {
-      debug i => _1;
-      let mut _0: i16;
-      let mut _2: i8;
-  
-      bb0: {
-          _2 = discriminant(_1);
-          switchInt(move _2) -> [255: bb4, 2: bb3, 253: bb2, otherwise: bb1];
-      }
-  
-      bb1: {
-          unreachable;
-      }
-  
-      bb2: {
-          _0 = const -3_i16;
-          goto -> bb5;
-      }
-  
-      bb3: {
-          _0 = const 2_i16;
-          goto -> bb5;
-      }
-  
-      bb4: {
-          _0 = const -1_i16;
-          goto -> bb5;
-      }
-  
-      bb5: {
-          return;
-      }
-  }
-  
diff --git a/tests/mir-opt/matches_reduce_branches.match_i8_i16_failed.MatchBranchSimplification.diff b/tests/mir-opt/matches_reduce_branches.match_i8_i16_failed.MatchBranchSimplification.diff
deleted file mode 100644
index 022039ecee6..00000000000
--- a/tests/mir-opt/matches_reduce_branches.match_i8_i16_failed.MatchBranchSimplification.diff
+++ /dev/null
@@ -1,37 +0,0 @@
-- // MIR for `match_i8_i16_failed` before MatchBranchSimplification
-+ // MIR for `match_i8_i16_failed` after MatchBranchSimplification
-  
-  fn match_i8_i16_failed(_1: EnumAi8) -> i16 {
-      debug i => _1;
-      let mut _0: i16;
-      let mut _2: i8;
-  
-      bb0: {
-          _2 = discriminant(_1);
-          switchInt(move _2) -> [255: bb4, 2: bb3, 253: bb2, otherwise: bb1];
-      }
-  
-      bb1: {
-          unreachable;
-      }
-  
-      bb2: {
-          _0 = const 3_i16;
-          goto -> bb5;
-      }
-  
-      bb3: {
-          _0 = const 2_i16;
-          goto -> bb5;
-      }
-  
-      bb4: {
-          _0 = const -1_i16;
-          goto -> bb5;
-      }
-  
-      bb5: {
-          return;
-      }
-  }
-  
diff --git a/tests/mir-opt/matches_reduce_branches.match_sext_i8_i16.MatchBranchSimplification.diff b/tests/mir-opt/matches_reduce_branches.match_sext_i8_i16.MatchBranchSimplification.diff
new file mode 100644
index 00000000000..7f8c2ab8d37
--- /dev/null
+++ b/tests/mir-opt/matches_reduce_branches.match_sext_i8_i16.MatchBranchSimplification.diff
@@ -0,0 +1,52 @@
+- // MIR for `match_sext_i8_i16` before MatchBranchSimplification
++ // MIR for `match_sext_i8_i16` after MatchBranchSimplification
+  
+  fn match_sext_i8_i16(_1: EnumAi8) -> i16 {
+      debug i => _1;
+      let mut _0: i16;
+      let mut _2: i8;
++     let mut _3: i8;
+  
+      bb0: {
+          _2 = discriminant(_1);
+-         switchInt(move _2) -> [128: bb6, 255: bb5, 0: bb4, 1: bb3, 127: bb2, otherwise: bb1];
+-     }
+- 
+-     bb1: {
+-         unreachable;
+-     }
+- 
+-     bb2: {
+-         _0 = const 127_i16;
+-         goto -> bb7;
+-     }
+- 
+-     bb3: {
+-         _0 = const 1_i16;
+-         goto -> bb7;
+-     }
+- 
+-     bb4: {
+-         _0 = const 0_i16;
+-         goto -> bb7;
+-     }
+- 
+-     bb5: {
+-         _0 = const -1_i16;
+-         goto -> bb7;
+-     }
+- 
+-     bb6: {
+-         _0 = const -128_i16;
+-         goto -> bb7;
+-     }
+- 
+-     bb7: {
++         StorageLive(_3);
++         _3 = move _2;
++         _0 = _3 as i16 (IntToInt);
++         StorageDead(_3);
+          return;
+      }
+  }
+  
diff --git a/tests/mir-opt/matches_reduce_branches.match_sext_i8_i16_failed.MatchBranchSimplification.diff b/tests/mir-opt/matches_reduce_branches.match_sext_i8_i16_failed.MatchBranchSimplification.diff
new file mode 100644
index 00000000000..94ec2293222
--- /dev/null
+++ b/tests/mir-opt/matches_reduce_branches.match_sext_i8_i16_failed.MatchBranchSimplification.diff
@@ -0,0 +1,47 @@
+- // MIR for `match_sext_i8_i16_failed` before MatchBranchSimplification
++ // MIR for `match_sext_i8_i16_failed` after MatchBranchSimplification
+  
+  fn match_sext_i8_i16_failed(_1: EnumAi8) -> i16 {
+      debug i => _1;
+      let mut _0: i16;
+      let mut _2: i8;
+  
+      bb0: {
+          _2 = discriminant(_1);
+          switchInt(move _2) -> [128: bb6, 255: bb5, 0: bb4, 1: bb3, 127: bb2, otherwise: bb1];
+      }
+  
+      bb1: {
+          unreachable;
+      }
+  
+      bb2: {
+          _0 = const 127_i16;
+          goto -> bb7;
+      }
+  
+      bb3: {
+          _0 = const 1_i16;
+          goto -> bb7;
+      }
+  
+      bb4: {
+          _0 = const 0_i16;
+          goto -> bb7;
+      }
+  
+      bb5: {
+          _0 = const 255_i16;
+          goto -> bb7;
+      }
+  
+      bb6: {
+          _0 = const -128_i16;
+          goto -> bb7;
+      }
+  
+      bb7: {
+          return;
+      }
+  }
+  
diff --git a/tests/mir-opt/matches_reduce_branches.match_sext_i8_u16.MatchBranchSimplification.diff b/tests/mir-opt/matches_reduce_branches.match_sext_i8_u16.MatchBranchSimplification.diff
new file mode 100644
index 00000000000..86d0d0ba6cf
--- /dev/null
+++ b/tests/mir-opt/matches_reduce_branches.match_sext_i8_u16.MatchBranchSimplification.diff
@@ -0,0 +1,52 @@
+- // MIR for `match_sext_i8_u16` before MatchBranchSimplification
++ // MIR for `match_sext_i8_u16` after MatchBranchSimplification
+  
+  fn match_sext_i8_u16(_1: EnumAi8) -> u16 {
+      debug i => _1;
+      let mut _0: u16;
+      let mut _2: i8;
++     let mut _3: i8;
+  
+      bb0: {
+          _2 = discriminant(_1);
+-         switchInt(move _2) -> [128: bb6, 255: bb5, 0: bb4, 1: bb3, 127: bb2, otherwise: bb1];
+-     }
+- 
+-     bb1: {
+-         unreachable;
+-     }
+- 
+-     bb2: {
+-         _0 = const 127_u16;
+-         goto -> bb7;
+-     }
+- 
+-     bb3: {
+-         _0 = const 1_u16;
+-         goto -> bb7;
+-     }
+- 
+-     bb4: {
+-         _0 = const 0_u16;
+-         goto -> bb7;
+-     }
+- 
+-     bb5: {
+-         _0 = const u16::MAX;
+-         goto -> bb7;
+-     }
+- 
+-     bb6: {
+-         _0 = const 65408_u16;
+-         goto -> bb7;
+-     }
+- 
+-     bb7: {
++         StorageLive(_3);
++         _3 = move _2;
++         _0 = _3 as u16 (IntToInt);
++         StorageDead(_3);
+          return;
+      }
+  }
+  
diff --git a/tests/mir-opt/matches_reduce_branches.match_sext_i8_u16_failed.MatchBranchSimplification.diff b/tests/mir-opt/matches_reduce_branches.match_sext_i8_u16_failed.MatchBranchSimplification.diff
new file mode 100644
index 00000000000..281f373bf87
--- /dev/null
+++ b/tests/mir-opt/matches_reduce_branches.match_sext_i8_u16_failed.MatchBranchSimplification.diff
@@ -0,0 +1,47 @@
+- // MIR for `match_sext_i8_u16_failed` before MatchBranchSimplification
++ // MIR for `match_sext_i8_u16_failed` after MatchBranchSimplification
+  
+  fn match_sext_i8_u16_failed(_1: EnumAi8) -> u16 {
+      debug i => _1;
+      let mut _0: u16;
+      let mut _2: i8;
+  
+      bb0: {
+          _2 = discriminant(_1);
+          switchInt(move _2) -> [128: bb6, 255: bb5, 0: bb4, 1: bb3, 127: bb2, otherwise: bb1];
+      }
+  
+      bb1: {
+          unreachable;
+      }
+  
+      bb2: {
+          _0 = const 127_u16;
+          goto -> bb7;
+      }
+  
+      bb3: {
+          _0 = const 1_u16;
+          goto -> bb7;
+      }
+  
+      bb4: {
+          _0 = const 0_u16;
+          goto -> bb7;
+      }
+  
+      bb5: {
+          _0 = const 255_u16;
+          goto -> bb7;
+      }
+  
+      bb6: {
+          _0 = const 65408_u16;
+          goto -> bb7;
+      }
+  
+      bb7: {
+          return;
+      }
+  }
+  
diff --git a/tests/mir-opt/matches_reduce_branches.match_trunc_i16_i8.MatchBranchSimplification.diff b/tests/mir-opt/matches_reduce_branches.match_trunc_i16_i8.MatchBranchSimplification.diff
new file mode 100644
index 00000000000..d3d27be2070
--- /dev/null
+++ b/tests/mir-opt/matches_reduce_branches.match_trunc_i16_i8.MatchBranchSimplification.diff
@@ -0,0 +1,77 @@
+- // MIR for `match_trunc_i16_i8` before MatchBranchSimplification
++ // MIR for `match_trunc_i16_i8` after MatchBranchSimplification
+  
+  fn match_trunc_i16_i8(_1: EnumAi16) -> i8 {
+      debug i => _1;
+      let mut _0: i8;
+      let mut _2: i16;
++     let mut _3: i16;
+  
+      bb0: {
+          _2 = discriminant(_1);
+-         switchInt(move _2) -> [128: bb11, 255: bb10, 0: bb9, 1: bb8, 127: bb7, 65408: bb6, 65535: bb5, 65280: bb4, 65281: bb3, 65407: bb2, otherwise: bb1];
+-     }
+- 
+-     bb1: {
+-         unreachable;
+-     }
+- 
+-     bb2: {
+-         _0 = const i8::MAX;
+-         goto -> bb12;
+-     }
+- 
+-     bb3: {
+-         _0 = const 1_i8;
+-         goto -> bb12;
+-     }
+- 
+-     bb4: {
+-         _0 = const 0_i8;
+-         goto -> bb12;
+-     }
+- 
+-     bb5: {
+-         _0 = const -1_i8;
+-         goto -> bb12;
+-     }
+- 
+-     bb6: {
+-         _0 = const i8::MIN;
+-         goto -> bb12;
+-     }
+- 
+-     bb7: {
+-         _0 = const i8::MAX;
+-         goto -> bb12;
+-     }
+- 
+-     bb8: {
+-         _0 = const 1_i8;
+-         goto -> bb12;
+-     }
+- 
+-     bb9: {
+-         _0 = const 0_i8;
+-         goto -> bb12;
+-     }
+- 
+-     bb10: {
+-         _0 = const -1_i8;
+-         goto -> bb12;
+-     }
+- 
+-     bb11: {
+-         _0 = const i8::MIN;
+-         goto -> bb12;
+-     }
+- 
+-     bb12: {
++         StorageLive(_3);
++         _3 = move _2;
++         _0 = _3 as i8 (IntToInt);
++         StorageDead(_3);
+          return;
+      }
+  }
+  
diff --git a/tests/mir-opt/matches_reduce_branches.match_trunc_i16_i8_failed.MatchBranchSimplification.diff b/tests/mir-opt/matches_reduce_branches.match_trunc_i16_i8_failed.MatchBranchSimplification.diff
new file mode 100644
index 00000000000..7f663baefba
--- /dev/null
+++ b/tests/mir-opt/matches_reduce_branches.match_trunc_i16_i8_failed.MatchBranchSimplification.diff
@@ -0,0 +1,72 @@
+- // MIR for `match_trunc_i16_i8_failed` before MatchBranchSimplification
++ // MIR for `match_trunc_i16_i8_failed` after MatchBranchSimplification
+  
+  fn match_trunc_i16_i8_failed(_1: EnumAi16) -> i8 {
+      debug i => _1;
+      let mut _0: i8;
+      let mut _2: i16;
+  
+      bb0: {
+          _2 = discriminant(_1);
+          switchInt(move _2) -> [128: bb11, 255: bb10, 0: bb9, 1: bb8, 127: bb7, 65408: bb6, 65535: bb5, 65280: bb4, 65281: bb3, 65407: bb2, otherwise: bb1];
+      }
+  
+      bb1: {
+          unreachable;
+      }
+  
+      bb2: {
+          _0 = const -127_i8;
+          goto -> bb12;
+      }
+  
+      bb3: {
+          _0 = const 1_i8;
+          goto -> bb12;
+      }
+  
+      bb4: {
+          _0 = const 0_i8;
+          goto -> bb12;
+      }
+  
+      bb5: {
+          _0 = const -1_i8;
+          goto -> bb12;
+      }
+  
+      bb6: {
+          _0 = const i8::MIN;
+          goto -> bb12;
+      }
+  
+      bb7: {
+          _0 = const i8::MAX;
+          goto -> bb12;
+      }
+  
+      bb8: {
+          _0 = const 1_i8;
+          goto -> bb12;
+      }
+  
+      bb9: {
+          _0 = const 0_i8;
+          goto -> bb12;
+      }
+  
+      bb10: {
+          _0 = const -1_i8;
+          goto -> bb12;
+      }
+  
+      bb11: {
+          _0 = const i8::MIN;
+          goto -> bb12;
+      }
+  
+      bb12: {
+          return;
+      }
+  }
+  
diff --git a/tests/mir-opt/matches_reduce_branches.match_trunc_i16_u8.MatchBranchSimplification.diff b/tests/mir-opt/matches_reduce_branches.match_trunc_i16_u8.MatchBranchSimplification.diff
new file mode 100644
index 00000000000..5fe899148eb
--- /dev/null
+++ b/tests/mir-opt/matches_reduce_branches.match_trunc_i16_u8.MatchBranchSimplification.diff
@@ -0,0 +1,77 @@
+- // MIR for `match_trunc_i16_u8` before MatchBranchSimplification
++ // MIR for `match_trunc_i16_u8` after MatchBranchSimplification
+  
+  fn match_trunc_i16_u8(_1: EnumAi16) -> u8 {
+      debug i => _1;
+      let mut _0: u8;
+      let mut _2: i16;
++     let mut _3: i16;
+  
+      bb0: {
+          _2 = discriminant(_1);
+-         switchInt(move _2) -> [128: bb11, 255: bb10, 0: bb9, 1: bb8, 127: bb7, 65408: bb6, 65535: bb5, 65280: bb4, 65281: bb3, 65407: bb2, otherwise: bb1];
+-     }
+- 
+-     bb1: {
+-         unreachable;
+-     }
+- 
+-     bb2: {
+-         _0 = const 127_u8;
+-         goto -> bb12;
+-     }
+- 
+-     bb3: {
+-         _0 = const 1_u8;
+-         goto -> bb12;
+-     }
+- 
+-     bb4: {
+-         _0 = const 0_u8;
+-         goto -> bb12;
+-     }
+- 
+-     bb5: {
+-         _0 = const u8::MAX;
+-         goto -> bb12;
+-     }
+- 
+-     bb6: {
+-         _0 = const 128_u8;
+-         goto -> bb12;
+-     }
+- 
+-     bb7: {
+-         _0 = const 127_u8;
+-         goto -> bb12;
+-     }
+- 
+-     bb8: {
+-         _0 = const 1_u8;
+-         goto -> bb12;
+-     }
+- 
+-     bb9: {
+-         _0 = const 0_u8;
+-         goto -> bb12;
+-     }
+- 
+-     bb10: {
+-         _0 = const u8::MAX;
+-         goto -> bb12;
+-     }
+- 
+-     bb11: {
+-         _0 = const 128_u8;
+-         goto -> bb12;
+-     }
+- 
+-     bb12: {
++         StorageLive(_3);
++         _3 = move _2;
++         _0 = _3 as u8 (IntToInt);
++         StorageDead(_3);
+          return;
+      }
+  }
+  
diff --git a/tests/mir-opt/matches_reduce_branches.match_trunc_i16_u8_failed.MatchBranchSimplification.diff b/tests/mir-opt/matches_reduce_branches.match_trunc_i16_u8_failed.MatchBranchSimplification.diff
new file mode 100644
index 00000000000..1c0ffb30c5b
--- /dev/null
+++ b/tests/mir-opt/matches_reduce_branches.match_trunc_i16_u8_failed.MatchBranchSimplification.diff
@@ -0,0 +1,72 @@
+- // MIR for `match_trunc_i16_u8_failed` before MatchBranchSimplification
++ // MIR for `match_trunc_i16_u8_failed` after MatchBranchSimplification
+  
+  fn match_trunc_i16_u8_failed(_1: EnumAi16) -> u8 {
+      debug i => _1;
+      let mut _0: u8;
+      let mut _2: i16;
+  
+      bb0: {
+          _2 = discriminant(_1);
+          switchInt(move _2) -> [128: bb11, 255: bb10, 0: bb9, 1: bb8, 127: bb7, 65408: bb6, 65535: bb5, 65280: bb4, 65281: bb3, 65407: bb2, otherwise: bb1];
+      }
+  
+      bb1: {
+          unreachable;
+      }
+  
+      bb2: {
+          _0 = const -127_i8 as u8 (IntToInt);
+          goto -> bb12;
+      }
+  
+      bb3: {
+          _0 = const 1_u8;
+          goto -> bb12;
+      }
+  
+      bb4: {
+          _0 = const 0_u8;
+          goto -> bb12;
+      }
+  
+      bb5: {
+          _0 = const u8::MAX;
+          goto -> bb12;
+      }
+  
+      bb6: {
+          _0 = const 128_u8;
+          goto -> bb12;
+      }
+  
+      bb7: {
+          _0 = const 127_u8;
+          goto -> bb12;
+      }
+  
+      bb8: {
+          _0 = const 1_u8;
+          goto -> bb12;
+      }
+  
+      bb9: {
+          _0 = const 0_u8;
+          goto -> bb12;
+      }
+  
+      bb10: {
+          _0 = const u8::MAX;
+          goto -> bb12;
+      }
+  
+      bb11: {
+          _0 = const 128_u8;
+          goto -> bb12;
+      }
+  
+      bb12: {
+          return;
+      }
+  }
+  
diff --git a/tests/mir-opt/matches_reduce_branches.match_trunc_u16_i8.MatchBranchSimplification.diff b/tests/mir-opt/matches_reduce_branches.match_trunc_u16_i8.MatchBranchSimplification.diff
new file mode 100644
index 00000000000..85f97a13cac
--- /dev/null
+++ b/tests/mir-opt/matches_reduce_branches.match_trunc_u16_i8.MatchBranchSimplification.diff
@@ -0,0 +1,67 @@
+- // MIR for `match_trunc_u16_i8` before MatchBranchSimplification
++ // MIR for `match_trunc_u16_i8` after MatchBranchSimplification
+  
+  fn match_trunc_u16_i8(_1: EnumAu16) -> i8 {
+      debug i => _1;
+      let mut _0: i8;
+      let mut _2: u16;
++     let mut _3: u16;
+  
+      bb0: {
+          _2 = discriminant(_1);
+-         switchInt(move _2) -> [0: bb9, 127: bb8, 128: bb7, 255: bb6, 65280: bb5, 65407: bb4, 65408: bb3, 65535: bb2, otherwise: bb1];
+-     }
+- 
+-     bb1: {
+-         unreachable;
+-     }
+- 
+-     bb2: {
+-         _0 = const -1_i8;
+-         goto -> bb10;
+-     }
+- 
+-     bb3: {
+-         _0 = const i8::MIN;
+-         goto -> bb10;
+-     }
+- 
+-     bb4: {
+-         _0 = const i8::MAX;
+-         goto -> bb10;
+-     }
+- 
+-     bb5: {
+-         _0 = const 0_i8;
+-         goto -> bb10;
+-     }
+- 
+-     bb6: {
+-         _0 = const -1_i8;
+-         goto -> bb10;
+-     }
+- 
+-     bb7: {
+-         _0 = const i8::MIN;
+-         goto -> bb10;
+-     }
+- 
+-     bb8: {
+-         _0 = const i8::MAX;
+-         goto -> bb10;
+-     }
+- 
+-     bb9: {
+-         _0 = const 0_i8;
+-         goto -> bb10;
+-     }
+- 
+-     bb10: {
++         StorageLive(_3);
++         _3 = move _2;
++         _0 = _3 as i8 (IntToInt);
++         StorageDead(_3);
+          return;
+      }
+  }
+  
diff --git a/tests/mir-opt/matches_reduce_branches.match_trunc_u16_i8_failed.MatchBranchSimplification.diff b/tests/mir-opt/matches_reduce_branches.match_trunc_u16_i8_failed.MatchBranchSimplification.diff
new file mode 100644
index 00000000000..cf6c86a71ad
--- /dev/null
+++ b/tests/mir-opt/matches_reduce_branches.match_trunc_u16_i8_failed.MatchBranchSimplification.diff
@@ -0,0 +1,62 @@
+- // MIR for `match_trunc_u16_i8_failed` before MatchBranchSimplification
++ // MIR for `match_trunc_u16_i8_failed` after MatchBranchSimplification
+  
+  fn match_trunc_u16_i8_failed(_1: EnumAu16) -> i8 {
+      debug i => _1;
+      let mut _0: i8;
+      let mut _2: u16;
+  
+      bb0: {
+          _2 = discriminant(_1);
+          switchInt(move _2) -> [0: bb9, 127: bb8, 128: bb7, 255: bb6, 65280: bb5, 65407: bb4, 65408: bb3, 65535: bb2, otherwise: bb1];
+      }
+  
+      bb1: {
+          unreachable;
+      }
+  
+      bb2: {
+          _0 = const 1_i8;
+          goto -> bb10;
+      }
+  
+      bb3: {
+          _0 = const i8::MIN;
+          goto -> bb10;
+      }
+  
+      bb4: {
+          _0 = const i8::MAX;
+          goto -> bb10;
+      }
+  
+      bb5: {
+          _0 = const 0_i8;
+          goto -> bb10;
+      }
+  
+      bb6: {
+          _0 = const -1_i8;
+          goto -> bb10;
+      }
+  
+      bb7: {
+          _0 = const i8::MIN;
+          goto -> bb10;
+      }
+  
+      bb8: {
+          _0 = const i8::MAX;
+          goto -> bb10;
+      }
+  
+      bb9: {
+          _0 = const 0_i8;
+          goto -> bb10;
+      }
+  
+      bb10: {
+          return;
+      }
+  }
+  
diff --git a/tests/mir-opt/matches_reduce_branches.match_trunc_u16_u8.MatchBranchSimplification.diff b/tests/mir-opt/matches_reduce_branches.match_trunc_u16_u8.MatchBranchSimplification.diff
new file mode 100644
index 00000000000..768d838eaa6
--- /dev/null
+++ b/tests/mir-opt/matches_reduce_branches.match_trunc_u16_u8.MatchBranchSimplification.diff
@@ -0,0 +1,67 @@
+- // MIR for `match_trunc_u16_u8` before MatchBranchSimplification
++ // MIR for `match_trunc_u16_u8` after MatchBranchSimplification
+  
+  fn match_trunc_u16_u8(_1: EnumAu16) -> u8 {
+      debug i => _1;
+      let mut _0: u8;
+      let mut _2: u16;
++     let mut _3: u16;
+  
+      bb0: {
+          _2 = discriminant(_1);
+-         switchInt(move _2) -> [0: bb9, 127: bb8, 128: bb7, 255: bb6, 65280: bb5, 65407: bb4, 65408: bb3, 65535: bb2, otherwise: bb1];
+-     }
+- 
+-     bb1: {
+-         unreachable;
+-     }
+- 
+-     bb2: {
+-         _0 = const u8::MAX;
+-         goto -> bb10;
+-     }
+- 
+-     bb3: {
+-         _0 = const 128_u8;
+-         goto -> bb10;
+-     }
+- 
+-     bb4: {
+-         _0 = const 127_u8;
+-         goto -> bb10;
+-     }
+- 
+-     bb5: {
+-         _0 = const 0_u8;
+-         goto -> bb10;
+-     }
+- 
+-     bb6: {
+-         _0 = const u8::MAX;
+-         goto -> bb10;
+-     }
+- 
+-     bb7: {
+-         _0 = const 128_u8;
+-         goto -> bb10;
+-     }
+- 
+-     bb8: {
+-         _0 = const 127_u8;
+-         goto -> bb10;
+-     }
+- 
+-     bb9: {
+-         _0 = const 0_u8;
+-         goto -> bb10;
+-     }
+- 
+-     bb10: {
++         StorageLive(_3);
++         _3 = move _2;
++         _0 = _3 as u8 (IntToInt);
++         StorageDead(_3);
+          return;
+      }
+  }
+  
diff --git a/tests/mir-opt/matches_reduce_branches.match_trunc_u16_u8_failed.MatchBranchSimplification.diff b/tests/mir-opt/matches_reduce_branches.match_trunc_u16_u8_failed.MatchBranchSimplification.diff
new file mode 100644
index 00000000000..109e97bb578
--- /dev/null
+++ b/tests/mir-opt/matches_reduce_branches.match_trunc_u16_u8_failed.MatchBranchSimplification.diff
@@ -0,0 +1,62 @@
+- // MIR for `match_trunc_u16_u8_failed` before MatchBranchSimplification
++ // MIR for `match_trunc_u16_u8_failed` after MatchBranchSimplification
+  
+  fn match_trunc_u16_u8_failed(_1: EnumAu16) -> u8 {
+      debug i => _1;
+      let mut _0: u8;
+      let mut _2: u16;
+  
+      bb0: {
+          _2 = discriminant(_1);
+          switchInt(move _2) -> [0: bb9, 127: bb8, 128: bb7, 255: bb6, 65280: bb5, 65407: bb4, 65408: bb3, 65535: bb2, otherwise: bb1];
+      }
+  
+      bb1: {
+          unreachable;
+      }
+  
+      bb2: {
+          _0 = const 127_u8;
+          goto -> bb10;
+      }
+  
+      bb3: {
+          _0 = const 128_u8;
+          goto -> bb10;
+      }
+  
+      bb4: {
+          _0 = const 127_u8;
+          goto -> bb10;
+      }
+  
+      bb5: {
+          _0 = const 0_u8;
+          goto -> bb10;
+      }
+  
+      bb6: {
+          _0 = const u8::MAX;
+          goto -> bb10;
+      }
+  
+      bb7: {
+          _0 = const 128_u8;
+          goto -> bb10;
+      }
+  
+      bb8: {
+          _0 = const 127_u8;
+          goto -> bb10;
+      }
+  
+      bb9: {
+          _0 = const 0_u8;
+          goto -> bb10;
+      }
+  
+      bb10: {
+          return;
+      }
+  }
+  
diff --git a/tests/mir-opt/matches_reduce_branches.match_u8_i16.MatchBranchSimplification.diff b/tests/mir-opt/matches_reduce_branches.match_u8_i16.MatchBranchSimplification.diff
deleted file mode 100644
index 72ad60956ab..00000000000
--- a/tests/mir-opt/matches_reduce_branches.match_u8_i16.MatchBranchSimplification.diff
+++ /dev/null
@@ -1,32 +0,0 @@
-- // MIR for `match_u8_i16` before MatchBranchSimplification
-+ // MIR for `match_u8_i16` after MatchBranchSimplification
-  
-  fn match_u8_i16(_1: EnumAu8) -> i16 {
-      debug i => _1;
-      let mut _0: i16;
-      let mut _2: u8;
-  
-      bb0: {
-          _2 = discriminant(_1);
-          switchInt(move _2) -> [1: bb3, 2: bb2, otherwise: bb1];
-      }
-  
-      bb1: {
-          unreachable;
-      }
-  
-      bb2: {
-          _0 = const 2_i16;
-          goto -> bb4;
-      }
-  
-      bb3: {
-          _0 = const 1_i16;
-          goto -> bb4;
-      }
-  
-      bb4: {
-          return;
-      }
-  }
-  
diff --git a/tests/mir-opt/matches_reduce_branches.match_u8_i16_2.MatchBranchSimplification.diff b/tests/mir-opt/matches_reduce_branches.match_u8_i16_2.MatchBranchSimplification.diff
deleted file mode 100644
index 3333cd765a8..00000000000
--- a/tests/mir-opt/matches_reduce_branches.match_u8_i16_2.MatchBranchSimplification.diff
+++ /dev/null
@@ -1,26 +0,0 @@
-- // MIR for `match_u8_i16_2` before MatchBranchSimplification
-+ // MIR for `match_u8_i16_2` after MatchBranchSimplification
-  
-  fn match_u8_i16_2(_1: EnumAu8) -> i16 {
-      let mut _0: i16;
-      let mut _2: u8;
-  
-      bb0: {
-          _2 = discriminant(_1);
-          switchInt(_2) -> [1: bb3, 2: bb1, otherwise: bb2];
-      }
-  
-      bb1: {
-          _0 = const 2_i16;
-          goto -> bb3;
-      }
-  
-      bb2: {
-          unreachable;
-      }
-  
-      bb3: {
-          return;
-      }
-  }
-  
diff --git a/tests/mir-opt/matches_reduce_branches.match_u8_i16_failed.MatchBranchSimplification.diff b/tests/mir-opt/matches_reduce_branches.match_u8_i16_failed.MatchBranchSimplification.diff
deleted file mode 100644
index 6da19e46dab..00000000000
--- a/tests/mir-opt/matches_reduce_branches.match_u8_i16_failed.MatchBranchSimplification.diff
+++ /dev/null
@@ -1,32 +0,0 @@
-- // MIR for `match_u8_i16_failed` before MatchBranchSimplification
-+ // MIR for `match_u8_i16_failed` after MatchBranchSimplification
-  
-  fn match_u8_i16_failed(_1: EnumAu8) -> i16 {
-      debug i => _1;
-      let mut _0: i16;
-      let mut _2: u8;
-  
-      bb0: {
-          _2 = discriminant(_1);
-          switchInt(move _2) -> [1: bb3, 2: bb2, otherwise: bb1];
-      }
-  
-      bb1: {
-          unreachable;
-      }
-  
-      bb2: {
-          _0 = const 3_i16;
-          goto -> bb4;
-      }
-  
-      bb3: {
-          _0 = const 1_i16;
-          goto -> bb4;
-      }
-  
-      bb4: {
-          return;
-      }
-  }
-  
diff --git a/tests/mir-opt/matches_reduce_branches.match_u8_i16_fallback.MatchBranchSimplification.diff b/tests/mir-opt/matches_reduce_branches.match_u8_i16_fallback.MatchBranchSimplification.diff
deleted file mode 100644
index 5690f17f24f..00000000000
--- a/tests/mir-opt/matches_reduce_branches.match_u8_i16_fallback.MatchBranchSimplification.diff
+++ /dev/null
@@ -1,31 +0,0 @@
-- // MIR for `match_u8_i16_fallback` before MatchBranchSimplification
-+ // MIR for `match_u8_i16_fallback` after MatchBranchSimplification
-  
-  fn match_u8_i16_fallback(_1: u8) -> i16 {
-      debug i => _1;
-      let mut _0: i16;
-  
-      bb0: {
-          switchInt(_1) -> [1: bb3, 2: bb2, otherwise: bb1];
-      }
-  
-      bb1: {
-          _0 = const 3_i16;
-          goto -> bb4;
-      }
-  
-      bb2: {
-          _0 = const 2_i16;
-          goto -> bb4;
-      }
-  
-      bb3: {
-          _0 = const 1_i16;
-          goto -> bb4;
-      }
-  
-      bb4: {
-          return;
-      }
-  }
-  
diff --git a/tests/mir-opt/matches_reduce_branches.match_u8_i8.MatchBranchSimplification.diff b/tests/mir-opt/matches_reduce_branches.match_u8_i8.MatchBranchSimplification.diff
new file mode 100644
index 00000000000..d63eed7c019
--- /dev/null
+++ b/tests/mir-opt/matches_reduce_branches.match_u8_i8.MatchBranchSimplification.diff
@@ -0,0 +1,47 @@
+- // MIR for `match_u8_i8` before MatchBranchSimplification
++ // MIR for `match_u8_i8` after MatchBranchSimplification
+  
+  fn match_u8_i8(_1: EnumAu8) -> i8 {
+      debug i => _1;
+      let mut _0: i8;
+      let mut _2: u8;
++     let mut _3: u8;
+  
+      bb0: {
+          _2 = discriminant(_1);
+-         switchInt(move _2) -> [0: bb5, 127: bb4, 128: bb3, 255: bb2, otherwise: bb1];
+-     }
+- 
+-     bb1: {
+-         unreachable;
+-     }
+- 
+-     bb2: {
+-         _0 = const -1_i8;
+-         goto -> bb6;
+-     }
+- 
+-     bb3: {
+-         _0 = const i8::MIN;
+-         goto -> bb6;
+-     }
+- 
+-     bb4: {
+-         _0 = const i8::MAX;
+-         goto -> bb6;
+-     }
+- 
+-     bb5: {
+-         _0 = const 0_i8;
+-         goto -> bb6;
+-     }
+- 
+-     bb6: {
++         StorageLive(_3);
++         _3 = move _2;
++         _0 = _3 as i8 (IntToInt);
++         StorageDead(_3);
+          return;
+      }
+  }
+  
diff --git a/tests/mir-opt/matches_reduce_branches.match_u8_i8_2.MatchBranchSimplification.diff b/tests/mir-opt/matches_reduce_branches.match_u8_i8_2.MatchBranchSimplification.diff
new file mode 100644
index 00000000000..98dee1835a8
--- /dev/null
+++ b/tests/mir-opt/matches_reduce_branches.match_u8_i8_2.MatchBranchSimplification.diff
@@ -0,0 +1,80 @@
+- // MIR for `match_u8_i8_2` before MatchBranchSimplification
++ // MIR for `match_u8_i8_2` after MatchBranchSimplification
+  
+  fn match_u8_i8_2(_1: EnumAu8) -> (i8, i8) {
+      debug i => _1;
+      let mut _0: (i8, i8);
+      let _2: i8;
+      let _4: ();
+      let mut _5: u8;
+      let mut _6: i8;
+      let mut _7: i8;
++     let mut _8: u8;
+      scope 1 {
+          debug a => _2;
+          let _3: i8;
+          scope 2 {
+              debug b => _3;
+          }
+      }
+  
+      bb0: {
+          StorageLive(_2);
+          StorageLive(_3);
+          StorageLive(_4);
+          _5 = discriminant(_1);
+-         switchInt(move _5) -> [0: bb5, 127: bb4, 128: bb3, 255: bb2, otherwise: bb1];
+-     }
+- 
+-     bb1: {
+-         unreachable;
+-     }
+- 
+-     bb2: {
+-         _2 = const -1_i8;
+-         _3 = const -1_i8;
++         StorageLive(_8);
++         _8 = move _5;
++         _2 = _8 as i8 (IntToInt);
++         _3 = _8 as i8 (IntToInt);
+          _4 = ();
+-         goto -> bb6;
+-     }
+- 
+-     bb3: {
+-         _2 = const i8::MIN;
+-         _3 = const i8::MIN;
+-         _4 = ();
+-         goto -> bb6;
+-     }
+- 
+-     bb4: {
+-         _2 = const i8::MAX;
+-         _3 = const i8::MAX;
+-         _4 = ();
+-         goto -> bb6;
+-     }
+- 
+-     bb5: {
+-         _2 = const 0_i8;
+-         _3 = const 0_i8;
+-         _4 = ();
+-         goto -> bb6;
+-     }
+- 
+-     bb6: {
++         StorageDead(_8);
+          StorageDead(_4);
+          StorageLive(_6);
+          _6 = _2;
+          StorageLive(_7);
+          _7 = _3;
+          _0 = (move _6, move _7);
+          StorageDead(_7);
+          StorageDead(_6);
+          StorageDead(_3);
+          StorageDead(_2);
+          return;
+      }
+  }
+  
diff --git a/tests/mir-opt/matches_reduce_branches.match_u8_i8_2_failed.MatchBranchSimplification.diff b/tests/mir-opt/matches_reduce_branches.match_u8_i8_2_failed.MatchBranchSimplification.diff
new file mode 100644
index 00000000000..901dda58617
--- /dev/null
+++ b/tests/mir-opt/matches_reduce_branches.match_u8_i8_2_failed.MatchBranchSimplification.diff
@@ -0,0 +1,74 @@
+- // MIR for `match_u8_i8_2_failed` before MatchBranchSimplification
++ // MIR for `match_u8_i8_2_failed` after MatchBranchSimplification
+  
+  fn match_u8_i8_2_failed(_1: EnumAu8) -> (i8, i8) {
+      debug i => _1;
+      let mut _0: (i8, i8);
+      let _2: i8;
+      let _4: ();
+      let mut _5: u8;
+      let mut _6: i8;
+      let mut _7: i8;
+      scope 1 {
+          debug a => _2;
+          let _3: i8;
+          scope 2 {
+              debug b => _3;
+          }
+      }
+  
+      bb0: {
+          StorageLive(_2);
+          StorageLive(_3);
+          StorageLive(_4);
+          _5 = discriminant(_1);
+          switchInt(move _5) -> [0: bb5, 127: bb4, 128: bb3, 255: bb2, otherwise: bb1];
+      }
+  
+      bb1: {
+          unreachable;
+      }
+  
+      bb2: {
+          _2 = const -1_i8;
+          _3 = const 1_i8;
+          _4 = ();
+          goto -> bb6;
+      }
+  
+      bb3: {
+          _2 = const i8::MIN;
+          _3 = const i8::MIN;
+          _4 = ();
+          goto -> bb6;
+      }
+  
+      bb4: {
+          _2 = const i8::MAX;
+          _3 = const i8::MAX;
+          _4 = ();
+          goto -> bb6;
+      }
+  
+      bb5: {
+          _2 = const 0_i8;
+          _3 = const 0_i8;
+          _4 = ();
+          goto -> bb6;
+      }
+  
+      bb6: {
+          StorageDead(_4);
+          StorageLive(_6);
+          _6 = _2;
+          StorageLive(_7);
+          _7 = _3;
+          _0 = (move _6, move _7);
+          StorageDead(_7);
+          StorageDead(_6);
+          StorageDead(_3);
+          StorageDead(_2);
+          return;
+      }
+  }
+  
diff --git a/tests/mir-opt/matches_reduce_branches.match_u8_i8_failed.MatchBranchSimplification.diff b/tests/mir-opt/matches_reduce_branches.match_u8_i8_failed.MatchBranchSimplification.diff
new file mode 100644
index 00000000000..ac96be55312
--- /dev/null
+++ b/tests/mir-opt/matches_reduce_branches.match_u8_i8_failed.MatchBranchSimplification.diff
@@ -0,0 +1,42 @@
+- // MIR for `match_u8_i8_failed` before MatchBranchSimplification
++ // MIR for `match_u8_i8_failed` after MatchBranchSimplification
+  
+  fn match_u8_i8_failed(_1: EnumAu8) -> i8 {
+      debug i => _1;
+      let mut _0: i8;
+      let mut _2: u8;
+  
+      bb0: {
+          _2 = discriminant(_1);
+          switchInt(move _2) -> [0: bb5, 127: bb4, 128: bb3, 255: bb2, otherwise: bb1];
+      }
+  
+      bb1: {
+          unreachable;
+      }
+  
+      bb2: {
+          _0 = const 1_i8;
+          goto -> bb6;
+      }
+  
+      bb3: {
+          _0 = const i8::MIN;
+          goto -> bb6;
+      }
+  
+      bb4: {
+          _0 = const i8::MAX;
+          goto -> bb6;
+      }
+  
+      bb5: {
+          _0 = const 0_i8;
+          goto -> bb6;
+      }
+  
+      bb6: {
+          return;
+      }
+  }
+  
diff --git a/tests/mir-opt/matches_reduce_branches.match_u8_i8_failed_len_1.MatchBranchSimplification.diff b/tests/mir-opt/matches_reduce_branches.match_u8_i8_failed_len_1.MatchBranchSimplification.diff
new file mode 100644
index 00000000000..9ebf2cf27cb
--- /dev/null
+++ b/tests/mir-opt/matches_reduce_branches.match_u8_i8_failed_len_1.MatchBranchSimplification.diff
@@ -0,0 +1,42 @@
+- // MIR for `match_u8_i8_failed_len_1` before MatchBranchSimplification
++ // MIR for `match_u8_i8_failed_len_1` after MatchBranchSimplification
+  
+  fn match_u8_i8_failed_len_1(_1: EnumAu8) -> i8 {
+      let mut _0: i8;
+      let mut _2: u8;
+  
+      bb0: {
+          _2 = discriminant(_1);
+          switchInt(_2) -> [0: bb1, 127: bb2, 128: bb3, 255: bb4, otherwise: bb5];
+      }
+  
+      bb1: {
+          _0 = const 0_i8;
+          goto -> bb6;
+      }
+  
+      bb2: {
+          _0 = const i8::MAX;
+          _0 = const i8::MAX;
+          goto -> bb6;
+      }
+  
+      bb3: {
+          _0 = const i8::MIN;
+          goto -> bb6;
+      }
+  
+      bb4: {
+          _0 = const -1_i8;
+          goto -> bb6;
+      }
+  
+      bb5: {
+          unreachable;
+      }
+  
+      bb6: {
+          return;
+      }
+  }
+  
diff --git a/tests/mir-opt/matches_reduce_branches.match_u8_i8_failed_len_2.MatchBranchSimplification.diff b/tests/mir-opt/matches_reduce_branches.match_u8_i8_failed_len_2.MatchBranchSimplification.diff
new file mode 100644
index 00000000000..554856777eb
--- /dev/null
+++ b/tests/mir-opt/matches_reduce_branches.match_u8_i8_failed_len_2.MatchBranchSimplification.diff
@@ -0,0 +1,42 @@
+- // MIR for `match_u8_i8_failed_len_2` before MatchBranchSimplification
++ // MIR for `match_u8_i8_failed_len_2` after MatchBranchSimplification
+  
+  fn match_u8_i8_failed_len_2(_1: EnumAu8) -> i8 {
+      let mut _0: i8;
+      let mut _2: u8;
+  
+      bb0: {
+          _2 = discriminant(_1);
+          switchInt(_2) -> [0: bb1, 127: bb2, 128: bb3, 255: bb4, otherwise: bb5];
+      }
+  
+      bb1: {
+          _0 = const 0_i8;
+          goto -> bb6;
+      }
+  
+      bb2: {
+          _0 = const i8::MAX;
+          goto -> bb6;
+      }
+  
+      bb3: {
+          _0 = const i8::MIN;
+          goto -> bb6;
+      }
+  
+      bb4: {
+          _0 = const -1_i8;
+          _0 = const -1_i8;
+          goto -> bb6;
+      }
+  
+      bb5: {
+          unreachable;
+      }
+  
+      bb6: {
+          return;
+      }
+  }
+  
diff --git a/tests/mir-opt/matches_reduce_branches.match_u8_i8_fallback.MatchBranchSimplification.diff b/tests/mir-opt/matches_reduce_branches.match_u8_i8_fallback.MatchBranchSimplification.diff
new file mode 100644
index 00000000000..356655021f7
--- /dev/null
+++ b/tests/mir-opt/matches_reduce_branches.match_u8_i8_fallback.MatchBranchSimplification.diff
@@ -0,0 +1,38 @@
+- // MIR for `match_u8_i8_fallback` before MatchBranchSimplification
++ // MIR for `match_u8_i8_fallback` after MatchBranchSimplification
+  
+  fn match_u8_i8_fallback(_1: EnumAu8) -> i8 {
+      debug i => _1;
+      let mut _0: i8;
+      let mut _2: u8;
+  
+      bb0: {
+          _2 = discriminant(_1);
+          switchInt(move _2) -> [0: bb4, 127: bb3, 128: bb2, otherwise: bb1];
+      }
+  
+      bb1: {
+          _0 = const -1_i8;
+          goto -> bb5;
+      }
+  
+      bb2: {
+          _0 = const i8::MIN;
+          goto -> bb5;
+      }
+  
+      bb3: {
+          _0 = const i8::MAX;
+          goto -> bb5;
+      }
+  
+      bb4: {
+          _0 = const 0_i8;
+          goto -> bb5;
+      }
+  
+      bb5: {
+          return;
+      }
+  }
+  
diff --git a/tests/mir-opt/matches_reduce_branches.match_u8_u16.MatchBranchSimplification.diff b/tests/mir-opt/matches_reduce_branches.match_u8_u16.MatchBranchSimplification.diff
deleted file mode 100644
index dc9c1c2b97f..00000000000
--- a/tests/mir-opt/matches_reduce_branches.match_u8_u16.MatchBranchSimplification.diff
+++ /dev/null
@@ -1,37 +0,0 @@
-- // MIR for `match_u8_u16` before MatchBranchSimplification
-+ // MIR for `match_u8_u16` after MatchBranchSimplification
-  
-  fn match_u8_u16(_1: EnumBu8) -> u16 {
-      debug i => _1;
-      let mut _0: u16;
-      let mut _2: u8;
-  
-      bb0: {
-          _2 = discriminant(_1);
-          switchInt(move _2) -> [1: bb4, 2: bb3, 5: bb2, otherwise: bb1];
-      }
-  
-      bb1: {
-          unreachable;
-      }
-  
-      bb2: {
-          _0 = const 5_u16;
-          goto -> bb5;
-      }
-  
-      bb3: {
-          _0 = const 2_u16;
-          goto -> bb5;
-      }
-  
-      bb4: {
-          _0 = const 1_u16;
-          goto -> bb5;
-      }
-  
-      bb5: {
-          return;
-      }
-  }
-  
diff --git a/tests/mir-opt/matches_reduce_branches.match_u8_u16_2.MatchBranchSimplification.diff b/tests/mir-opt/matches_reduce_branches.match_u8_u16_2.MatchBranchSimplification.diff
deleted file mode 100644
index b47de6a52b7..00000000000
--- a/tests/mir-opt/matches_reduce_branches.match_u8_u16_2.MatchBranchSimplification.diff
+++ /dev/null
@@ -1,37 +0,0 @@
-- // MIR for `match_u8_u16_2` before MatchBranchSimplification
-+ // MIR for `match_u8_u16_2` after MatchBranchSimplification
-  
-  fn match_u8_u16_2(_1: EnumBu8) -> i16 {
-      let mut _0: i16;
-      let mut _2: u8;
-  
-      bb0: {
-          _2 = discriminant(_1);
-          switchInt(_2) -> [1: bb1, 2: bb2, 5: bb3, otherwise: bb4];
-      }
-  
-      bb1: {
-          _0 = const 1_i16;
-          goto -> bb5;
-      }
-  
-      bb2: {
-          _0 = const 2_i16;
-          goto -> bb5;
-      }
-  
-      bb3: {
-          _0 = const 5_i16;
-          _0 = const 5_i16;
-          goto -> bb5;
-      }
-  
-      bb4: {
-          unreachable;
-      }
-  
-      bb5: {
-          return;
-      }
-  }
-  
diff --git a/tests/mir-opt/matches_reduce_branches.match_zext_u8_i16.MatchBranchSimplification.diff b/tests/mir-opt/matches_reduce_branches.match_zext_u8_i16.MatchBranchSimplification.diff
new file mode 100644
index 00000000000..e00a604fe25
--- /dev/null
+++ b/tests/mir-opt/matches_reduce_branches.match_zext_u8_i16.MatchBranchSimplification.diff
@@ -0,0 +1,47 @@
+- // MIR for `match_zext_u8_i16` before MatchBranchSimplification
++ // MIR for `match_zext_u8_i16` after MatchBranchSimplification
+  
+  fn match_zext_u8_i16(_1: EnumAu8) -> i16 {
+      debug i => _1;
+      let mut _0: i16;
+      let mut _2: u8;
++     let mut _3: u8;
+  
+      bb0: {
+          _2 = discriminant(_1);
+-         switchInt(move _2) -> [0: bb5, 127: bb4, 128: bb3, 255: bb2, otherwise: bb1];
+-     }
+- 
+-     bb1: {
+-         unreachable;
+-     }
+- 
+-     bb2: {
+-         _0 = const 255_i16;
+-         goto -> bb6;
+-     }
+- 
+-     bb3: {
+-         _0 = const 128_i16;
+-         goto -> bb6;
+-     }
+- 
+-     bb4: {
+-         _0 = const 127_i16;
+-         goto -> bb6;
+-     }
+- 
+-     bb5: {
+-         _0 = const 0_i16;
+-         goto -> bb6;
+-     }
+- 
+-     bb6: {
++         StorageLive(_3);
++         _3 = move _2;
++         _0 = _3 as i16 (IntToInt);
++         StorageDead(_3);
+          return;
+      }
+  }
+  
diff --git a/tests/mir-opt/matches_reduce_branches.match_zext_u8_i16_failed.MatchBranchSimplification.diff b/tests/mir-opt/matches_reduce_branches.match_zext_u8_i16_failed.MatchBranchSimplification.diff
new file mode 100644
index 00000000000..a19cd796c27
--- /dev/null
+++ b/tests/mir-opt/matches_reduce_branches.match_zext_u8_i16_failed.MatchBranchSimplification.diff
@@ -0,0 +1,42 @@
+- // MIR for `match_zext_u8_i16_failed` before MatchBranchSimplification
++ // MIR for `match_zext_u8_i16_failed` after MatchBranchSimplification
+  
+  fn match_zext_u8_i16_failed(_1: EnumAu8) -> i16 {
+      debug i => _1;
+      let mut _0: i16;
+      let mut _2: u8;
+  
+      bb0: {
+          _2 = discriminant(_1);
+          switchInt(move _2) -> [0: bb5, 127: bb4, 128: bb3, 255: bb2, otherwise: bb1];
+      }
+  
+      bb1: {
+          unreachable;
+      }
+  
+      bb2: {
+          _0 = const 255_i16;
+          goto -> bb6;
+      }
+  
+      bb3: {
+          _0 = const 128_i16;
+          goto -> bb6;
+      }
+  
+      bb4: {
+          _0 = const -127_i16;
+          goto -> bb6;
+      }
+  
+      bb5: {
+          _0 = const 0_i16;
+          goto -> bb6;
+      }
+  
+      bb6: {
+          return;
+      }
+  }
+  
diff --git a/tests/mir-opt/matches_reduce_branches.match_zext_u8_u16.MatchBranchSimplification.diff b/tests/mir-opt/matches_reduce_branches.match_zext_u8_u16.MatchBranchSimplification.diff
new file mode 100644
index 00000000000..befb9118907
--- /dev/null
+++ b/tests/mir-opt/matches_reduce_branches.match_zext_u8_u16.MatchBranchSimplification.diff
@@ -0,0 +1,47 @@
+- // MIR for `match_zext_u8_u16` before MatchBranchSimplification
++ // MIR for `match_zext_u8_u16` after MatchBranchSimplification
+  
+  fn match_zext_u8_u16(_1: EnumAu8) -> u16 {
+      debug i => _1;
+      let mut _0: u16;
+      let mut _2: u8;
++     let mut _3: u8;
+  
+      bb0: {
+          _2 = discriminant(_1);
+-         switchInt(move _2) -> [0: bb5, 127: bb4, 128: bb3, 255: bb2, otherwise: bb1];
+-     }
+- 
+-     bb1: {
+-         unreachable;
+-     }
+- 
+-     bb2: {
+-         _0 = const 255_u16;
+-         goto -> bb6;
+-     }
+- 
+-     bb3: {
+-         _0 = const 128_u16;
+-         goto -> bb6;
+-     }
+- 
+-     bb4: {
+-         _0 = const 127_u16;
+-         goto -> bb6;
+-     }
+- 
+-     bb5: {
+-         _0 = const 0_u16;
+-         goto -> bb6;
+-     }
+- 
+-     bb6: {
++         StorageLive(_3);
++         _3 = move _2;
++         _0 = _3 as u16 (IntToInt);
++         StorageDead(_3);
+          return;
+      }
+  }
+  
diff --git a/tests/mir-opt/matches_reduce_branches.match_zext_u8_u16_failed.MatchBranchSimplification.diff b/tests/mir-opt/matches_reduce_branches.match_zext_u8_u16_failed.MatchBranchSimplification.diff
new file mode 100644
index 00000000000..f781f88449d
--- /dev/null
+++ b/tests/mir-opt/matches_reduce_branches.match_zext_u8_u16_failed.MatchBranchSimplification.diff
@@ -0,0 +1,42 @@
+- // MIR for `match_zext_u8_u16_failed` before MatchBranchSimplification
++ // MIR for `match_zext_u8_u16_failed` after MatchBranchSimplification
+  
+  fn match_zext_u8_u16_failed(_1: EnumAu8) -> u16 {
+      debug i => _1;
+      let mut _0: u16;
+      let mut _2: u8;
+  
+      bb0: {
+          _2 = discriminant(_1);
+          switchInt(move _2) -> [0: bb5, 127: bb4, 128: bb3, 255: bb2, otherwise: bb1];
+      }
+  
+      bb1: {
+          unreachable;
+      }
+  
+      bb2: {
+          _0 = const 255_u16;
+          goto -> bb6;
+      }
+  
+      bb3: {
+          _0 = const 128_u16;
+          goto -> bb6;
+      }
+  
+      bb4: {
+          _0 = const 65407_u16;
+          goto -> bb6;
+      }
+  
+      bb5: {
+          _0 = const 0_u16;
+          goto -> bb6;
+      }
+  
+      bb6: {
+          return;
+      }
+  }
+  
diff --git a/tests/mir-opt/matches_reduce_branches.rs b/tests/mir-opt/matches_reduce_branches.rs
index 176d68bcd40..9328c616127 100644
--- a/tests/mir-opt/matches_reduce_branches.rs
+++ b/tests/mir-opt/matches_reduce_branches.rs
@@ -1,8 +1,10 @@
 //@ test-mir-pass: MatchBranchSimplification
+//@ compile-flags: -Zunsound-mir-opts
 
 #![feature(repr128)]
 #![feature(core_intrinsics)]
 #![feature(custom_mir)]
+#![allow(non_camel_case_types)]
 
 use std::intrinsics::mir::*;
 
@@ -12,6 +14,7 @@ fn foo(bar: Option<()>) {
     // CHECK: = Eq(
     // CHECK: switchInt
     // CHECK-NOT: switchInt
+    // CHECK: return
     if matches!(bar, None) {
         ()
     }
@@ -23,6 +26,7 @@ fn bar(i: i32) -> (bool, bool, bool, bool) {
     // CHECK: = Ne(
     // CHECK: = Eq(
     // CHECK-NOT: switchInt
+    // CHECK: return
     let a;
     let b;
     let c;
@@ -52,6 +56,7 @@ fn bar(i: i32) -> (bool, bool, bool, bool) {
 fn match_nested_if() -> bool {
     // CHECK-LABEL: fn match_nested_if(
     // CHECK-NOT: switchInt
+    // CHECK: return
     let val = match () {
         () if if if if true { true } else { false } { true } else { false } {
             true
@@ -66,42 +71,170 @@ fn match_nested_if() -> bool {
     val
 }
 
+// # Fold switchInt into IntToInt.
+// To simplify writing and checking these test cases, I use the first character of
+// each case to distinguish the sign of the number:
+// 'u' for unsigned, '_' for negative, and 'o' for non-negative.
+// Followed by a decimal number, and add the corresponding radix representation.
+// For example, o127_0x7f represents 127i8, and _1_0xff represents -1i8.
+
+// ## Cast but without numeric conversion.
+
 #[repr(u8)]
 enum EnumAu8 {
-    A = 1,
-    B = 2,
+    u0_0x00 = 0,
+    u127_0x7f = 127,
+    u128_0x80 = 128,
+    u255_0xff = 255,
+}
+
+#[repr(i8)]
+enum EnumAi8 {
+    _128_0x80 = -128,
+    _1_0xff = -1,
+    o0_0x00 = 0,
+    o1_0x01 = 1,
+    o127_0x7f = 127,
 }
 
-// EMIT_MIR matches_reduce_branches.match_u8_i16.MatchBranchSimplification.diff
-fn match_u8_i16(i: EnumAu8) -> i16 {
-    // CHECK-LABEL: fn match_u8_i16(
+// EMIT_MIR matches_reduce_branches.match_u8_i8.MatchBranchSimplification.diff
+fn match_u8_i8(i: EnumAu8) -> i8 {
+    // CHECK-LABEL: fn match_u8_i8(
+    // CHECK-NOT: switchInt
+    // CHECK: return
+    match i {
+        EnumAu8::u0_0x00 => 0,
+        EnumAu8::u127_0x7f => 127,
+        EnumAu8::u128_0x80 => -128,
+        EnumAu8::u255_0xff => -1,
+    }
+}
+
+// EMIT_MIR matches_reduce_branches.match_u8_i8_failed.MatchBranchSimplification.diff
+fn match_u8_i8_failed(i: EnumAu8) -> i8 {
+    // CHECK-LABEL: fn match_u8_i8_failed(
     // CHECK: switchInt
+    // CHECK: return
     match i {
-        EnumAu8::A => 1,
-        EnumAu8::B => 2,
+        EnumAu8::u0_0x00 => 0,
+        EnumAu8::u127_0x7f => 127,
+        EnumAu8::u128_0x80 => -128,
+        EnumAu8::u255_0xff => 1, // failed
     }
 }
 
-// EMIT_MIR matches_reduce_branches.match_u8_i16_2.MatchBranchSimplification.diff
+// EMIT_MIR matches_reduce_branches.match_u8_i8_2.MatchBranchSimplification.diff
+fn match_u8_i8_2(i: EnumAu8) -> (i8, i8) {
+    // CHECK-LABEL: fn match_u8_i8_2(
+    // CHECK-NOT: switchInt
+    // CHECK: IntToInt
+    // CHECK: IntToInt
+    // CHECK: return
+    let a: i8;
+    let b: i8;
+    match i {
+        EnumAu8::u0_0x00 => {
+            a = 0;
+            b = 0;
+            ()
+        }
+        EnumAu8::u127_0x7f => {
+            a = 127;
+            b = 127;
+            ()
+        }
+        EnumAu8::u128_0x80 => {
+            a = -128;
+            b = -128;
+            ()
+        }
+        EnumAu8::u255_0xff => {
+            a = -1;
+            b = -1;
+            ()
+        }
+    };
+    (a, b)
+}
+
+// EMIT_MIR matches_reduce_branches.match_u8_i8_2_failed.MatchBranchSimplification.diff
+fn match_u8_i8_2_failed(i: EnumAu8) -> (i8, i8) {
+    // CHECK-LABEL: fn match_u8_i8_2_failed(
+    // CHECK: switchInt
+    // CHECK: return
+    let a: i8;
+    let b: i8;
+    match i {
+        EnumAu8::u0_0x00 => {
+            a = 0;
+            b = 0;
+            ()
+        }
+        EnumAu8::u127_0x7f => {
+            a = 127;
+            b = 127;
+            ()
+        }
+        EnumAu8::u128_0x80 => {
+            a = -128;
+            b = -128;
+            ()
+        }
+        EnumAu8::u255_0xff => {
+            a = -1;
+            b = 1; // failed
+            ()
+        }
+    };
+    (a, b)
+}
+
+// EMIT_MIR matches_reduce_branches.match_u8_i8_fallback.MatchBranchSimplification.diff
+fn match_u8_i8_fallback(i: EnumAu8) -> i8 {
+    // CHECK-LABEL: fn match_u8_i8_fallback(
+    // CHECK: switchInt
+    // CHECK: return
+    match i {
+        EnumAu8::u0_0x00 => 0,
+        EnumAu8::u127_0x7f => 127,
+        EnumAu8::u128_0x80 => -128,
+        _ => -1,
+    }
+}
+
+// EMIT_MIR matches_reduce_branches.match_u8_i8_failed_len_1.MatchBranchSimplification.diff
 // Check for different instruction lengths
 #[custom_mir(dialect = "built")]
-fn match_u8_i16_2(i: EnumAu8) -> i16 {
-    // CHECK-LABEL: fn match_u8_i16_2(
+fn match_u8_i8_failed_len_1(i: EnumAu8) -> i8 {
+    // CHECK-LABEL: fn match_u8_i8_failed_len_1(
     // CHECK: switchInt
+    // CHECK: return
     mir! {
         {
             let a = Discriminant(i);
             match a {
-                1 => bb1,
-                2 => bb2,
+                0 => bb1,
+                127 => bb2,
+                128 => bb3,
+                255 => bb4,
                 _ => unreachable_bb,
             }
         }
         bb1 = {
+            RET = 0;
             Goto(ret)
         }
         bb2 = {
-            RET = 2;
+            RET = 127;
+            RET = 127;
+            Goto(ret)
+        }
+        bb3 = {
+            RET = -128;
+            Goto(ret)
+        }
+        bb4 = {
+            RET = -1;
             Goto(ret)
         }
         unreachable_bb = {
@@ -113,72 +246,39 @@ fn match_u8_i16_2(i: EnumAu8) -> i16 {
     }
 }
 
-// EMIT_MIR matches_reduce_branches.match_u8_i16_failed.MatchBranchSimplification.diff
-fn match_u8_i16_failed(i: EnumAu8) -> i16 {
-    // CHECK-LABEL: fn match_u8_i16_failed(
-    // CHECK: switchInt
-    match i {
-        EnumAu8::A => 1,
-        EnumAu8::B => 3,
-    }
-}
-
-// EMIT_MIR matches_reduce_branches.match_u8_i16_fallback.MatchBranchSimplification.diff
-fn match_u8_i16_fallback(i: u8) -> i16 {
-    // CHECK-LABEL: fn match_u8_i16_fallback(
-    // CHECK: switchInt
-    match i {
-        1 => 1,
-        2 => 2,
-        _ => 3,
-    }
-}
-
-#[repr(u8)]
-enum EnumBu8 {
-    A = 1,
-    B = 2,
-    C = 5,
-}
-
-// EMIT_MIR matches_reduce_branches.match_u8_u16.MatchBranchSimplification.diff
-fn match_u8_u16(i: EnumBu8) -> u16 {
-    // CHECK-LABEL: fn match_u8_u16(
-    // CHECK: switchInt
-    match i {
-        EnumBu8::A => 1,
-        EnumBu8::B => 2,
-        EnumBu8::C => 5,
-    }
-}
-
-// EMIT_MIR matches_reduce_branches.match_u8_u16_2.MatchBranchSimplification.diff
+// EMIT_MIR matches_reduce_branches.match_u8_i8_failed_len_2.MatchBranchSimplification.diff
 // Check for different instruction lengths
 #[custom_mir(dialect = "built")]
-fn match_u8_u16_2(i: EnumBu8) -> i16 {
-    // CHECK-LABEL: fn match_u8_u16_2(
+fn match_u8_i8_failed_len_2(i: EnumAu8) -> i8 {
+    // CHECK-LABEL: fn match_u8_i8_failed_len_2(
     // CHECK: switchInt
+    // CHECK: return
     mir! {
         {
             let a = Discriminant(i);
             match a {
-                1 => bb1,
-                2 => bb2,
-                5 => bb5,
+                0 => bb1,
+                127 => bb2,
+                128 => bb3,
+                255 => bb4,
                 _ => unreachable_bb,
             }
         }
         bb1 = {
-            RET = 1;
+            RET = 0;
             Goto(ret)
         }
         bb2 = {
-            RET = 2;
+            RET = 127;
             Goto(ret)
         }
-        bb5 = {
-            RET = 5;
-            RET = 5;
+        bb3 = {
+            RET = -128;
+            Goto(ret)
+        }
+        bb4 = {
+            RET = -1;
+            RET = -1;
             Goto(ret)
         }
         unreachable_bb = {
@@ -190,50 +290,309 @@ fn match_u8_u16_2(i: EnumBu8) -> i16 {
     }
 }
 
-#[repr(i8)]
-enum EnumAi8 {
-    A = -1,
-    B = 2,
-    C = -3,
+// ## Cast with sext.
+
+// EMIT_MIR matches_reduce_branches.match_sext_i8_i16.MatchBranchSimplification.diff
+fn match_sext_i8_i16(i: EnumAi8) -> i16 {
+    // CHECK-LABEL: fn match_sext_i8_i16(
+    // CHECK-NOT: switchInt
+    // CHECK: return
+    match i {
+        EnumAi8::_128_0x80 => -128,
+        EnumAi8::_1_0xff => -1,
+        EnumAi8::o0_0x00 => 0,
+        EnumAi8::o1_0x01 => 1,
+        EnumAi8::o127_0x7f => 127,
+    }
+}
+
+// EMIT_MIR matches_reduce_branches.match_sext_i8_i16_failed.MatchBranchSimplification.diff
+// Converting `-1i8` to `255i16` is zext.
+fn match_sext_i8_i16_failed(i: EnumAi8) -> i16 {
+    // CHECK-LABEL: fn match_sext_i8_i16_failed(
+    // CHECK: switchInt
+    // CHECK: return
+    match i {
+        EnumAi8::_128_0x80 => -128,
+        EnumAi8::_1_0xff => 255, // failed
+        EnumAi8::o0_0x00 => 0,
+        EnumAi8::o1_0x01 => 1,
+        EnumAi8::o127_0x7f => 127,
+    }
+}
+
+// EMIT_MIR matches_reduce_branches.match_sext_i8_u16.MatchBranchSimplification.diff
+fn match_sext_i8_u16(i: EnumAi8) -> u16 {
+    // CHECK-LABEL: fn match_sext_i8_u16(
+    // CHECK-NOT: switchInt
+    // CHECK: return
+    match i {
+        EnumAi8::_128_0x80 => 0xff80,
+        EnumAi8::_1_0xff => 0xffff,
+        EnumAi8::o0_0x00 => 0,
+        EnumAi8::o1_0x01 => 1,
+        EnumAi8::o127_0x7f => 127,
+    }
+}
+
+// EMIT_MIR matches_reduce_branches.match_sext_i8_u16_failed.MatchBranchSimplification.diff
+// Converting `-1i8` to `255u16` is zext.
+fn match_sext_i8_u16_failed(i: EnumAi8) -> u16 {
+    // CHECK-LABEL: fn match_sext_i8_u16_failed(
+    // CHECK: switchInt
+    // CHECK: return
+    match i {
+        EnumAi8::_128_0x80 => 0xff80,
+        EnumAi8::_1_0xff => 0x00ff, // failed
+        EnumAi8::o0_0x00 => 0,
+        EnumAi8::o1_0x01 => 1,
+        EnumAi8::o127_0x7f => 127,
+    }
+}
+
+// ## Cast with zext.
+
+// EMIT_MIR matches_reduce_branches.match_zext_u8_u16.MatchBranchSimplification.diff
+fn match_zext_u8_u16(i: EnumAu8) -> u16 {
+    // CHECK-LABEL: fn match_zext_u8_u16(
+    // CHECK-NOT: switchInt
+    // CHECK: return
+    match i {
+        EnumAu8::u0_0x00 => 0,
+        EnumAu8::u127_0x7f => 0x7f,
+        EnumAu8::u128_0x80 => 128,
+        EnumAu8::u255_0xff => 255,
+    }
 }
 
-// EMIT_MIR matches_reduce_branches.match_i8_i16.MatchBranchSimplification.diff
-fn match_i8_i16(i: EnumAi8) -> i16 {
-    // CHECK-LABEL: fn match_i8_i16(
+// EMIT_MIR matches_reduce_branches.match_zext_u8_u16_failed.MatchBranchSimplification.diff
+fn match_zext_u8_u16_failed(i: EnumAu8) -> u16 {
+    // CHECK-LABEL: fn match_zext_u8_u16_failed(
     // CHECK: switchInt
+    // CHECK: return
+    match i {
+        EnumAu8::u0_0x00 => 0,
+        EnumAu8::u127_0x7f => 0xff7f, // failed
+        EnumAu8::u128_0x80 => 128,
+        EnumAu8::u255_0xff => 255,
+    }
+}
+
+// EMIT_MIR matches_reduce_branches.match_zext_u8_i16.MatchBranchSimplification.diff
+fn match_zext_u8_i16(i: EnumAu8) -> i16 {
+    // CHECK-LABEL: fn match_zext_u8_i16(
+    // CHECK-NOT: switchInt
+    // CHECK: return
     match i {
-        EnumAi8::A => -1,
-        EnumAi8::B => 2,
-        EnumAi8::C => -3,
+        EnumAu8::u0_0x00 => 0,
+        EnumAu8::u127_0x7f => 127,
+        EnumAu8::u128_0x80 => 128,
+        EnumAu8::u255_0xff => 255,
     }
 }
 
-// EMIT_MIR matches_reduce_branches.match_i8_i16_failed.MatchBranchSimplification.diff
-fn match_i8_i16_failed(i: EnumAi8) -> i16 {
-    // CHECK-LABEL: fn match_i8_i16_failed(
+// EMIT_MIR matches_reduce_branches.match_zext_u8_i16_failed.MatchBranchSimplification.diff
+fn match_zext_u8_i16_failed(i: EnumAu8) -> i16 {
+    // CHECK-LABEL: fn match_zext_u8_i16_failed(
     // CHECK: switchInt
+    // CHECK: return
     match i {
-        EnumAi8::A => -1,
-        EnumAi8::B => 2,
-        EnumAi8::C => 3,
+        EnumAu8::u0_0x00 => 0,
+        EnumAu8::u127_0x7f => -127, // failed
+        EnumAu8::u128_0x80 => 128,
+        EnumAu8::u255_0xff => 255,
     }
 }
 
+// ## Cast with trunc.
+
+#[repr(u16)]
+enum EnumAu16 {
+    // 0x00nn
+    u0_0x0000 = 0,
+    u127_0x007f = 127,
+    u128_0x0080 = 128,
+    u255_0x00ff = 255,
+    // 0xffnn
+    u65280_0xff00 = 65280,
+    u65407_0xff7f = 65407,
+    u65408_0xff80 = 65408,
+    u65535_0xffff = 65535,
+}
+
 #[repr(i16)]
 enum EnumAi16 {
-    A = -1,
-    B = 2,
-    C = -3,
+    // 0x00nn
+    o128_0x0080 = 128,
+    o255_0x00ff = 255,
+    o0_0x0000 = 0,
+    o1_0x0001 = 1,
+    o127_0x007f = 127,
+    // 0xffnn
+    _128_0xff80 = -128,
+    _1_0xffff = -1,
+    o0_0xff00 = -256,
+    o1_0xff01 = -255,
+    o127_0xff7f = -129,
 }
 
-// EMIT_MIR matches_reduce_branches.match_i16_i8.MatchBranchSimplification.diff
-fn match_i16_i8(i: EnumAi16) -> i8 {
-    // CHECK-LABEL: fn match_i16_i8(
+// EMIT_MIR matches_reduce_branches.match_trunc_i16_i8.MatchBranchSimplification.diff
+fn match_trunc_i16_i8(i: EnumAi16) -> i8 {
+    // CHECK-LABEL: fn match_trunc_i16_i8(
+    // CHECK-NOT: switchInt
+    // CHECK: return
+    match i {
+        // 0x00nn
+        EnumAi16::o128_0x0080 => -128,
+        EnumAi16::o255_0x00ff => -1,
+        EnumAi16::o0_0x0000 => 0,
+        EnumAi16::o1_0x0001 => 1,
+        EnumAi16::o127_0x007f => 127,
+        // 0xffnn
+        EnumAi16::_128_0xff80 => -128,
+        EnumAi16::_1_0xffff => -1,
+        EnumAi16::o0_0xff00 => 0,
+        EnumAi16::o1_0xff01 => 1,
+        EnumAi16::o127_0xff7f => 127,
+    }
+}
+
+// EMIT_MIR matches_reduce_branches.match_trunc_i16_i8_failed.MatchBranchSimplification.diff
+fn match_trunc_i16_i8_failed(i: EnumAi16) -> i8 {
+    // CHECK-LABEL: fn match_trunc_i16_i8_failed(
     // CHECK: switchInt
+    // CHECK: return
     match i {
-        EnumAi16::A => -1,
-        EnumAi16::B => 2,
-        EnumAi16::C => -3,
+        // 0x00nn
+        EnumAi16::o128_0x0080 => -128,
+        EnumAi16::o255_0x00ff => -1,
+        EnumAi16::o0_0x0000 => 0,
+        EnumAi16::o1_0x0001 => 1,
+        EnumAi16::o127_0x007f => 127,
+        // 0xffnn
+        EnumAi16::_128_0xff80 => -128,
+        EnumAi16::_1_0xffff => -1,
+        EnumAi16::o0_0xff00 => 0,
+        EnumAi16::o1_0xff01 => 1,
+        EnumAi16::o127_0xff7f => -127, // failed
+    }
+}
+
+// EMIT_MIR matches_reduce_branches.match_trunc_i16_u8.MatchBranchSimplification.diff
+fn match_trunc_i16_u8(i: EnumAi16) -> u8 {
+    // CHECK-LABEL: fn match_trunc_i16_u8(
+    // CHECK-NOT: switchInt
+    // CHECK: return
+    match i {
+        // 0x00nn
+        EnumAi16::o128_0x0080 => 128,
+        EnumAi16::o255_0x00ff => 255,
+        EnumAi16::o0_0x0000 => 0,
+        EnumAi16::o1_0x0001 => 1,
+        EnumAi16::o127_0x007f => 127,
+        // 0xffnn
+        EnumAi16::_128_0xff80 => 128,
+        EnumAi16::_1_0xffff => 255,
+        EnumAi16::o0_0xff00 => 0,
+        EnumAi16::o1_0xff01 => 1,
+        EnumAi16::o127_0xff7f => 127,
+    }
+}
+
+// EMIT_MIR matches_reduce_branches.match_trunc_i16_u8_failed.MatchBranchSimplification.diff
+fn match_trunc_i16_u8_failed(i: EnumAi16) -> u8 {
+    // CHECK-LABEL: fn match_trunc_i16_u8_failed(
+    // CHECK: switchInt
+    // CHECK: return
+    match i {
+        // 0x00nn
+        EnumAi16::o128_0x0080 => 128,
+        EnumAi16::o255_0x00ff => 255,
+        EnumAi16::o0_0x0000 => 0,
+        EnumAi16::o1_0x0001 => 1,
+        EnumAi16::o127_0x007f => 127,
+        // 0xffnn
+        EnumAi16::_128_0xff80 => 128,
+        EnumAi16::_1_0xffff => 255,
+        EnumAi16::o0_0xff00 => 0,
+        EnumAi16::o1_0xff01 => 1,
+        EnumAi16::o127_0xff7f => -127i8 as u8, // failed
+    }
+}
+
+// EMIT_MIR matches_reduce_branches.match_trunc_u16_u8.MatchBranchSimplification.diff
+fn match_trunc_u16_u8(i: EnumAu16) -> u8 {
+    // CHECK-LABEL: fn match_trunc_u16_u8(
+    // CHECK-NOT: switchInt
+    // CHECK: return
+    match i {
+        // 0x00nn
+        EnumAu16::u0_0x0000 => 0,
+        EnumAu16::u127_0x007f => 127,
+        EnumAu16::u128_0x0080 => 128,
+        EnumAu16::u255_0x00ff => 255,
+        // 0xffnn
+        EnumAu16::u65280_0xff00 => 0,
+        EnumAu16::u65407_0xff7f => 127,
+        EnumAu16::u65408_0xff80 => 128,
+        EnumAu16::u65535_0xffff => 255,
+    }
+}
+
+// EMIT_MIR matches_reduce_branches.match_trunc_u16_u8_failed.MatchBranchSimplification.diff
+fn match_trunc_u16_u8_failed(i: EnumAu16) -> u8 {
+    // CHECK-LABEL: fn match_trunc_u16_u8_failed(
+    // CHECK: switchInt
+    // CHECK: return
+    match i {
+        // 0x00nn
+        EnumAu16::u0_0x0000 => 0,
+        EnumAu16::u127_0x007f => 127,
+        EnumAu16::u128_0x0080 => 128,
+        EnumAu16::u255_0x00ff => 255,
+        // 0xffnn
+        EnumAu16::u65280_0xff00 => 0,
+        EnumAu16::u65407_0xff7f => 127,
+        EnumAu16::u65408_0xff80 => 128,
+        EnumAu16::u65535_0xffff => 127, // failed
+    }
+}
+
+// EMIT_MIR matches_reduce_branches.match_trunc_u16_i8.MatchBranchSimplification.diff
+fn match_trunc_u16_i8(i: EnumAu16) -> i8 {
+    // CHECK-LABEL: fn match_trunc_u16_i8(
+    // CHECK-NOT: switchInt
+    // CHECK: return
+    match i {
+        // 0x00nn
+        EnumAu16::u0_0x0000 => 0,
+        EnumAu16::u127_0x007f => 127,
+        EnumAu16::u128_0x0080 => -128,
+        EnumAu16::u255_0x00ff => -1,
+        // 0xffnn
+        EnumAu16::u65280_0xff00 => 0,
+        EnumAu16::u65407_0xff7f => 127,
+        EnumAu16::u65408_0xff80 => -128,
+        EnumAu16::u65535_0xffff => -1,
+    }
+}
+
+// EMIT_MIR matches_reduce_branches.match_trunc_u16_i8_failed.MatchBranchSimplification.diff
+fn match_trunc_u16_i8_failed(i: EnumAu16) -> i8 {
+    // CHECK-LABEL: fn match_trunc_u16_i8_failed(
+    // CHECK: switchInt
+    // CHECK: return
+    match i {
+        // 0x00nn
+        EnumAu16::u0_0x0000 => 0,
+        EnumAu16::u127_0x007f => 127,
+        EnumAu16::u128_0x0080 => -128,
+        EnumAu16::u255_0x00ff => -1,
+        // 0xffnn
+        EnumAu16::u65280_0xff00 => 0,
+        EnumAu16::u65407_0xff7f => 127,
+        EnumAu16::u65408_0xff80 => -128,
+        EnumAu16::u65535_0xffff => 1,
     }
 }
 
@@ -248,7 +607,8 @@ enum EnumAi128 {
 // EMIT_MIR matches_reduce_branches.match_i128_u128.MatchBranchSimplification.diff
 fn match_i128_u128(i: EnumAi128) -> u128 {
     // CHECK-LABEL: fn match_i128_u128(
-    // CHECK: switchInt
+    // CHECK-NOT: switchInt
+    // CHECK: return
     match i {
         EnumAi128::A => 1,
         EnumAi128::B => 2,
@@ -262,15 +622,34 @@ fn main() {
     let _ = foo(Some(()));
     let _ = bar(0);
     let _ = match_nested_if();
-    let _ = match_u8_i16(EnumAu8::A);
-    let _ = match_u8_i16_2(EnumAu8::A);
-    let _ = match_u8_i16_failed(EnumAu8::A);
-    let _ = match_u8_i16_fallback(1);
-    let _ = match_u8_u16(EnumBu8::A);
-    let _ = match_u8_u16_2(EnumBu8::A);
-    let _ = match_i8_i16(EnumAi8::A);
-    let _ = match_i8_i16_failed(EnumAi8::A);
-    let _ = match_i8_i16(EnumAi8::A);
-    let _ = match_i16_i8(EnumAi16::A);
+
+    let _: i8 = match_u8_i8(EnumAu8::u0_0x00);
+    let _: i8 = match_u8_i8_failed(EnumAu8::u0_0x00);
+    let _: (i8, i8) = match_u8_i8_2(EnumAu8::u0_0x00);
+    let _: (i8, i8) = match_u8_i8_2_failed(EnumAu8::u0_0x00);
+    let _: i8 = match_u8_i8_fallback(EnumAu8::u0_0x00);
+    let _: i8 = match_u8_i8_failed_len_1(EnumAu8::u0_0x00);
+    let _: i8 = match_u8_i8_failed_len_2(EnumAu8::u0_0x00);
+
+    let _: i16 = match_sext_i8_i16(EnumAi8::o0_0x00);
+    let _: i16 = match_sext_i8_i16_failed(EnumAi8::o0_0x00);
+    let _: u16 = match_sext_i8_u16(EnumAi8::o0_0x00);
+    let _: u16 = match_sext_i8_u16_failed(EnumAi8::o0_0x00);
+
+    let _: u16 = match_zext_u8_u16(EnumAu8::u0_0x00);
+    let _: u16 = match_zext_u8_u16_failed(EnumAu8::u0_0x00);
+    let _: i16 = match_zext_u8_i16(EnumAu8::u0_0x00);
+    let _: i16 = match_zext_u8_i16_failed(EnumAu8::u0_0x00);
+
+    let _: i8 = match_trunc_i16_i8(EnumAi16::o0_0x0000);
+    let _: i8 = match_trunc_i16_i8_failed(EnumAi16::o0_0x0000);
+    let _: u8 = match_trunc_i16_u8(EnumAi16::o0_0x0000);
+    let _: u8 = match_trunc_i16_u8_failed(EnumAi16::o0_0x0000);
+
+    let _: i8 = match_trunc_u16_i8(EnumAu16::u0_0x0000);
+    let _: i8 = match_trunc_u16_i8_failed(EnumAu16::u0_0x0000);
+    let _: u8 = match_trunc_u16_u8(EnumAu16::u0_0x0000);
+    let _: u8 = match_trunc_u16_u8_failed(EnumAu16::u0_0x0000);
+
     let _ = match_i128_u128(EnumAi128::A);
 }
diff --git a/tests/mir-opt/matches_u8.exhaustive_match.MatchBranchSimplification.diff b/tests/mir-opt/matches_u8.exhaustive_match.MatchBranchSimplification.diff
index 157f9c98353..11a18f58e3a 100644
--- a/tests/mir-opt/matches_u8.exhaustive_match.MatchBranchSimplification.diff
+++ b/tests/mir-opt/matches_u8.exhaustive_match.MatchBranchSimplification.diff
@@ -5,27 +5,32 @@
       debug e => _1;
       let mut _0: u8;
       let mut _2: isize;
++     let mut _3: isize;
   
       bb0: {
           _2 = discriminant(_1);
-          switchInt(move _2) -> [0: bb3, 1: bb2, otherwise: bb1];
-      }
-  
-      bb1: {
-          unreachable;
-      }
-  
-      bb2: {
-          _0 = const 1_u8;
-          goto -> bb4;
-      }
-  
-      bb3: {
-          _0 = const 0_u8;
-          goto -> bb4;
-      }
-  
-      bb4: {
+-         switchInt(move _2) -> [0: bb3, 1: bb2, otherwise: bb1];
+-     }
+- 
+-     bb1: {
+-         unreachable;
+-     }
+- 
+-     bb2: {
+-         _0 = const 1_u8;
+-         goto -> bb4;
+-     }
+- 
+-     bb3: {
+-         _0 = const 0_u8;
+-         goto -> bb4;
+-     }
+- 
+-     bb4: {
++         StorageLive(_3);
++         _3 = move _2;
++         _0 = _3 as u8 (IntToInt);
++         StorageDead(_3);
           return;
       }
   }
diff --git a/tests/mir-opt/matches_u8.exhaustive_match_i8.MatchBranchSimplification.diff b/tests/mir-opt/matches_u8.exhaustive_match_i8.MatchBranchSimplification.diff
index 19083771fd9..809badc41ba 100644
--- a/tests/mir-opt/matches_u8.exhaustive_match_i8.MatchBranchSimplification.diff
+++ b/tests/mir-opt/matches_u8.exhaustive_match_i8.MatchBranchSimplification.diff
@@ -5,27 +5,32 @@
       debug e => _1;
       let mut _0: i8;
       let mut _2: isize;
++     let mut _3: isize;
   
       bb0: {
           _2 = discriminant(_1);
-          switchInt(move _2) -> [0: bb3, 1: bb2, otherwise: bb1];
-      }
-  
-      bb1: {
-          unreachable;
-      }
-  
-      bb2: {
-          _0 = const 1_i8;
-          goto -> bb4;
-      }
-  
-      bb3: {
-          _0 = const 0_i8;
-          goto -> bb4;
-      }
-  
-      bb4: {
+-         switchInt(move _2) -> [0: bb3, 1: bb2, otherwise: bb1];
+-     }
+- 
+-     bb1: {
+-         unreachable;
+-     }
+- 
+-     bb2: {
+-         _0 = const 1_i8;
+-         goto -> bb4;
+-     }
+- 
+-     bb3: {
+-         _0 = const 0_i8;
+-         goto -> bb4;
+-     }
+- 
+-     bb4: {
++         StorageLive(_3);
++         _3 = move _2;
++         _0 = _3 as i8 (IntToInt);
++         StorageDead(_3);
           return;
       }
   }
diff --git a/tests/mir-opt/matches_u8.rs b/tests/mir-opt/matches_u8.rs
index 86d64625674..89deead461e 100644
--- a/tests/mir-opt/matches_u8.rs
+++ b/tests/mir-opt/matches_u8.rs
@@ -1,5 +1,6 @@
 // skip-filecheck
 //@ test-mir-pass: MatchBranchSimplification
+//@ compile-flags: -Zunsound-mir-opts
 
 // EMIT_MIR matches_u8.exhaustive_match.MatchBranchSimplification.diff
 // EMIT_MIR matches_u8.exhaustive_match_i8.MatchBranchSimplification.diff