about summary refs log tree commit diff
diff options
context:
space:
mode:
authorCamille GILLOT <gillot.camille@gmail.com>2023-09-16 09:35:46 +0000
committerCamille GILLOT <gillot.camille@gmail.com>2023-10-25 06:46:47 +0000
commit48d2157a89ffddce3287c57b3e3817a7e093b6c5 (patch)
tree1102b41765d669b7ca3ea6488ebfcca3406c8ef2
parent692e5286479e16b3e9b47ab842b543985e1a6ceb (diff)
downloadrust-48d2157a89ffddce3287c57b3e3817a7e093b6c5.tar.gz
rust-48d2157a89ffddce3287c57b3e3817a7e093b6c5.zip
Simplify aggregate projections.
-rw-r--r--compiler/rustc_mir_transform/src/gvn.rs41
-rw-r--r--tests/mir-opt/gvn.references.GVN.panic-abort.diff21
-rw-r--r--tests/mir-opt/gvn.references.GVN.panic-unwind.diff21
-rw-r--r--tests/mir-opt/gvn.slices.GVN.panic-abort.diff82
-rw-r--r--tests/mir-opt/gvn.slices.GVN.panic-unwind.diff82
-rw-r--r--tests/mir-opt/gvn.subexpression_elimination.GVN.panic-abort.diff14
-rw-r--r--tests/mir-opt/gvn.subexpression_elimination.GVN.panic-unwind.diff14
-rw-r--r--tests/mir-opt/gvn.wrap_unwrap.GVN.panic-abort.diff18
-rw-r--r--tests/mir-opt/gvn.wrap_unwrap.GVN.panic-unwind.diff18
9 files changed, 192 insertions, 119 deletions
diff --git a/compiler/rustc_mir_transform/src/gvn.rs b/compiler/rustc_mir_transform/src/gvn.rs
index eaa1c70a5e9..70d0f22a7b9 100644
--- a/compiler/rustc_mir_transform/src/gvn.rs
+++ b/compiler/rustc_mir_transform/src/gvn.rs
@@ -276,6 +276,10 @@ impl<'body, 'tcx> VnState<'body, 'tcx> {
         }
     }
 
+    fn insert_scalar(&mut self, scalar: Scalar, ty: Ty<'tcx>) -> VnIndex {
+        self.insert(Value::Constant(Const::from_scalar(self.tcx, scalar, ty)))
+    }
+
     #[instrument(level = "trace", skip(self), ret)]
     fn eval_to_const(&mut self, value: VnIndex) -> Option<OpTy<'tcx>> {
         use Value::*;
@@ -483,12 +487,33 @@ impl<'body, 'tcx> VnState<'body, 'tcx> {
                 }
             }
             ProjectionElem::Downcast(name, index) => ProjectionElem::Downcast(name, index),
-            ProjectionElem::Field(f, ty) => ProjectionElem::Field(f, ty),
+            ProjectionElem::Field(f, ty) => {
+                if let Value::Aggregate(_, _, fields) = self.get(value) {
+                    return Some(fields[f.as_usize()]);
+                } else if let Value::Projection(outer_value, ProjectionElem::Downcast(_, read_variant)) = self.get(value)
+                    && let Value::Aggregate(_, written_variant, fields) = self.get(*outer_value)
+                    && written_variant == read_variant
+                {
+                    return Some(fields[f.as_usize()]);
+                }
+                ProjectionElem::Field(f, ty)
+            }
             ProjectionElem::Index(idx) => {
                 let idx = self.locals[idx]?;
                 ProjectionElem::Index(idx)
             }
             ProjectionElem::ConstantIndex { offset, min_length, from_end } => {
+                match self.get(value) {
+                    Value::Aggregate(ty, _, operands) if ty.is_array() => {
+                        let offset = if from_end {
+                            operands.len() - offset as usize
+                        } else {
+                            offset as usize
+                        };
+                        return operands.get(offset).copied();
+                    }
+                    _ => {}
+                };
                 ProjectionElem::ConstantIndex { offset, min_length, from_end }
             }
             ProjectionElem::Subslice { from, to, from_end } => {
@@ -679,6 +704,9 @@ impl<'body, 'tcx> VnState<'body, 'tcx> {
             }
             Rvalue::Discriminant(ref mut place) => {
                 let place = self.simplify_place_value(place, location)?;
+                if let Some(discr) = self.simplify_discriminant(place) {
+                    return Some(discr);
+                }
                 Value::Discriminant(place)
             }
 
@@ -688,6 +716,17 @@ impl<'body, 'tcx> VnState<'body, 'tcx> {
         debug!(?value);
         Some(self.insert(value))
     }
+
+    fn simplify_discriminant(&mut self, place: VnIndex) -> Option<VnIndex> {
+        if let Value::Aggregate(enum_ty, variant, _) = *self.get(place)
+            && enum_ty.is_enum()
+        {
+            let discr = self.ecx.discriminant_for_variant(enum_ty, variant).ok()?;
+            return Some(self.insert_scalar(discr.to_scalar(), discr.layout.ty));
+        }
+
+        None
+    }
 }
 
 fn op_to_prop_const<'tcx>(
diff --git a/tests/mir-opt/gvn.references.GVN.panic-abort.diff b/tests/mir-opt/gvn.references.GVN.panic-abort.diff
index 88543172565..7799c611445 100644
--- a/tests/mir-opt/gvn.references.GVN.panic-abort.diff
+++ b/tests/mir-opt/gvn.references.GVN.panic-abort.diff
@@ -115,8 +115,7 @@
 -         StorageLive(_18);
 +         nop;
           _18 = &mut _1;
--         StorageLive(_19);
-+         nop;
+          StorageLive(_19);
           StorageLive(_20);
           StorageLive(_21);
 -         _21 = move _18;
@@ -124,11 +123,13 @@
 +         _21 = _18;
 +         _20 = S::<&mut impl Sized>(_18);
           StorageDead(_21);
-          _19 = move (_20.0: &mut impl Sized);
+-         _19 = move (_20.0: &mut impl Sized);
++         _19 = _18;
           StorageDead(_20);
           StorageLive(_22);
           StorageLive(_23);
-          _23 = &(*_19);
+-         _23 = &(*_19);
++         _23 = &(*_18);
           _22 = opaque::<&impl Sized>(move _23) -> [return: bb9, unwind unreachable];
       }
   
@@ -137,7 +138,8 @@
           StorageDead(_22);
           StorageLive(_24);
           StorageLive(_25);
-          _25 = &mut (*_19);
+-         _25 = &mut (*_19);
++         _25 = &mut (*_18);
           _24 = opaque::<&mut impl Sized>(move _25) -> [return: bb10, unwind unreachable];
       }
   
@@ -146,7 +148,8 @@
           StorageDead(_24);
           StorageLive(_26);
           StorageLive(_27);
-          _27 = &raw const (*_19);
+-         _27 = &raw const (*_19);
++         _27 = &raw const (*_18);
           _26 = opaque::<*const impl Sized>(move _27) -> [return: bb11, unwind unreachable];
       }
   
@@ -155,7 +158,8 @@
           StorageDead(_26);
           StorageLive(_28);
           StorageLive(_29);
-          _29 = &raw mut (*_19);
+-         _29 = &raw mut (*_19);
++         _29 = &raw mut (*_18);
           _28 = opaque::<*mut impl Sized>(move _29) -> [return: bb12, unwind unreachable];
       }
   
@@ -163,10 +167,9 @@
           StorageDead(_29);
           StorageDead(_28);
           _0 = const ();
--         StorageDead(_19);
+          StorageDead(_19);
 -         StorageDead(_18);
 +         nop;
-+         nop;
           drop(_1) -> [return: bb13, unwind unreachable];
       }
   
diff --git a/tests/mir-opt/gvn.references.GVN.panic-unwind.diff b/tests/mir-opt/gvn.references.GVN.panic-unwind.diff
index 106b453fe80..880e7913fa9 100644
--- a/tests/mir-opt/gvn.references.GVN.panic-unwind.diff
+++ b/tests/mir-opt/gvn.references.GVN.panic-unwind.diff
@@ -115,8 +115,7 @@
 -         StorageLive(_18);
 +         nop;
           _18 = &mut _1;
--         StorageLive(_19);
-+         nop;
+          StorageLive(_19);
           StorageLive(_20);
           StorageLive(_21);
 -         _21 = move _18;
@@ -124,11 +123,13 @@
 +         _21 = _18;
 +         _20 = S::<&mut impl Sized>(_18);
           StorageDead(_21);
-          _19 = move (_20.0: &mut impl Sized);
+-         _19 = move (_20.0: &mut impl Sized);
++         _19 = _18;
           StorageDead(_20);
           StorageLive(_22);
           StorageLive(_23);
-          _23 = &(*_19);
+-         _23 = &(*_19);
++         _23 = &(*_18);
           _22 = opaque::<&impl Sized>(move _23) -> [return: bb9, unwind: bb14];
       }
   
@@ -137,7 +138,8 @@
           StorageDead(_22);
           StorageLive(_24);
           StorageLive(_25);
-          _25 = &mut (*_19);
+-         _25 = &mut (*_19);
++         _25 = &mut (*_18);
           _24 = opaque::<&mut impl Sized>(move _25) -> [return: bb10, unwind: bb14];
       }
   
@@ -146,7 +148,8 @@
           StorageDead(_24);
           StorageLive(_26);
           StorageLive(_27);
-          _27 = &raw const (*_19);
+-         _27 = &raw const (*_19);
++         _27 = &raw const (*_18);
           _26 = opaque::<*const impl Sized>(move _27) -> [return: bb11, unwind: bb14];
       }
   
@@ -155,7 +158,8 @@
           StorageDead(_26);
           StorageLive(_28);
           StorageLive(_29);
-          _29 = &raw mut (*_19);
+-         _29 = &raw mut (*_19);
++         _29 = &raw mut (*_18);
           _28 = opaque::<*mut impl Sized>(move _29) -> [return: bb12, unwind: bb14];
       }
   
@@ -163,10 +167,9 @@
           StorageDead(_29);
           StorageDead(_28);
           _0 = const ();
--         StorageDead(_19);
+          StorageDead(_19);
 -         StorageDead(_18);
 +         nop;
-+         nop;
           drop(_1) -> [return: bb13, unwind: bb15];
       }
   
diff --git a/tests/mir-opt/gvn.slices.GVN.panic-abort.diff b/tests/mir-opt/gvn.slices.GVN.panic-abort.diff
index 6168476d6f2..9db6e068fa7 100644
--- a/tests/mir-opt/gvn.slices.GVN.panic-abort.diff
+++ b/tests/mir-opt/gvn.slices.GVN.panic-abort.diff
@@ -112,7 +112,8 @@
           StorageDead(_5);
           StorageLive(_7);
           StorageLive(_8);
-          StorageLive(_9);
+-         StorageLive(_9);
++         nop;
           StorageLive(_10);
           StorageLive(_11);
           _11 = &(*_1);
@@ -122,7 +123,8 @@
       bb3: {
           StorageDead(_11);
           _9 = &_10;
-          StorageLive(_12);
+-         StorageLive(_12);
++         nop;
           StorageLive(_13);
           StorageLive(_14);
 -         _14 = &(*_4);
@@ -133,20 +135,25 @@
       bb4: {
           StorageDead(_14);
           _12 = &_13;
-          _8 = (move _9, move _12);
-          StorageDead(_12);
-          StorageDead(_9);
--         StorageLive(_15);
+-         _8 = (move _9, move _12);
+-         StorageDead(_12);
+-         StorageDead(_9);
++         _8 = (_9, _12);
 +         nop;
-          _15 = (_8.0: &*const u8);
--         StorageLive(_16);
 +         nop;
-          _16 = (_8.1: &*const u8);
+          StorageLive(_15);
+-         _15 = (_8.0: &*const u8);
++         _15 = _9;
+          StorageLive(_16);
+-         _16 = (_8.1: &*const u8);
++         _16 = _12;
           StorageLive(_17);
           StorageLive(_18);
-          _18 = (*_15);
+-         _18 = (*_15);
++         _18 = (*_9);
           StorageLive(_19);
-          _19 = (*_16);
+-         _19 = (*_16);
++         _19 = (*_12);
           _17 = Eq(move _18, move _19);
           switchInt(move _17) -> [0: bb6, otherwise: bb5];
       }
@@ -156,10 +163,8 @@
           StorageDead(_18);
           _7 = const ();
           StorageDead(_17);
--         StorageDead(_16);
--         StorageDead(_15);
-+         nop;
-+         nop;
+          StorageDead(_16);
+          StorageDead(_15);
           StorageDead(_13);
           StorageDead(_10);
           StorageDead(_8);
@@ -190,13 +195,15 @@
 +         _23 = const core::panicking::AssertKind::Eq;
           StorageLive(_24);
 -         StorageLive(_25);
+-         _25 = &(*_15);
 +         nop;
-          _25 = &(*_15);
++         _25 = &(*_9);
           _24 = &(*_25);
           StorageLive(_26);
 -         StorageLive(_27);
+-         _27 = &(*_16);
 +         nop;
-          _27 = &(*_16);
++         _27 = &(*_12);
           _26 = &(*_27);
           StorageLive(_28);
           _28 = Option::<Arguments<'_>>::None;
@@ -209,7 +216,8 @@
           StorageDead(_31);
           StorageLive(_33);
           StorageLive(_34);
-          StorageLive(_35);
+-         StorageLive(_35);
++         nop;
           StorageLive(_36);
           StorageLive(_37);
           _37 = &(*_1);
@@ -219,7 +227,8 @@
       bb8: {
           StorageDead(_37);
           _35 = &_36;
-          StorageLive(_38);
+-         StorageLive(_38);
++         nop;
           StorageLive(_39);
           StorageLive(_40);
           _40 = &(*_29);
@@ -229,20 +238,25 @@
       bb9: {
           StorageDead(_40);
           _38 = &_39;
-          _34 = (move _35, move _38);
-          StorageDead(_38);
-          StorageDead(_35);
--         StorageLive(_41);
+-         _34 = (move _35, move _38);
+-         StorageDead(_38);
+-         StorageDead(_35);
++         _34 = (_35, _38);
 +         nop;
-          _41 = (_34.0: &*const u8);
--         StorageLive(_42);
 +         nop;
-          _42 = (_34.1: &*const u8);
+          StorageLive(_41);
+-         _41 = (_34.0: &*const u8);
++         _41 = _35;
+          StorageLive(_42);
+-         _42 = (_34.1: &*const u8);
++         _42 = _38;
           StorageLive(_43);
           StorageLive(_44);
-          _44 = (*_41);
+-         _44 = (*_41);
++         _44 = (*_35);
           StorageLive(_45);
-          _45 = (*_42);
+-         _45 = (*_42);
++         _45 = (*_38);
           _43 = Eq(move _44, move _45);
           switchInt(move _43) -> [0: bb11, otherwise: bb10];
       }
@@ -252,10 +266,8 @@
           StorageDead(_44);
           _33 = const ();
           StorageDead(_43);
--         StorageDead(_42);
--         StorageDead(_41);
-+         nop;
-+         nop;
+          StorageDead(_42);
+          StorageDead(_41);
           StorageDead(_39);
           StorageDead(_36);
           StorageDead(_34);
@@ -282,13 +294,15 @@
 +         _49 = const core::panicking::AssertKind::Eq;
           StorageLive(_50);
 -         StorageLive(_51);
+-         _51 = &(*_41);
 +         nop;
-          _51 = &(*_41);
++         _51 = &(*_35);
           _50 = &(*_51);
           StorageLive(_52);
 -         StorageLive(_53);
+-         _53 = &(*_42);
 +         nop;
-          _53 = &(*_42);
++         _53 = &(*_38);
           _52 = &(*_53);
           StorageLive(_54);
           _54 = Option::<Arguments<'_>>::None;
diff --git a/tests/mir-opt/gvn.slices.GVN.panic-unwind.diff b/tests/mir-opt/gvn.slices.GVN.panic-unwind.diff
index f6003885808..ac7a3e74688 100644
--- a/tests/mir-opt/gvn.slices.GVN.panic-unwind.diff
+++ b/tests/mir-opt/gvn.slices.GVN.panic-unwind.diff
@@ -112,7 +112,8 @@
           StorageDead(_5);
           StorageLive(_7);
           StorageLive(_8);
-          StorageLive(_9);
+-         StorageLive(_9);
++         nop;
           StorageLive(_10);
           StorageLive(_11);
           _11 = &(*_1);
@@ -122,7 +123,8 @@
       bb3: {
           StorageDead(_11);
           _9 = &_10;
-          StorageLive(_12);
+-         StorageLive(_12);
++         nop;
           StorageLive(_13);
           StorageLive(_14);
 -         _14 = &(*_4);
@@ -133,20 +135,25 @@
       bb4: {
           StorageDead(_14);
           _12 = &_13;
-          _8 = (move _9, move _12);
-          StorageDead(_12);
-          StorageDead(_9);
--         StorageLive(_15);
+-         _8 = (move _9, move _12);
+-         StorageDead(_12);
+-         StorageDead(_9);
++         _8 = (_9, _12);
 +         nop;
-          _15 = (_8.0: &*const u8);
--         StorageLive(_16);
 +         nop;
-          _16 = (_8.1: &*const u8);
+          StorageLive(_15);
+-         _15 = (_8.0: &*const u8);
++         _15 = _9;
+          StorageLive(_16);
+-         _16 = (_8.1: &*const u8);
++         _16 = _12;
           StorageLive(_17);
           StorageLive(_18);
-          _18 = (*_15);
+-         _18 = (*_15);
++         _18 = (*_9);
           StorageLive(_19);
-          _19 = (*_16);
+-         _19 = (*_16);
++         _19 = (*_12);
           _17 = Eq(move _18, move _19);
           switchInt(move _17) -> [0: bb6, otherwise: bb5];
       }
@@ -156,10 +163,8 @@
           StorageDead(_18);
           _7 = const ();
           StorageDead(_17);
--         StorageDead(_16);
--         StorageDead(_15);
-+         nop;
-+         nop;
+          StorageDead(_16);
+          StorageDead(_15);
           StorageDead(_13);
           StorageDead(_10);
           StorageDead(_8);
@@ -190,13 +195,15 @@
 +         _23 = const core::panicking::AssertKind::Eq;
           StorageLive(_24);
 -         StorageLive(_25);
+-         _25 = &(*_15);
 +         nop;
-          _25 = &(*_15);
++         _25 = &(*_9);
           _24 = &(*_25);
           StorageLive(_26);
 -         StorageLive(_27);
+-         _27 = &(*_16);
 +         nop;
-          _27 = &(*_16);
++         _27 = &(*_12);
           _26 = &(*_27);
           StorageLive(_28);
           _28 = Option::<Arguments<'_>>::None;
@@ -209,7 +216,8 @@
           StorageDead(_31);
           StorageLive(_33);
           StorageLive(_34);
-          StorageLive(_35);
+-         StorageLive(_35);
++         nop;
           StorageLive(_36);
           StorageLive(_37);
           _37 = &(*_1);
@@ -219,7 +227,8 @@
       bb8: {
           StorageDead(_37);
           _35 = &_36;
-          StorageLive(_38);
+-         StorageLive(_38);
++         nop;
           StorageLive(_39);
           StorageLive(_40);
           _40 = &(*_29);
@@ -229,20 +238,25 @@
       bb9: {
           StorageDead(_40);
           _38 = &_39;
-          _34 = (move _35, move _38);
-          StorageDead(_38);
-          StorageDead(_35);
--         StorageLive(_41);
+-         _34 = (move _35, move _38);
+-         StorageDead(_38);
+-         StorageDead(_35);
++         _34 = (_35, _38);
 +         nop;
-          _41 = (_34.0: &*const u8);
--         StorageLive(_42);
 +         nop;
-          _42 = (_34.1: &*const u8);
+          StorageLive(_41);
+-         _41 = (_34.0: &*const u8);
++         _41 = _35;
+          StorageLive(_42);
+-         _42 = (_34.1: &*const u8);
++         _42 = _38;
           StorageLive(_43);
           StorageLive(_44);
-          _44 = (*_41);
+-         _44 = (*_41);
++         _44 = (*_35);
           StorageLive(_45);
-          _45 = (*_42);
+-         _45 = (*_42);
++         _45 = (*_38);
           _43 = Eq(move _44, move _45);
           switchInt(move _43) -> [0: bb11, otherwise: bb10];
       }
@@ -252,10 +266,8 @@
           StorageDead(_44);
           _33 = const ();
           StorageDead(_43);
--         StorageDead(_42);
--         StorageDead(_41);
-+         nop;
-+         nop;
+          StorageDead(_42);
+          StorageDead(_41);
           StorageDead(_39);
           StorageDead(_36);
           StorageDead(_34);
@@ -282,13 +294,15 @@
 +         _49 = const core::panicking::AssertKind::Eq;
           StorageLive(_50);
 -         StorageLive(_51);
+-         _51 = &(*_41);
 +         nop;
-          _51 = &(*_41);
++         _51 = &(*_35);
           _50 = &(*_51);
           StorageLive(_52);
 -         StorageLive(_53);
+-         _53 = &(*_42);
 +         nop;
-          _53 = &(*_42);
++         _53 = &(*_38);
           _52 = &(*_53);
           StorageLive(_54);
           _54 = Option::<Arguments<'_>>::None;
diff --git a/tests/mir-opt/gvn.subexpression_elimination.GVN.panic-abort.diff b/tests/mir-opt/gvn.subexpression_elimination.GVN.panic-abort.diff
index 41f29959c95..23ba2559448 100644
--- a/tests/mir-opt/gvn.subexpression_elimination.GVN.panic-abort.diff
+++ b/tests/mir-opt/gvn.subexpression_elimination.GVN.panic-abort.diff
@@ -442,8 +442,7 @@
 +         nop;
           StorageDead(_52);
           StorageLive(_55);
--         StorageLive(_56);
-+         nop;
+          StorageLive(_56);
           StorageLive(_57);
           StorageLive(_58);
           _58 = _1;
@@ -452,13 +451,12 @@
           StorageDead(_58);
 -         _56 = (_57.0: u64);
 -         _55 = opaque::<u64>(move _56) -> [return: bb16, unwind unreachable];
-+         _56 = (_53.0: u64);
-+         _55 = opaque::<u64>(_56) -> [return: bb16, unwind unreachable];
++         _56 = _1;
++         _55 = opaque::<u64>(_1) -> [return: bb16, unwind unreachable];
       }
   
       bb16: {
--         StorageDead(_56);
-+         nop;
+          StorageDead(_56);
           StorageDead(_57);
           StorageDead(_55);
           StorageLive(_59);
@@ -729,8 +727,8 @@
           StorageDead(_127);
 -         _125 = (_126.0: u64);
 -         _124 = opaque::<u64>(move _125) -> [return: bb30, unwind unreachable];
-+         _125 = _56;
-+         _124 = opaque::<u64>(_56) -> [return: bb30, unwind unreachable];
++         _125 = _1;
++         _124 = opaque::<u64>(_1) -> [return: bb30, unwind unreachable];
       }
   
       bb30: {
diff --git a/tests/mir-opt/gvn.subexpression_elimination.GVN.panic-unwind.diff b/tests/mir-opt/gvn.subexpression_elimination.GVN.panic-unwind.diff
index ca928986cf6..062dc6ff561 100644
--- a/tests/mir-opt/gvn.subexpression_elimination.GVN.panic-unwind.diff
+++ b/tests/mir-opt/gvn.subexpression_elimination.GVN.panic-unwind.diff
@@ -442,8 +442,7 @@
 +         nop;
           StorageDead(_52);
           StorageLive(_55);
--         StorageLive(_56);
-+         nop;
+          StorageLive(_56);
           StorageLive(_57);
           StorageLive(_58);
           _58 = _1;
@@ -452,13 +451,12 @@
           StorageDead(_58);
 -         _56 = (_57.0: u64);
 -         _55 = opaque::<u64>(move _56) -> [return: bb16, unwind continue];
-+         _56 = (_53.0: u64);
-+         _55 = opaque::<u64>(_56) -> [return: bb16, unwind continue];
++         _56 = _1;
++         _55 = opaque::<u64>(_1) -> [return: bb16, unwind continue];
       }
   
       bb16: {
--         StorageDead(_56);
-+         nop;
+          StorageDead(_56);
           StorageDead(_57);
           StorageDead(_55);
           StorageLive(_59);
@@ -729,8 +727,8 @@
           StorageDead(_127);
 -         _125 = (_126.0: u64);
 -         _124 = opaque::<u64>(move _125) -> [return: bb30, unwind continue];
-+         _125 = _56;
-+         _124 = opaque::<u64>(_56) -> [return: bb30, unwind continue];
++         _125 = _1;
++         _124 = opaque::<u64>(_1) -> [return: bb30, unwind continue];
       }
   
       bb30: {
diff --git a/tests/mir-opt/gvn.wrap_unwrap.GVN.panic-abort.diff b/tests/mir-opt/gvn.wrap_unwrap.GVN.panic-abort.diff
index 2dd51934778..62710ba8fbf 100644
--- a/tests/mir-opt/gvn.wrap_unwrap.GVN.panic-abort.diff
+++ b/tests/mir-opt/gvn.wrap_unwrap.GVN.panic-abort.diff
@@ -20,8 +20,10 @@
 -         _2 = Option::<T>::Some(move _3);
 +         _2 = Option::<T>::Some(_1);
           StorageDead(_3);
-          _4 = discriminant(_2);
-          switchInt(move _4) -> [0: bb1, 1: bb3, otherwise: bb2];
+-         _4 = discriminant(_2);
+-         switchInt(move _4) -> [0: bb1, 1: bb3, otherwise: bb2];
++         _4 = const 1_isize;
++         switchInt(const 1_isize) -> [0: bb1, 1: bb3, otherwise: bb2];
       }
   
       bb1: {
@@ -34,12 +36,12 @@
       }
   
       bb3: {
--         StorageLive(_5);
-+         nop;
-          _5 = ((_2 as Some).0: T);
-          _0 = _5;
--         StorageDead(_5);
-+         nop;
+          StorageLive(_5);
+-         _5 = ((_2 as Some).0: T);
+-         _0 = _5;
++         _5 = _1;
++         _0 = _1;
+          StorageDead(_5);
           StorageDead(_2);
           return;
       }
diff --git a/tests/mir-opt/gvn.wrap_unwrap.GVN.panic-unwind.diff b/tests/mir-opt/gvn.wrap_unwrap.GVN.panic-unwind.diff
index 610d70576c9..ad46a065b1e 100644
--- a/tests/mir-opt/gvn.wrap_unwrap.GVN.panic-unwind.diff
+++ b/tests/mir-opt/gvn.wrap_unwrap.GVN.panic-unwind.diff
@@ -20,8 +20,10 @@
 -         _2 = Option::<T>::Some(move _3);
 +         _2 = Option::<T>::Some(_1);
           StorageDead(_3);
-          _4 = discriminant(_2);
-          switchInt(move _4) -> [0: bb1, 1: bb3, otherwise: bb2];
+-         _4 = discriminant(_2);
+-         switchInt(move _4) -> [0: bb1, 1: bb3, otherwise: bb2];
++         _4 = const 1_isize;
++         switchInt(const 1_isize) -> [0: bb1, 1: bb3, otherwise: bb2];
       }
   
       bb1: {
@@ -34,12 +36,12 @@
       }
   
       bb3: {
--         StorageLive(_5);
-+         nop;
-          _5 = ((_2 as Some).0: T);
-          _0 = _5;
--         StorageDead(_5);
-+         nop;
+          StorageLive(_5);
+-         _5 = ((_2 as Some).0: T);
+-         _0 = _5;
++         _5 = _1;
++         _0 = _1;
+          StorageDead(_5);
           StorageDead(_2);
           return;
       }