From 7e39100586d717f5a350eb8704bcd8938d09419c Mon Sep 17 00:00:00 2001
From: Camille GILLOT <gillot.camille@gmail.com>
Date: Sun, 24 Dec 2023 13:00:48 +0000
Subject: [PATCH] Avoid recording no-op replacements.

---
 compiler/rustc_mir_transform/src/gvn.rs       | 13 ++++----
 .../const_allocation.main.GVN.after.32bit.mir |  4 +--
 .../const_allocation.main.GVN.after.64bit.mir |  4 +--
 ...const_allocation2.main.GVN.after.32bit.mir |  4 +--
 ...const_allocation2.main.GVN.after.64bit.mir |  4 +--
 ...const_allocation3.main.GVN.after.32bit.mir |  4 +--
 ...const_allocation3.main.GVN.after.64bit.mir |  4 +--
 .../const_prop/address_of_pair.fn0.GVN.diff   |  6 ++--
 ...for_slices.main.GVN.32bit.panic-abort.diff | 12 +++-----
 ...or_slices.main.GVN.32bit.panic-unwind.diff | 12 +++-----
 ...for_slices.main.GVN.64bit.panic-abort.diff | 12 +++-----
 ...or_slices.main.GVN.64bit.panic-unwind.diff | 12 +++-----
 .../const_prop/indirect_mutation.bar.GVN.diff |  6 ++--
 .../const_prop/indirect_mutation.foo.GVN.diff |  6 ++--
 ...e_variable_aggregate_mut_ref.main.GVN.diff |  6 ++--
 .../mutable_variable_no_prop.main.GVN.diff    |  6 ++--
 ...r_expose_address.main.GVN.panic-abort.diff |  6 ++--
 ..._expose_address.main.GVN.panic-unwind.diff |  6 ++--
 .../const_prop/ref_deref.main.GVN.diff        |  6 ++--
 .../ref_deref_project.main.GVN.diff           |  6 ++--
 .../slice_len.main.GVN.32bit.panic-abort.diff |  6 ++--
 ...slice_len.main.GVN.32bit.panic-unwind.diff |  6 ++--
 .../slice_len.main.GVN.64bit.panic-abort.diff |  6 ++--
 ...slice_len.main.GVN.64bit.panic-unwind.diff |  6 ++--
 .../transmute.unreachable_mut.GVN.32bit.diff  |  6 ++--
 .../transmute.unreachable_mut.GVN.64bit.diff  |  6 ++--
 .../gvn.dereferences.GVN.panic-abort.diff     | 18 ++++-------
 .../gvn.dereferences.GVN.panic-unwind.diff    | 18 ++++-------
 tests/mir-opt/gvn.slices.GVN.panic-abort.diff | 12 +++-----
 .../mir-opt/gvn.slices.GVN.panic-unwind.diff  | 12 +++-----
 ...xpression_elimination.GVN.panic-abort.diff | 30 +++++++------------
 ...pression_elimination.GVN.panic-unwind.diff | 30 +++++++------------
 ...variant_a-{closure#0}.PreCodegen.after.mir | 16 ++++++++++
 ...mut_usize.PreCodegen.after.panic-abort.mir |  2 ++
 ...ut_usize.PreCodegen.after.panic-unwind.mir |  2 ++
 35 files changed, 126 insertions(+), 189 deletions(-)

diff --git a/compiler/rustc_mir_transform/src/gvn.rs b/compiler/rustc_mir_transform/src/gvn.rs
index e8b86d1327d..dc3af038d80 100644
--- a/compiler/rustc_mir_transform/src/gvn.rs
+++ b/compiler/rustc_mir_transform/src/gvn.rs
@@ -637,6 +637,7 @@ impl<'body, 'tcx> VnState<'body, 'tcx> {
         if place.is_indirect()
             && let Some(base) = self.locals[place.local]
             && let Some(new_local) = self.try_as_local(base, location)
+            && place.local != new_local
         {
             place.local = new_local;
             self.reused_locals.insert(new_local);
@@ -646,8 +647,8 @@ impl<'body, 'tcx> VnState<'body, 'tcx> {
 
         for i in 0..projection.len() {
             let elem = projection[i];
-            if let ProjectionElem::Index(idx) = elem
-                && let Some(idx) = self.locals[idx]
+            if let ProjectionElem::Index(idx_local) = elem
+                && let Some(idx) = self.locals[idx_local]
             {
                 if let Some(offset) = self.evaluated[idx].as_ref()
                     && let Ok(offset) = self.ecx.read_target_usize(offset)
@@ -655,9 +656,11 @@ impl<'body, 'tcx> VnState<'body, 'tcx> {
                 {
                     projection.to_mut()[i] =
                         ProjectionElem::ConstantIndex { offset, min_length, from_end: false };
-                } else if let Some(new_idx) = self.try_as_local(idx, location) {
-                    projection.to_mut()[i] = ProjectionElem::Index(new_idx);
-                    self.reused_locals.insert(new_idx);
+                } else if let Some(new_idx_local) = self.try_as_local(idx, location)
+                    && idx_local != new_idx_local
+                {
+                    projection.to_mut()[i] = ProjectionElem::Index(new_idx_local);
+                    self.reused_locals.insert(new_idx_local);
                 }
             }
         }
diff --git a/tests/mir-opt/const_allocation.main.GVN.after.32bit.mir b/tests/mir-opt/const_allocation.main.GVN.after.32bit.mir
index f089c6741fe..10d99a13463 100644
--- a/tests/mir-opt/const_allocation.main.GVN.after.32bit.mir
+++ b/tests/mir-opt/const_allocation.main.GVN.after.32bit.mir
@@ -7,10 +7,10 @@ fn main() -> () {
 
     bb0: {
         StorageLive(_1);
-        nop;
+        StorageLive(_2);
         _2 = const {ALLOC9: &&[(Option<i32>, &[&str])]};
         _1 = (*_2);
-        nop;
+        StorageDead(_2);
         StorageDead(_1);
         _0 = const ();
         return;
diff --git a/tests/mir-opt/const_allocation.main.GVN.after.64bit.mir b/tests/mir-opt/const_allocation.main.GVN.after.64bit.mir
index 9cbbaf302be..2f23dbe9ee4 100644
--- a/tests/mir-opt/const_allocation.main.GVN.after.64bit.mir
+++ b/tests/mir-opt/const_allocation.main.GVN.after.64bit.mir
@@ -7,10 +7,10 @@ fn main() -> () {
 
     bb0: {
         StorageLive(_1);
-        nop;
+        StorageLive(_2);
         _2 = const {ALLOC9: &&[(Option<i32>, &[&str])]};
         _1 = (*_2);
-        nop;
+        StorageDead(_2);
         StorageDead(_1);
         _0 = const ();
         return;
diff --git a/tests/mir-opt/const_allocation2.main.GVN.after.32bit.mir b/tests/mir-opt/const_allocation2.main.GVN.after.32bit.mir
index dfa2d808128..6499e3676aa 100644
--- a/tests/mir-opt/const_allocation2.main.GVN.after.32bit.mir
+++ b/tests/mir-opt/const_allocation2.main.GVN.after.32bit.mir
@@ -7,10 +7,10 @@ fn main() -> () {
 
     bb0: {
         StorageLive(_1);
-        nop;
+        StorageLive(_2);
         _2 = const {ALLOC9: &&[(Option<i32>, &[&u8])]};
         _1 = (*_2);
-        nop;
+        StorageDead(_2);
         StorageDead(_1);
         _0 = const ();
         return;
diff --git a/tests/mir-opt/const_allocation2.main.GVN.after.64bit.mir b/tests/mir-opt/const_allocation2.main.GVN.after.64bit.mir
index 02b66987169..02f5ebab847 100644
--- a/tests/mir-opt/const_allocation2.main.GVN.after.64bit.mir
+++ b/tests/mir-opt/const_allocation2.main.GVN.after.64bit.mir
@@ -7,10 +7,10 @@ fn main() -> () {
 
     bb0: {
         StorageLive(_1);
-        nop;
+        StorageLive(_2);
         _2 = const {ALLOC9: &&[(Option<i32>, &[&u8])]};
         _1 = (*_2);
-        nop;
+        StorageDead(_2);
         StorageDead(_1);
         _0 = const ();
         return;
diff --git a/tests/mir-opt/const_allocation3.main.GVN.after.32bit.mir b/tests/mir-opt/const_allocation3.main.GVN.after.32bit.mir
index 386a55ee6fa..c95e696946a 100644
--- a/tests/mir-opt/const_allocation3.main.GVN.after.32bit.mir
+++ b/tests/mir-opt/const_allocation3.main.GVN.after.32bit.mir
@@ -7,10 +7,10 @@ fn main() -> () {
 
     bb0: {
         StorageLive(_1);
-        nop;
+        StorageLive(_2);
         _2 = const {ALLOC4: &&Packed};
         _1 = (*_2);
-        nop;
+        StorageDead(_2);
         StorageDead(_1);
         _0 = const ();
         return;
diff --git a/tests/mir-opt/const_allocation3.main.GVN.after.64bit.mir b/tests/mir-opt/const_allocation3.main.GVN.after.64bit.mir
index b9e98f8cd4c..198bc8bd07e 100644
--- a/tests/mir-opt/const_allocation3.main.GVN.after.64bit.mir
+++ b/tests/mir-opt/const_allocation3.main.GVN.after.64bit.mir
@@ -7,10 +7,10 @@ fn main() -> () {
 
     bb0: {
         StorageLive(_1);
-        nop;
+        StorageLive(_2);
         _2 = const {ALLOC2: &&Packed};
         _1 = (*_2);
-        nop;
+        StorageDead(_2);
         StorageDead(_1);
         _0 = const ();
         return;
diff --git a/tests/mir-opt/const_prop/address_of_pair.fn0.GVN.diff b/tests/mir-opt/const_prop/address_of_pair.fn0.GVN.diff
index 2285962fad1..a044cfc62e2 100644
--- a/tests/mir-opt/const_prop/address_of_pair.fn0.GVN.diff
+++ b/tests/mir-opt/const_prop/address_of_pair.fn0.GVN.diff
@@ -24,9 +24,8 @@
       bb0: {
           StorageLive(_2);
 -         _2 = (const 1_i32, const false);
--         StorageLive(_3);
 +         _2 = const (1_i32, false);
-+         nop;
+          StorageLive(_3);
           _3 = &raw mut (_2.1: bool);
 -         _2 = (const 1_i32, const false);
 +         _2 = const (1_i32, false);
@@ -42,9 +41,8 @@
           StorageDead(_6);
           _0 = _5;
 -         StorageDead(_5);
--         StorageDead(_3);
-+         nop;
 +         nop;
+          StorageDead(_3);
           StorageDead(_2);
           return;
       }
diff --git a/tests/mir-opt/const_prop/bad_op_unsafe_oob_for_slices.main.GVN.32bit.panic-abort.diff b/tests/mir-opt/const_prop/bad_op_unsafe_oob_for_slices.main.GVN.32bit.panic-abort.diff
index a42f9291324..e1a93e31446 100644
--- a/tests/mir-opt/const_prop/bad_op_unsafe_oob_for_slices.main.GVN.32bit.panic-abort.diff
+++ b/tests/mir-opt/const_prop/bad_op_unsafe_oob_for_slices.main.GVN.32bit.panic-abort.diff
@@ -22,18 +22,15 @@
       }
   
       bb0: {
--         StorageLive(_1);
-+         nop;
+          StorageLive(_1);
           StorageLive(_2);
--         StorageLive(_3);
-+         nop;
+          StorageLive(_3);
           _9 = const _;
           _3 = &(*_9);
           _2 = &raw const (*_3);
           _1 = move _2 as *const [i32] (PointerCoercion(Unsize));
           StorageDead(_2);
--         StorageDead(_3);
-+         nop;
+          StorageDead(_3);
           StorageLive(_5);
           StorageLive(_6);
           _6 = const 3_usize;
@@ -50,8 +47,7 @@
           StorageDead(_6);
           _0 = const ();
           StorageDead(_5);
--         StorageDead(_1);
-+         nop;
+          StorageDead(_1);
           return;
       }
   }
diff --git a/tests/mir-opt/const_prop/bad_op_unsafe_oob_for_slices.main.GVN.32bit.panic-unwind.diff b/tests/mir-opt/const_prop/bad_op_unsafe_oob_for_slices.main.GVN.32bit.panic-unwind.diff
index f2d6de6621b..91999145efb 100644
--- a/tests/mir-opt/const_prop/bad_op_unsafe_oob_for_slices.main.GVN.32bit.panic-unwind.diff
+++ b/tests/mir-opt/const_prop/bad_op_unsafe_oob_for_slices.main.GVN.32bit.panic-unwind.diff
@@ -22,18 +22,15 @@
       }
   
       bb0: {
--         StorageLive(_1);
-+         nop;
+          StorageLive(_1);
           StorageLive(_2);
--         StorageLive(_3);
-+         nop;
+          StorageLive(_3);
           _9 = const _;
           _3 = &(*_9);
           _2 = &raw const (*_3);
           _1 = move _2 as *const [i32] (PointerCoercion(Unsize));
           StorageDead(_2);
--         StorageDead(_3);
-+         nop;
+          StorageDead(_3);
           StorageLive(_5);
           StorageLive(_6);
           _6 = const 3_usize;
@@ -50,8 +47,7 @@
           StorageDead(_6);
           _0 = const ();
           StorageDead(_5);
--         StorageDead(_1);
-+         nop;
+          StorageDead(_1);
           return;
       }
   }
diff --git a/tests/mir-opt/const_prop/bad_op_unsafe_oob_for_slices.main.GVN.64bit.panic-abort.diff b/tests/mir-opt/const_prop/bad_op_unsafe_oob_for_slices.main.GVN.64bit.panic-abort.diff
index a42f9291324..e1a93e31446 100644
--- a/tests/mir-opt/const_prop/bad_op_unsafe_oob_for_slices.main.GVN.64bit.panic-abort.diff
+++ b/tests/mir-opt/const_prop/bad_op_unsafe_oob_for_slices.main.GVN.64bit.panic-abort.diff
@@ -22,18 +22,15 @@
       }
   
       bb0: {
--         StorageLive(_1);
-+         nop;
+          StorageLive(_1);
           StorageLive(_2);
--         StorageLive(_3);
-+         nop;
+          StorageLive(_3);
           _9 = const _;
           _3 = &(*_9);
           _2 = &raw const (*_3);
           _1 = move _2 as *const [i32] (PointerCoercion(Unsize));
           StorageDead(_2);
--         StorageDead(_3);
-+         nop;
+          StorageDead(_3);
           StorageLive(_5);
           StorageLive(_6);
           _6 = const 3_usize;
@@ -50,8 +47,7 @@
           StorageDead(_6);
           _0 = const ();
           StorageDead(_5);
--         StorageDead(_1);
-+         nop;
+          StorageDead(_1);
           return;
       }
   }
diff --git a/tests/mir-opt/const_prop/bad_op_unsafe_oob_for_slices.main.GVN.64bit.panic-unwind.diff b/tests/mir-opt/const_prop/bad_op_unsafe_oob_for_slices.main.GVN.64bit.panic-unwind.diff
index f2d6de6621b..91999145efb 100644
--- a/tests/mir-opt/const_prop/bad_op_unsafe_oob_for_slices.main.GVN.64bit.panic-unwind.diff
+++ b/tests/mir-opt/const_prop/bad_op_unsafe_oob_for_slices.main.GVN.64bit.panic-unwind.diff
@@ -22,18 +22,15 @@
       }
   
       bb0: {
--         StorageLive(_1);
-+         nop;
+          StorageLive(_1);
           StorageLive(_2);
--         StorageLive(_3);
-+         nop;
+          StorageLive(_3);
           _9 = const _;
           _3 = &(*_9);
           _2 = &raw const (*_3);
           _1 = move _2 as *const [i32] (PointerCoercion(Unsize));
           StorageDead(_2);
--         StorageDead(_3);
-+         nop;
+          StorageDead(_3);
           StorageLive(_5);
           StorageLive(_6);
           _6 = const 3_usize;
@@ -50,8 +47,7 @@
           StorageDead(_6);
           _0 = const ();
           StorageDead(_5);
--         StorageDead(_1);
-+         nop;
+          StorageDead(_1);
           return;
       }
   }
diff --git a/tests/mir-opt/const_prop/indirect_mutation.bar.GVN.diff b/tests/mir-opt/const_prop/indirect_mutation.bar.GVN.diff
index 7dd80d64360..b389080c497 100644
--- a/tests/mir-opt/const_prop/indirect_mutation.bar.GVN.diff
+++ b/tests/mir-opt/const_prop/indirect_mutation.bar.GVN.diff
@@ -22,12 +22,10 @@
 -         _1 = (const 1_i32,);
 +         _1 = const (1_i32,);
           StorageLive(_2);
--         StorageLive(_3);
-+         nop;
+          StorageLive(_3);
           _3 = &raw mut (_1.0: i32);
           (*_3) = const 5_i32;
--         StorageDead(_3);
-+         nop;
+          StorageDead(_3);
           _2 = const ();
           StorageDead(_2);
           StorageLive(_4);
diff --git a/tests/mir-opt/const_prop/indirect_mutation.foo.GVN.diff b/tests/mir-opt/const_prop/indirect_mutation.foo.GVN.diff
index c4b647d9d2d..c21869dece6 100644
--- a/tests/mir-opt/const_prop/indirect_mutation.foo.GVN.diff
+++ b/tests/mir-opt/const_prop/indirect_mutation.foo.GVN.diff
@@ -17,13 +17,11 @@
       bb0: {
           StorageLive(_1);
 -         _1 = (const 1_i32,);
--         StorageLive(_2);
 +         _1 = const (1_i32,);
-+         nop;
+          StorageLive(_2);
           _2 = &mut (_1.0: i32);
           (*_2) = const 5_i32;
--         StorageDead(_2);
-+         nop;
+          StorageDead(_2);
           StorageLive(_3);
           StorageLive(_4);
           _4 = (_1.0: i32);
diff --git a/tests/mir-opt/const_prop/mutable_variable_aggregate_mut_ref.main.GVN.diff b/tests/mir-opt/const_prop/mutable_variable_aggregate_mut_ref.main.GVN.diff
index bc60546cd19..4ed7c985147 100644
--- a/tests/mir-opt/const_prop/mutable_variable_aggregate_mut_ref.main.GVN.diff
+++ b/tests/mir-opt/const_prop/mutable_variable_aggregate_mut_ref.main.GVN.diff
@@ -19,17 +19,15 @@
       bb0: {
           StorageLive(_1);
 -         _1 = (const 42_i32, const 43_i32);
--         StorageLive(_2);
 +         _1 = const (42_i32, 43_i32);
-+         nop;
+          StorageLive(_2);
           _2 = &mut _1;
           ((*_2).1: i32) = const 99_i32;
           StorageLive(_3);
           _3 = _1;
           _0 = const ();
           StorageDead(_3);
--         StorageDead(_2);
-+         nop;
+          StorageDead(_2);
           StorageDead(_1);
           return;
       }
diff --git a/tests/mir-opt/const_prop/mutable_variable_no_prop.main.GVN.diff b/tests/mir-opt/const_prop/mutable_variable_no_prop.main.GVN.diff
index d02c392f6bd..e113f43a56e 100644
--- a/tests/mir-opt/const_prop/mutable_variable_no_prop.main.GVN.diff
+++ b/tests/mir-opt/const_prop/mutable_variable_no_prop.main.GVN.diff
@@ -22,14 +22,12 @@
           _1 = const 42_u32;
           StorageLive(_2);
           StorageLive(_3);
--         StorageLive(_4);
-+         nop;
+          StorageLive(_4);
           _4 = const {ALLOC0: *mut u32};
           _3 = (*_4);
           _1 = move _3;
           StorageDead(_3);
--         StorageDead(_4);
-+         nop;
+          StorageDead(_4);
           _2 = const ();
           StorageDead(_2);
           StorageLive(_5);
diff --git a/tests/mir-opt/const_prop/pointer_expose_address.main.GVN.panic-abort.diff b/tests/mir-opt/const_prop/pointer_expose_address.main.GVN.panic-abort.diff
index 425bc3ff6c1..4e79b3ad599 100644
--- a/tests/mir-opt/const_prop/pointer_expose_address.main.GVN.panic-abort.diff
+++ b/tests/mir-opt/const_prop/pointer_expose_address.main.GVN.panic-abort.diff
@@ -16,14 +16,12 @@
 -         StorageLive(_1);
 +         nop;
           StorageLive(_2);
--         StorageLive(_3);
-+         nop;
+          StorageLive(_3);
           _3 = const _;
           _2 = &raw const (*_3);
           _1 = move _2 as usize (PointerExposeAddress);
           StorageDead(_2);
--         StorageDead(_3);
-+         nop;
+          StorageDead(_3);
           StorageLive(_4);
           StorageLive(_5);
           _5 = _1;
diff --git a/tests/mir-opt/const_prop/pointer_expose_address.main.GVN.panic-unwind.diff b/tests/mir-opt/const_prop/pointer_expose_address.main.GVN.panic-unwind.diff
index e9360ab8d62..fdc459b457c 100644
--- a/tests/mir-opt/const_prop/pointer_expose_address.main.GVN.panic-unwind.diff
+++ b/tests/mir-opt/const_prop/pointer_expose_address.main.GVN.panic-unwind.diff
@@ -16,14 +16,12 @@
 -         StorageLive(_1);
 +         nop;
           StorageLive(_2);
--         StorageLive(_3);
-+         nop;
+          StorageLive(_3);
           _3 = const _;
           _2 = &raw const (*_3);
           _1 = move _2 as usize (PointerExposeAddress);
           StorageDead(_2);
--         StorageDead(_3);
-+         nop;
+          StorageDead(_3);
           StorageLive(_4);
           StorageLive(_5);
           _5 = _1;
diff --git a/tests/mir-opt/const_prop/ref_deref.main.GVN.diff b/tests/mir-opt/const_prop/ref_deref.main.GVN.diff
index 8f9aa20524d..56cbd00025e 100644
--- a/tests/mir-opt/const_prop/ref_deref.main.GVN.diff
+++ b/tests/mir-opt/const_prop/ref_deref.main.GVN.diff
@@ -13,14 +13,12 @@
   
       bb0: {
           StorageLive(_1);
--         StorageLive(_2);
-+         nop;
+          StorageLive(_2);
           _4 = const _;
           _2 = &(*_4);
 -         _1 = (*_2);
--         StorageDead(_2);
 +         _1 = const 4_i32;
-+         nop;
+          StorageDead(_2);
           _0 = const ();
           StorageDead(_1);
           return;
diff --git a/tests/mir-opt/const_prop/ref_deref_project.main.GVN.diff b/tests/mir-opt/const_prop/ref_deref_project.main.GVN.diff
index 8d38888b7d6..d75c0c3b286 100644
--- a/tests/mir-opt/const_prop/ref_deref_project.main.GVN.diff
+++ b/tests/mir-opt/const_prop/ref_deref_project.main.GVN.diff
@@ -13,14 +13,12 @@
   
       bb0: {
           StorageLive(_1);
--         StorageLive(_2);
-+         nop;
+          StorageLive(_2);
           _4 = const _;
           _2 = &((*_4).1: i32);
 -         _1 = (*_2);
--         StorageDead(_2);
 +         _1 = const 5_i32;
-+         nop;
+          StorageDead(_2);
           _0 = const ();
           StorageDead(_1);
           return;
diff --git a/tests/mir-opt/const_prop/slice_len.main.GVN.32bit.panic-abort.diff b/tests/mir-opt/const_prop/slice_len.main.GVN.32bit.panic-abort.diff
index 8b2411e50ab..803be994d9a 100644
--- a/tests/mir-opt/const_prop/slice_len.main.GVN.32bit.panic-abort.diff
+++ b/tests/mir-opt/const_prop/slice_len.main.GVN.32bit.panic-abort.diff
@@ -18,8 +18,7 @@
   
       bb0: {
           StorageLive(_1);
--         StorageLive(_2);
-+         nop;
+          StorageLive(_2);
           StorageLive(_3);
           StorageLive(_4);
           _9 = const _;
@@ -44,8 +43,7 @@
 +         _1 = (*_2)[1 of 2];
           StorageDead(_6);
           StorageDead(_4);
--         StorageDead(_2);
-+         nop;
+          StorageDead(_2);
           _0 = const ();
           StorageDead(_1);
           return;
diff --git a/tests/mir-opt/const_prop/slice_len.main.GVN.32bit.panic-unwind.diff b/tests/mir-opt/const_prop/slice_len.main.GVN.32bit.panic-unwind.diff
index 9b20d243f87..2a20e3eca59 100644
--- a/tests/mir-opt/const_prop/slice_len.main.GVN.32bit.panic-unwind.diff
+++ b/tests/mir-opt/const_prop/slice_len.main.GVN.32bit.panic-unwind.diff
@@ -18,8 +18,7 @@
   
       bb0: {
           StorageLive(_1);
--         StorageLive(_2);
-+         nop;
+          StorageLive(_2);
           StorageLive(_3);
           StorageLive(_4);
           _9 = const _;
@@ -44,8 +43,7 @@
 +         _1 = (*_2)[1 of 2];
           StorageDead(_6);
           StorageDead(_4);
--         StorageDead(_2);
-+         nop;
+          StorageDead(_2);
           _0 = const ();
           StorageDead(_1);
           return;
diff --git a/tests/mir-opt/const_prop/slice_len.main.GVN.64bit.panic-abort.diff b/tests/mir-opt/const_prop/slice_len.main.GVN.64bit.panic-abort.diff
index 8b2411e50ab..803be994d9a 100644
--- a/tests/mir-opt/const_prop/slice_len.main.GVN.64bit.panic-abort.diff
+++ b/tests/mir-opt/const_prop/slice_len.main.GVN.64bit.panic-abort.diff
@@ -18,8 +18,7 @@
   
       bb0: {
           StorageLive(_1);
--         StorageLive(_2);
-+         nop;
+          StorageLive(_2);
           StorageLive(_3);
           StorageLive(_4);
           _9 = const _;
@@ -44,8 +43,7 @@
 +         _1 = (*_2)[1 of 2];
           StorageDead(_6);
           StorageDead(_4);
--         StorageDead(_2);
-+         nop;
+          StorageDead(_2);
           _0 = const ();
           StorageDead(_1);
           return;
diff --git a/tests/mir-opt/const_prop/slice_len.main.GVN.64bit.panic-unwind.diff b/tests/mir-opt/const_prop/slice_len.main.GVN.64bit.panic-unwind.diff
index 9b20d243f87..2a20e3eca59 100644
--- a/tests/mir-opt/const_prop/slice_len.main.GVN.64bit.panic-unwind.diff
+++ b/tests/mir-opt/const_prop/slice_len.main.GVN.64bit.panic-unwind.diff
@@ -18,8 +18,7 @@
   
       bb0: {
           StorageLive(_1);
--         StorageLive(_2);
-+         nop;
+          StorageLive(_2);
           StorageLive(_3);
           StorageLive(_4);
           _9 = const _;
@@ -44,8 +43,7 @@
 +         _1 = (*_2)[1 of 2];
           StorageDead(_6);
           StorageDead(_4);
--         StorageDead(_2);
-+         nop;
+          StorageDead(_2);
           _0 = const ();
           StorageDead(_1);
           return;
diff --git a/tests/mir-opt/const_prop/transmute.unreachable_mut.GVN.32bit.diff b/tests/mir-opt/const_prop/transmute.unreachable_mut.GVN.32bit.diff
index 2dc3aa9afca..0ff31b1a981 100644
--- a/tests/mir-opt/const_prop/transmute.unreachable_mut.GVN.32bit.diff
+++ b/tests/mir-opt/const_prop/transmute.unreachable_mut.GVN.32bit.diff
@@ -13,14 +13,12 @@
   
       bb0: {
           StorageLive(_1);
--         StorageLive(_2);
+          StorageLive(_2);
 -         _2 = const 1_usize as &mut Never (Transmute);
 -         _1 = &mut (*_2);
--         StorageDead(_2);
-+         nop;
 +         _2 = const {0x1 as &mut Never};
 +         _1 = const {0x1 as &mut Never};
-+         nop;
+          StorageDead(_2);
           unreachable;
       }
   }
diff --git a/tests/mir-opt/const_prop/transmute.unreachable_mut.GVN.64bit.diff b/tests/mir-opt/const_prop/transmute.unreachable_mut.GVN.64bit.diff
index 2dc3aa9afca..0ff31b1a981 100644
--- a/tests/mir-opt/const_prop/transmute.unreachable_mut.GVN.64bit.diff
+++ b/tests/mir-opt/const_prop/transmute.unreachable_mut.GVN.64bit.diff
@@ -13,14 +13,12 @@
   
       bb0: {
           StorageLive(_1);
--         StorageLive(_2);
+          StorageLive(_2);
 -         _2 = const 1_usize as &mut Never (Transmute);
 -         _1 = &mut (*_2);
--         StorageDead(_2);
-+         nop;
 +         _2 = const {0x1 as &mut Never};
 +         _1 = const {0x1 as &mut Never};
-+         nop;
+          StorageDead(_2);
           unreachable;
       }
   }
diff --git a/tests/mir-opt/gvn.dereferences.GVN.panic-abort.diff b/tests/mir-opt/gvn.dereferences.GVN.panic-abort.diff
index a587b1e6b1d..46bf13985da 100644
--- a/tests/mir-opt/gvn.dereferences.GVN.panic-abort.diff
+++ b/tests/mir-opt/gvn.dereferences.GVN.panic-abort.diff
@@ -72,8 +72,7 @@
       bb2: {
           StorageDead(_7);
           StorageDead(_6);
--         StorageLive(_8);
-+         nop;
+          StorageLive(_8);
           _8 = &raw const (*_1);
           StorageLive(_9);
           StorageLive(_10);
@@ -93,8 +92,7 @@
       bb4: {
           StorageDead(_12);
           StorageDead(_11);
--         StorageLive(_13);
-+         nop;
+          StorageLive(_13);
           _13 = &raw mut (*_1);
           StorageLive(_14);
           StorageLive(_15);
@@ -114,8 +112,7 @@
       bb6: {
           StorageDead(_17);
           StorageDead(_16);
--         StorageLive(_18);
-+         nop;
+          StorageLive(_18);
           _18 = &(*_1);
           StorageLive(_19);
 -         StorageLive(_20);
@@ -191,12 +188,9 @@
           StorageDead(_32);
           StorageDead(_31);
           _0 = const ();
--         StorageDead(_18);
--         StorageDead(_13);
--         StorageDead(_8);
-+         nop;
-+         nop;
-+         nop;
+          StorageDead(_18);
+          StorageDead(_13);
+          StorageDead(_8);
           return;
       }
   }
diff --git a/tests/mir-opt/gvn.dereferences.GVN.panic-unwind.diff b/tests/mir-opt/gvn.dereferences.GVN.panic-unwind.diff
index 6fdda5e9988..3e731ead859 100644
--- a/tests/mir-opt/gvn.dereferences.GVN.panic-unwind.diff
+++ b/tests/mir-opt/gvn.dereferences.GVN.panic-unwind.diff
@@ -72,8 +72,7 @@
       bb2: {
           StorageDead(_7);
           StorageDead(_6);
--         StorageLive(_8);
-+         nop;
+          StorageLive(_8);
           _8 = &raw const (*_1);
           StorageLive(_9);
           StorageLive(_10);
@@ -93,8 +92,7 @@
       bb4: {
           StorageDead(_12);
           StorageDead(_11);
--         StorageLive(_13);
-+         nop;
+          StorageLive(_13);
           _13 = &raw mut (*_1);
           StorageLive(_14);
           StorageLive(_15);
@@ -114,8 +112,7 @@
       bb6: {
           StorageDead(_17);
           StorageDead(_16);
--         StorageLive(_18);
-+         nop;
+          StorageLive(_18);
           _18 = &(*_1);
           StorageLive(_19);
 -         StorageLive(_20);
@@ -191,12 +188,9 @@
           StorageDead(_32);
           StorageDead(_31);
           _0 = const ();
--         StorageDead(_18);
--         StorageDead(_13);
--         StorageDead(_8);
-+         nop;
-+         nop;
-+         nop;
+          StorageDead(_18);
+          StorageDead(_13);
+          StorageDead(_8);
           return;
       }
   }
diff --git a/tests/mir-opt/gvn.slices.GVN.panic-abort.diff b/tests/mir-opt/gvn.slices.GVN.panic-abort.diff
index ec449980312..f3f9073909e 100644
--- a/tests/mir-opt/gvn.slices.GVN.panic-abort.diff
+++ b/tests/mir-opt/gvn.slices.GVN.panic-abort.diff
@@ -194,15 +194,13 @@
 -         _23 = move _21;
 +         _23 = const core::panicking::AssertKind::Eq;
           StorageLive(_24);
--         StorageLive(_25);
+          StorageLive(_25);
 -         _25 = &(*_15);
-+         nop;
 +         _25 = &(*_9);
           _24 = &(*_25);
           StorageLive(_26);
--         StorageLive(_27);
+          StorageLive(_27);
 -         _27 = &(*_16);
-+         nop;
 +         _27 = &(*_12);
           _26 = &(*_27);
           StorageLive(_28);
@@ -293,15 +291,13 @@
 -         _49 = move _47;
 +         _49 = const core::panicking::AssertKind::Eq;
           StorageLive(_50);
--         StorageLive(_51);
+          StorageLive(_51);
 -         _51 = &(*_41);
-+         nop;
 +         _51 = &(*_35);
           _50 = &(*_51);
           StorageLive(_52);
--         StorageLive(_53);
+          StorageLive(_53);
 -         _53 = &(*_42);
-+         nop;
 +         _53 = &(*_38);
           _52 = &(*_53);
           StorageLive(_54);
diff --git a/tests/mir-opt/gvn.slices.GVN.panic-unwind.diff b/tests/mir-opt/gvn.slices.GVN.panic-unwind.diff
index 56a78ca8694..383152cce5e 100644
--- a/tests/mir-opt/gvn.slices.GVN.panic-unwind.diff
+++ b/tests/mir-opt/gvn.slices.GVN.panic-unwind.diff
@@ -194,15 +194,13 @@
 -         _23 = move _21;
 +         _23 = const core::panicking::AssertKind::Eq;
           StorageLive(_24);
--         StorageLive(_25);
+          StorageLive(_25);
 -         _25 = &(*_15);
-+         nop;
 +         _25 = &(*_9);
           _24 = &(*_25);
           StorageLive(_26);
--         StorageLive(_27);
+          StorageLive(_27);
 -         _27 = &(*_16);
-+         nop;
 +         _27 = &(*_12);
           _26 = &(*_27);
           StorageLive(_28);
@@ -293,15 +291,13 @@
 -         _49 = move _47;
 +         _49 = const core::panicking::AssertKind::Eq;
           StorageLive(_50);
--         StorageLive(_51);
+          StorageLive(_51);
 -         _51 = &(*_41);
-+         nop;
 +         _51 = &(*_35);
           _50 = &(*_51);
           StorageLive(_52);
--         StorageLive(_53);
+          StorageLive(_53);
 -         _53 = &(*_42);
-+         nop;
 +         _53 = &(*_38);
           _52 = &(*_53);
           StorageLive(_54);
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 0a747d3aef0..3ecd4650d81 100644
--- a/tests/mir-opt/gvn.subexpression_elimination.GVN.panic-abort.diff
+++ b/tests/mir-opt/gvn.subexpression_elimination.GVN.panic-abort.diff
@@ -757,8 +757,7 @@
       bb34: {
           StorageDead(_121);
           StorageDead(_120);
--         StorageLive(_126);
-+         nop;
+          StorageLive(_126);
           _126 = &_3;
           StorageLive(_127);
 -         StorageLive(_128);
@@ -799,8 +798,7 @@
       bb36: {
           StorageDead(_132);
           StorageDead(_131);
--         StorageLive(_135);
-+         nop;
+          StorageLive(_135);
           _135 = &mut _3;
           StorageLive(_136);
           StorageLive(_137);
@@ -835,8 +833,7 @@
           StorageDead(_141);
           StorageDead(_140);
           StorageLive(_144);
--         StorageLive(_145);
-+         nop;
+          StorageLive(_145);
           _145 = &raw const _3;
           StorageLive(_146);
           StorageLive(_147);
@@ -870,8 +867,7 @@
       bb40: {
           StorageDead(_151);
           StorageDead(_150);
--         StorageLive(_154);
-+         nop;
+          StorageLive(_154);
           _154 = &raw mut _3;
           StorageLive(_155);
           StorageLive(_156);
@@ -906,13 +902,10 @@
           StorageDead(_160);
           StorageDead(_159);
           _144 = const ();
--         StorageDead(_154);
--         StorageDead(_145);
-+         nop;
-+         nop;
+          StorageDead(_154);
+          StorageDead(_145);
           StorageDead(_144);
--         StorageLive(_163);
-+         nop;
+          StorageLive(_163);
           _163 = &_3;
           StorageLive(_164);
 -         StorageLive(_165);
@@ -954,12 +947,9 @@
           StorageDead(_169);
           StorageDead(_168);
           _0 = const ();
--         StorageDead(_163);
--         StorageDead(_135);
--         StorageDead(_126);
-+         nop;
-+         nop;
-+         nop;
+          StorageDead(_163);
+          StorageDead(_135);
+          StorageDead(_126);
           return;
       }
   }
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 119a4d9bbe9..bf448280b1e 100644
--- a/tests/mir-opt/gvn.subexpression_elimination.GVN.panic-unwind.diff
+++ b/tests/mir-opt/gvn.subexpression_elimination.GVN.panic-unwind.diff
@@ -757,8 +757,7 @@
       bb34: {
           StorageDead(_121);
           StorageDead(_120);
--         StorageLive(_126);
-+         nop;
+          StorageLive(_126);
           _126 = &_3;
           StorageLive(_127);
 -         StorageLive(_128);
@@ -799,8 +798,7 @@
       bb36: {
           StorageDead(_132);
           StorageDead(_131);
--         StorageLive(_135);
-+         nop;
+          StorageLive(_135);
           _135 = &mut _3;
           StorageLive(_136);
           StorageLive(_137);
@@ -835,8 +833,7 @@
           StorageDead(_141);
           StorageDead(_140);
           StorageLive(_144);
--         StorageLive(_145);
-+         nop;
+          StorageLive(_145);
           _145 = &raw const _3;
           StorageLive(_146);
           StorageLive(_147);
@@ -870,8 +867,7 @@
       bb40: {
           StorageDead(_151);
           StorageDead(_150);
--         StorageLive(_154);
-+         nop;
+          StorageLive(_154);
           _154 = &raw mut _3;
           StorageLive(_155);
           StorageLive(_156);
@@ -906,13 +902,10 @@
           StorageDead(_160);
           StorageDead(_159);
           _144 = const ();
--         StorageDead(_154);
--         StorageDead(_145);
-+         nop;
-+         nop;
+          StorageDead(_154);
+          StorageDead(_145);
           StorageDead(_144);
--         StorageLive(_163);
-+         nop;
+          StorageLive(_163);
           _163 = &_3;
           StorageLive(_164);
 -         StorageLive(_165);
@@ -954,12 +947,9 @@
           StorageDead(_169);
           StorageDead(_168);
           _0 = const ();
--         StorageDead(_163);
--         StorageDead(_135);
--         StorageDead(_126);
-+         nop;
-+         nop;
-+         nop;
+          StorageDead(_163);
+          StorageDead(_135);
+          StorageDead(_126);
           return;
       }
   }
diff --git a/tests/mir-opt/pre-codegen/slice_filter.variant_a-{closure#0}.PreCodegen.after.mir b/tests/mir-opt/pre-codegen/slice_filter.variant_a-{closure#0}.PreCodegen.after.mir
index cc009e45e7e..7370da5629c 100644
--- a/tests/mir-opt/pre-codegen/slice_filter.variant_a-{closure#0}.PreCodegen.after.mir
+++ b/tests/mir-opt/pre-codegen/slice_filter.variant_a-{closure#0}.PreCodegen.after.mir
@@ -94,6 +94,8 @@ fn variant_a::{closure#0}(_1: &mut {closure@$DIR/slice_filter.rs:8:25: 8:39}, _2
         StorageLive(_9);
         _9 = _6;
         _10 = &_9;
+        StorageLive(_11);
+        StorageLive(_12);
         _11 = _4;
         _12 = _9;
         StorageLive(_13);
@@ -103,6 +105,8 @@ fn variant_a::{closure#0}(_1: &mut {closure@$DIR/slice_filter.rs:8:25: 8:39}, _2
         _15 = Le(move _13, move _14);
         StorageDead(_14);
         StorageDead(_13);
+        StorageDead(_12);
+        StorageDead(_11);
         switchInt(move _15) -> [0: bb1, otherwise: bb2];
     }
 
@@ -124,6 +128,8 @@ fn variant_a::{closure#0}(_1: &mut {closure@$DIR/slice_filter.rs:8:25: 8:39}, _2
         StorageLive(_17);
         _17 = _5;
         _18 = &_17;
+        StorageLive(_19);
+        StorageLive(_20);
         _19 = _7;
         _20 = _17;
         StorageLive(_21);
@@ -133,6 +139,8 @@ fn variant_a::{closure#0}(_1: &mut {closure@$DIR/slice_filter.rs:8:25: 8:39}, _2
         _23 = Le(move _21, move _22);
         StorageDead(_22);
         StorageDead(_21);
+        StorageDead(_20);
+        StorageDead(_19);
         switchInt(move _23) -> [0: bb3, otherwise: bb8];
     }
 
@@ -151,6 +159,8 @@ fn variant_a::{closure#0}(_1: &mut {closure@$DIR/slice_filter.rs:8:25: 8:39}, _2
         StorageLive(_25);
         _25 = _4;
         _26 = &_25;
+        StorageLive(_27);
+        StorageLive(_28);
         _27 = _6;
         _28 = _25;
         StorageLive(_29);
@@ -160,6 +170,8 @@ fn variant_a::{closure#0}(_1: &mut {closure@$DIR/slice_filter.rs:8:25: 8:39}, _2
         _31 = Le(move _29, move _30);
         StorageDead(_30);
         StorageDead(_29);
+        StorageDead(_28);
+        StorageDead(_27);
         switchInt(move _31) -> [0: bb5, otherwise: bb6];
     }
 
@@ -181,6 +193,8 @@ fn variant_a::{closure#0}(_1: &mut {closure@$DIR/slice_filter.rs:8:25: 8:39}, _2
         StorageLive(_33);
         _33 = _7;
         _34 = &_33;
+        StorageLive(_35);
+        StorageLive(_36);
         _35 = _5;
         _36 = _33;
         StorageLive(_37);
@@ -190,6 +204,8 @@ fn variant_a::{closure#0}(_1: &mut {closure@$DIR/slice_filter.rs:8:25: 8:39}, _2
         _0 = Le(move _37, move _38);
         StorageDead(_38);
         StorageDead(_37);
+        StorageDead(_36);
+        StorageDead(_35);
         StorageDead(_33);
         StorageDead(_34);
         StorageDead(_32);
diff --git a/tests/mir-opt/pre-codegen/slice_index.slice_get_mut_usize.PreCodegen.after.panic-abort.mir b/tests/mir-opt/pre-codegen/slice_index.slice_get_mut_usize.PreCodegen.after.panic-abort.mir
index a12411a0413..e4d9060d4cf 100644
--- a/tests/mir-opt/pre-codegen/slice_index.slice_get_mut_usize.PreCodegen.after.panic-abort.mir
+++ b/tests/mir-opt/pre-codegen/slice_index.slice_get_mut_usize.PreCodegen.after.panic-abort.mir
@@ -50,6 +50,7 @@ fn slice_get_mut_usize(_1: &mut [u32], _2: usize) -> Option<&mut u32> {
     }
 
     bb0: {
+        StorageLive(_7);
         StorageLive(_4);
         StorageLive(_3);
         _3 = Len((*_1));
@@ -85,6 +86,7 @@ fn slice_get_mut_usize(_1: &mut [u32], _2: usize) -> Option<&mut u32> {
 
     bb3: {
         StorageDead(_4);
+        StorageDead(_7);
         return;
     }
 }
diff --git a/tests/mir-opt/pre-codegen/slice_index.slice_get_mut_usize.PreCodegen.after.panic-unwind.mir b/tests/mir-opt/pre-codegen/slice_index.slice_get_mut_usize.PreCodegen.after.panic-unwind.mir
index a12411a0413..e4d9060d4cf 100644
--- a/tests/mir-opt/pre-codegen/slice_index.slice_get_mut_usize.PreCodegen.after.panic-unwind.mir
+++ b/tests/mir-opt/pre-codegen/slice_index.slice_get_mut_usize.PreCodegen.after.panic-unwind.mir
@@ -50,6 +50,7 @@ fn slice_get_mut_usize(_1: &mut [u32], _2: usize) -> Option<&mut u32> {
     }
 
     bb0: {
+        StorageLive(_7);
         StorageLive(_4);
         StorageLive(_3);
         _3 = Len((*_1));
@@ -85,6 +86,7 @@ fn slice_get_mut_usize(_1: &mut [u32], _2: usize) -> Option<&mut u32> {
 
     bb3: {
         StorageDead(_4);
+        StorageDead(_7);
         return;
     }
 }