about summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--compiler/rustc_codegen_llvm/src/debuginfo/metadata.rs12
-rw-r--r--compiler/rustc_codegen_ssa/src/mir/analyze.rs17
-rw-r--r--compiler/rustc_data_structures/src/graph/dominators/mod.rs76
-rw-r--r--compiler/rustc_data_structures/src/graph/dominators/tests.rs45
-rw-r--r--compiler/rustc_index/src/bit_set.rs8
-rw-r--r--compiler/rustc_middle/src/mir/mod.rs17
-rw-r--r--compiler/rustc_mir_dataflow/src/debuginfo.rs20
-rw-r--r--compiler/rustc_mir_dataflow/src/lib.rs1
-rw-r--r--compiler/rustc_mir_transform/src/dead_store_elimination.rs22
-rw-r--r--compiler/rustc_mir_transform/src/ssa.rs94
-rw-r--r--compiler/rustc_serialize/src/collection_impls.rs279
-rw-r--r--compiler/rustc_serialize/src/lib.rs17
-rw-r--r--compiler/rustc_serialize/src/serialize.rs262
-rw-r--r--compiler/rustc_target/src/spec/mod.rs15
-rw-r--r--src/doc/rustc/src/codegen-options/index.md8
-rw-r--r--tests/codegen/debug-fndef-size.rs18
-rw-r--r--tests/incremental/hashes/for_loops.rs6
-rw-r--r--tests/incremental/hashes/loop_expressions.rs4
-rw-r--r--tests/incremental/hashes/while_loops.rs10
-rw-r--r--tests/mir-opt/dead-store-elimination/cycle.cycle.DeadStoreElimination.diff29
-rw-r--r--tests/mir-opt/dead-store-elimination/cycle.cycle.DeadStoreElimination.panic-abort.diff73
-rw-r--r--tests/mir-opt/dead-store-elimination/cycle.cycle.DeadStoreElimination.panic-unwind.diff73
-rw-r--r--tests/mir-opt/dead-store-elimination/cycle.rs37
-rw-r--r--tests/mir-opt/dest-prop/dead_stores_better.f.DestinationPropagation.after.panic-abort.mir7
-rw-r--r--tests/mir-opt/dest-prop/dead_stores_better.f.DestinationPropagation.after.panic-unwind.mir7
-rw-r--r--tests/mir-opt/dest-prop/union.main.DestinationPropagation.panic-abort.diff2
-rw-r--r--tests/mir-opt/dest-prop/union.main.DestinationPropagation.panic-unwind.diff2
-rw-r--r--tests/mir-opt/issue_101973.inner.ConstProp.panic-abort.diff1
-rw-r--r--tests/mir-opt/issue_101973.inner.ConstProp.panic-unwind.diff1
-rw-r--r--tests/mir-opt/issues/issue_59352.num_to_digit.PreCodegen.after.panic-abort.mir45
-rw-r--r--tests/mir-opt/issues/issue_59352.num_to_digit.PreCodegen.after.panic-unwind.mir45
-rw-r--r--tests/mir-opt/pre-codegen/checked_ops.step_forward.PreCodegen.after.mir45
-rw-r--r--tests/mir-opt/pre-codegen/loops.filter_mapped.PreCodegen.after.mir43
-rw-r--r--tests/mir-opt/pre-codegen/loops.int_range.PreCodegen.after.mir99
-rw-r--r--tests/mir-opt/pre-codegen/range_iter.forward_loop.PreCodegen.after.panic-abort.mir115
-rw-r--r--tests/mir-opt/pre-codegen/range_iter.forward_loop.PreCodegen.after.panic-unwind.mir115
-rw-r--r--tests/mir-opt/pre-codegen/range_iter.range_iter_next.PreCodegen.after.panic-abort.mir64
-rw-r--r--tests/mir-opt/pre-codegen/range_iter.range_iter_next.PreCodegen.after.panic-unwind.mir64
-rw-r--r--tests/mir-opt/pre-codegen/slice_filter.variant_a-{closure#0}.PreCodegen.after.mir256
-rw-r--r--tests/mir-opt/pre-codegen/slice_index.slice_get_unchecked_mut_range.PreCodegen.after.panic-abort.mir14
-rw-r--r--tests/mir-opt/pre-codegen/slice_index.slice_get_unchecked_mut_range.PreCodegen.after.panic-unwind.mir14
-rw-r--r--tests/mir-opt/pre-codegen/slice_iter.range_loop.PreCodegen.after.panic-abort.mir131
-rw-r--r--tests/mir-opt/pre-codegen/slice_iter.range_loop.PreCodegen.after.panic-unwind.mir131
-rw-r--r--tests/mir-opt/pre-codegen/slice_iter.reverse_loop.PreCodegen.after.panic-abort.mir49
-rw-r--r--tests/mir-opt/pre-codegen/slice_iter.reverse_loop.PreCodegen.after.panic-unwind.mir49
-rw-r--r--tests/ui/linkage-attr/unstable-flavor.bpf.stderr2
-rw-r--r--tests/ui/linkage-attr/unstable-flavor.ptx.stderr2
-rw-r--r--tests/ui/linkage-attr/unstable-flavor.rs8
48 files changed, 1188 insertions, 1266 deletions
diff --git a/compiler/rustc_codegen_llvm/src/debuginfo/metadata.rs b/compiler/rustc_codegen_llvm/src/debuginfo/metadata.rs
index ed938761694..11874898a5a 100644
--- a/compiler/rustc_codegen_llvm/src/debuginfo/metadata.rs
+++ b/compiler/rustc_codegen_llvm/src/debuginfo/metadata.rs
@@ -335,12 +335,20 @@ fn build_subroutine_type_di_node<'ll, 'tcx>(
 
     // This is actually a function pointer, so wrap it in pointer DI.
     let name = compute_debuginfo_type_name(cx.tcx, fn_ty, false);
+    let (size, align) = match fn_ty.kind() {
+        ty::FnDef(..) => (0, 1),
+        ty::FnPtr(..) => (
+            cx.tcx.data_layout.pointer_size.bits(),
+            cx.tcx.data_layout.pointer_align.abi.bits() as u32,
+        ),
+        _ => unreachable!(),
+    };
     let di_node = unsafe {
         llvm::LLVMRustDIBuilderCreatePointerType(
             DIB(cx),
             fn_di_node,
-            cx.tcx.data_layout.pointer_size.bits(),
-            cx.tcx.data_layout.pointer_align.abi.bits() as u32,
+            size,
+            align,
             0, // Ignore DWARF address space.
             name.as_ptr().cast(),
             name.len(),
diff --git a/compiler/rustc_codegen_ssa/src/mir/analyze.rs b/compiler/rustc_codegen_ssa/src/mir/analyze.rs
index 7fda2d5fadf..62e997e5cfa 100644
--- a/compiler/rustc_codegen_ssa/src/mir/analyze.rs
+++ b/compiler/rustc_codegen_ssa/src/mir/analyze.rs
@@ -8,7 +8,7 @@ use rustc_index::bit_set::BitSet;
 use rustc_index::{IndexSlice, IndexVec};
 use rustc_middle::mir::traversal;
 use rustc_middle::mir::visit::{MutatingUseContext, NonMutatingUseContext, PlaceContext, Visitor};
-use rustc_middle::mir::{self, Location, TerminatorKind};
+use rustc_middle::mir::{self, DefLocation, Location, TerminatorKind};
 use rustc_middle::ty::layout::{HasTyCtxt, LayoutOf};
 
 pub fn non_ssa_locals<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>>(
@@ -67,21 +67,6 @@ enum LocalKind {
     SSA(DefLocation),
 }
 
-#[derive(Copy, Clone, PartialEq, Eq)]
-enum DefLocation {
-    Argument,
-    Body(Location),
-}
-
-impl DefLocation {
-    fn dominates(self, location: Location, dominators: &Dominators<mir::BasicBlock>) -> bool {
-        match self {
-            DefLocation::Argument => true,
-            DefLocation::Body(def) => def.successor_within_block().dominates(location, dominators),
-        }
-    }
-}
-
 struct LocalAnalyzer<'mir, 'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> {
     fx: &'mir FunctionCx<'a, 'tcx, Bx>,
     dominators: &'mir Dominators<mir::BasicBlock>,
diff --git a/compiler/rustc_data_structures/src/graph/dominators/mod.rs b/compiler/rustc_data_structures/src/graph/dominators/mod.rs
index 4075481e561..9685ad24a97 100644
--- a/compiler/rustc_data_structures/src/graph/dominators/mod.rs
+++ b/compiler/rustc_data_structures/src/graph/dominators/mod.rs
@@ -26,7 +26,42 @@ rustc_index::newtype_index! {
     struct PreorderIndex {}
 }
 
-pub fn dominators<G: ControlFlowGraph>(graph: &G) -> Dominators<G::Node> {
+#[derive(Clone, Debug)]
+pub struct Dominators<Node: Idx> {
+    kind: Kind<Node>,
+}
+
+#[derive(Clone, Debug)]
+enum Kind<Node: Idx> {
+    /// A representation optimized for a small path graphs.
+    Path,
+    General(Inner<Node>),
+}
+
+pub fn dominators<G: ControlFlowGraph>(g: &G) -> Dominators<G::Node> {
+    // We often encounter MIR bodies with 1 or 2 basic blocks. Special case the dominators
+    // computation and representation for those cases.
+    if is_small_path_graph(g) {
+        Dominators { kind: Kind::Path }
+    } else {
+        Dominators { kind: Kind::General(dominators_impl(g)) }
+    }
+}
+
+fn is_small_path_graph<G: ControlFlowGraph>(g: &G) -> bool {
+    if g.start_node().index() != 0 {
+        return false;
+    }
+    if g.num_nodes() == 1 {
+        return true;
+    }
+    if g.num_nodes() == 2 {
+        return g.successors(g.start_node()).any(|n| n.index() == 1);
+    }
+    false
+}
+
+fn dominators_impl<G: ControlFlowGraph>(graph: &G) -> Inner<G::Node> {
     // compute the post order index (rank) for each node
     let mut post_order_rank = IndexVec::from_elem_n(0, graph.num_nodes());
 
@@ -245,7 +280,7 @@ pub fn dominators<G: ControlFlowGraph>(graph: &G) -> Dominators<G::Node> {
 
     let time = compute_access_time(start_node, &immediate_dominators);
 
-    Dominators { start_node, post_order_rank, immediate_dominators, time }
+    Inner { post_order_rank, immediate_dominators, time }
 }
 
 /// Evaluate the link-eval virtual forest, providing the currently minimum semi
@@ -310,8 +345,7 @@ fn compress(
 
 /// Tracks the list of dominators for each node.
 #[derive(Clone, Debug)]
-pub struct Dominators<N: Idx> {
-    start_node: N,
+struct Inner<N: Idx> {
     post_order_rank: IndexVec<N, usize>,
     // Even though we track only the immediate dominator of each node, it's
     // possible to get its full list of dominators by looking up the dominator
@@ -323,12 +357,24 @@ pub struct Dominators<N: Idx> {
 impl<Node: Idx> Dominators<Node> {
     /// Returns true if node is reachable from the start node.
     pub fn is_reachable(&self, node: Node) -> bool {
-        node == self.start_node || self.immediate_dominators[node].is_some()
+        match &self.kind {
+            Kind::Path => true,
+            Kind::General(g) => g.time[node].start != 0,
+        }
     }
 
     /// Returns the immediate dominator of node, if any.
     pub fn immediate_dominator(&self, node: Node) -> Option<Node> {
-        self.immediate_dominators[node]
+        match &self.kind {
+            Kind::Path => {
+                if 0 < node.index() {
+                    Some(Node::new(node.index() - 1))
+                } else {
+                    None
+                }
+            }
+            Kind::General(g) => g.immediate_dominators[node],
+        }
     }
 
     /// Provides an iterator over each dominator up the CFG, for the given Node.
@@ -343,7 +389,10 @@ impl<Node: Idx> Dominators<Node> {
     /// of two unrelated nodes will also be consistent, but otherwise the order has no
     /// meaning.) This method cannot be used to determine if either Node dominates the other.
     pub fn cmp_in_dominator_order(&self, lhs: Node, rhs: Node) -> Ordering {
-        self.post_order_rank[rhs].cmp(&self.post_order_rank[lhs])
+        match &self.kind {
+            Kind::Path => lhs.index().cmp(&rhs.index()),
+            Kind::General(g) => g.post_order_rank[rhs].cmp(&g.post_order_rank[lhs]),
+        }
     }
 
     /// Returns true if `a` dominates `b`.
@@ -352,10 +401,15 @@ impl<Node: Idx> Dominators<Node> {
     ///
     /// Panics if `b` is unreachable.
     pub fn dominates(&self, a: Node, b: Node) -> bool {
-        let a = self.time[a];
-        let b = self.time[b];
-        assert!(b.start != 0, "node {b:?} is not reachable");
-        a.start <= b.start && b.finish <= a.finish
+        match &self.kind {
+            Kind::Path => a.index() <= b.index(),
+            Kind::General(g) => {
+                let a = g.time[a];
+                let b = g.time[b];
+                assert!(b.start != 0, "node {b:?} is not reachable");
+                a.start <= b.start && b.finish <= a.finish
+            }
+        }
     }
 }
 
diff --git a/compiler/rustc_data_structures/src/graph/dominators/tests.rs b/compiler/rustc_data_structures/src/graph/dominators/tests.rs
index 5472bb8087e..39725ba4301 100644
--- a/compiler/rustc_data_structures/src/graph/dominators/tests.rs
+++ b/compiler/rustc_data_structures/src/graph/dominators/tests.rs
@@ -6,12 +6,11 @@ use super::super::tests::TestGraph;
 fn diamond() {
     let graph = TestGraph::new(0, &[(0, 1), (0, 2), (1, 3), (2, 3)]);
 
-    let dominators = dominators(&graph);
-    let immediate_dominators = &dominators.immediate_dominators;
-    assert_eq!(immediate_dominators[0], None);
-    assert_eq!(immediate_dominators[1], Some(0));
-    assert_eq!(immediate_dominators[2], Some(0));
-    assert_eq!(immediate_dominators[3], Some(0));
+    let d = dominators(&graph);
+    assert_eq!(d.immediate_dominator(0), None);
+    assert_eq!(d.immediate_dominator(1), Some(0));
+    assert_eq!(d.immediate_dominator(2), Some(0));
+    assert_eq!(d.immediate_dominator(3), Some(0));
 }
 
 #[test]
@@ -22,15 +21,14 @@ fn paper() {
         &[(6, 5), (6, 4), (5, 1), (4, 2), (4, 3), (1, 2), (2, 3), (3, 2), (2, 1)],
     );
 
-    let dominators = dominators(&graph);
-    let immediate_dominators = &dominators.immediate_dominators;
-    assert_eq!(immediate_dominators[0], None); // <-- note that 0 is not in graph
-    assert_eq!(immediate_dominators[1], Some(6));
-    assert_eq!(immediate_dominators[2], Some(6));
-    assert_eq!(immediate_dominators[3], Some(6));
-    assert_eq!(immediate_dominators[4], Some(6));
-    assert_eq!(immediate_dominators[5], Some(6));
-    assert_eq!(immediate_dominators[6], None);
+    let d = dominators(&graph);
+    assert_eq!(d.immediate_dominator(0), None); // <-- note that 0 is not in graph
+    assert_eq!(d.immediate_dominator(1), Some(6));
+    assert_eq!(d.immediate_dominator(2), Some(6));
+    assert_eq!(d.immediate_dominator(3), Some(6));
+    assert_eq!(d.immediate_dominator(4), Some(6));
+    assert_eq!(d.immediate_dominator(5), Some(6));
+    assert_eq!(d.immediate_dominator(6), None);
 }
 
 #[test]
@@ -47,11 +45,11 @@ fn paper_slt() {
 #[test]
 fn immediate_dominator() {
     let graph = TestGraph::new(1, &[(1, 2), (2, 3)]);
-    let dominators = dominators(&graph);
-    assert_eq!(dominators.immediate_dominator(0), None);
-    assert_eq!(dominators.immediate_dominator(1), None);
-    assert_eq!(dominators.immediate_dominator(2), Some(1));
-    assert_eq!(dominators.immediate_dominator(3), Some(2));
+    let d = dominators(&graph);
+    assert_eq!(d.immediate_dominator(0), None);
+    assert_eq!(d.immediate_dominator(1), None);
+    assert_eq!(d.immediate_dominator(2), Some(1));
+    assert_eq!(d.immediate_dominator(3), Some(2));
 }
 
 #[test]
@@ -75,8 +73,7 @@ fn transitive_dominator() {
         ],
     );
 
-    let dom_tree = dominators(&graph);
-    let immediate_dominators = &dom_tree.immediate_dominators;
-    assert_eq!(immediate_dominators[2], Some(0));
-    assert_eq!(immediate_dominators[3], Some(0)); // This used to return Some(1).
+    let d = dominators(&graph);
+    assert_eq!(d.immediate_dominator(2), Some(0));
+    assert_eq!(d.immediate_dominator(3), Some(0)); // This used to return Some(1).
 }
diff --git a/compiler/rustc_index/src/bit_set.rs b/compiler/rustc_index/src/bit_set.rs
index 12a7ecf8133..ece61ff1252 100644
--- a/compiler/rustc_index/src/bit_set.rs
+++ b/compiler/rustc_index/src/bit_set.rs
@@ -365,7 +365,7 @@ impl<T: Idx> From<GrowableBitSet<T>> for BitSet<T> {
 /// All operations that involve an element will panic if the element is equal
 /// to or greater than the domain size. All operations that involve two bitsets
 /// will panic if the bitsets have differing domain sizes.
-#[derive(Debug, PartialEq, Eq)]
+#[derive(PartialEq, Eq)]
 pub struct ChunkedBitSet<T> {
     domain_size: usize,
 
@@ -1074,6 +1074,12 @@ impl<T: Idx> fmt::Debug for BitSet<T> {
     }
 }
 
+impl<T: Idx> fmt::Debug for ChunkedBitSet<T> {
+    fn fmt(&self, w: &mut fmt::Formatter<'_>) -> fmt::Result {
+        w.debug_list().entries(self.iter()).finish()
+    }
+}
+
 impl<T: Idx> ToString for BitSet<T> {
     fn to_string(&self) -> String {
         let mut result = String::new();
diff --git a/compiler/rustc_middle/src/mir/mod.rs b/compiler/rustc_middle/src/mir/mod.rs
index 34b6250a89d..f979f736b15 100644
--- a/compiler/rustc_middle/src/mir/mod.rs
+++ b/compiler/rustc_middle/src/mir/mod.rs
@@ -1562,6 +1562,23 @@ impl Location {
     }
 }
 
+/// `DefLocation` represents the location of a definition - either an argument or an assignment
+/// within MIR body.
+#[derive(Copy, Clone, Debug, PartialEq, Eq)]
+pub enum DefLocation {
+    Argument,
+    Body(Location),
+}
+
+impl DefLocation {
+    pub fn dominates(self, location: Location, dominators: &Dominators<BasicBlock>) -> bool {
+        match self {
+            DefLocation::Argument => true,
+            DefLocation::Body(def) => def.successor_within_block().dominates(location, dominators),
+        }
+    }
+}
+
 // Some nodes are used a lot. Make sure they don't unintentionally get bigger.
 #[cfg(all(target_arch = "x86_64", target_pointer_width = "64"))]
 mod size_asserts {
diff --git a/compiler/rustc_mir_dataflow/src/debuginfo.rs b/compiler/rustc_mir_dataflow/src/debuginfo.rs
new file mode 100644
index 00000000000..fd5e8cf2955
--- /dev/null
+++ b/compiler/rustc_mir_dataflow/src/debuginfo.rs
@@ -0,0 +1,20 @@
+use rustc_index::bit_set::BitSet;
+use rustc_middle::mir::visit::*;
+use rustc_middle::mir::*;
+
+/// Return the set of locals that appear in debuginfo.
+pub fn debuginfo_locals(body: &Body<'_>) -> BitSet<Local> {
+    let mut visitor = DebuginfoLocals(BitSet::new_empty(body.local_decls.len()));
+    for debuginfo in body.var_debug_info.iter() {
+        visitor.visit_var_debug_info(debuginfo);
+    }
+    visitor.0
+}
+
+struct DebuginfoLocals(BitSet<Local>);
+
+impl Visitor<'_> for DebuginfoLocals {
+    fn visit_local(&mut self, local: Local, _: PlaceContext, _: Location) {
+        self.0.insert(local);
+    }
+}
diff --git a/compiler/rustc_mir_dataflow/src/lib.rs b/compiler/rustc_mir_dataflow/src/lib.rs
index 0cdbee19d2c..ecf46715cd0 100644
--- a/compiler/rustc_mir_dataflow/src/lib.rs
+++ b/compiler/rustc_mir_dataflow/src/lib.rs
@@ -35,6 +35,7 @@ pub use self::framework::{
 
 use self::move_paths::MoveData;
 
+pub mod debuginfo;
 pub mod drop_flag_effects;
 pub mod elaborate_drops;
 mod errors;
diff --git a/compiler/rustc_mir_transform/src/dead_store_elimination.rs b/compiler/rustc_mir_transform/src/dead_store_elimination.rs
index ef14105041b..3d74ef7e327 100644
--- a/compiler/rustc_mir_transform/src/dead_store_elimination.rs
+++ b/compiler/rustc_mir_transform/src/dead_store_elimination.rs
@@ -13,10 +13,10 @@
 //!
 
 use crate::util::is_within_packed;
-use rustc_index::bit_set::BitSet;
 use rustc_middle::mir::visit::Visitor;
 use rustc_middle::mir::*;
 use rustc_middle::ty::TyCtxt;
+use rustc_mir_dataflow::debuginfo::debuginfo_locals;
 use rustc_mir_dataflow::impls::{
     borrowed_locals, LivenessTransferFunction, MaybeTransitiveLiveLocals,
 };
@@ -26,8 +26,15 @@ use rustc_mir_dataflow::Analysis;
 ///
 /// The `borrowed` set must be a `BitSet` of all the locals that are ever borrowed in this body. It
 /// can be generated via the [`borrowed_locals`] function.
-pub fn eliminate<'tcx>(tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>, borrowed: &BitSet<Local>) {
-    let mut live = MaybeTransitiveLiveLocals::new(borrowed)
+pub fn eliminate<'tcx>(tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) {
+    let borrowed_locals = borrowed_locals(body);
+
+    // If the user requests complete debuginfo, mark the locals that appear in it as live, so
+    // we don't remove assignements to them.
+    let mut always_live = debuginfo_locals(body);
+    always_live.union(&borrowed_locals);
+
+    let mut live = MaybeTransitiveLiveLocals::new(&always_live)
         .into_engine(tcx, body)
         .iterate_to_fixpoint()
         .into_results_cursor(body);
@@ -48,7 +55,9 @@ pub fn eliminate<'tcx>(tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>, borrowed: &BitS
             for (index, arg) in args.iter().enumerate().rev() {
                 if let Operand::Copy(place) = *arg
                     && !place.is_indirect()
-                    && !borrowed.contains(place.local)
+                    // Do not skip the transformation if the local is in debuginfo, as we do
+                    // not really lose any information for this purpose.
+                    && !borrowed_locals.contains(place.local)
                     && !state.contains(place.local)
                     // If `place` is a projection of a disaligned field in a packed ADT,
                     // the move may be codegened as a pointer to that field.
@@ -75,7 +84,7 @@ pub fn eliminate<'tcx>(tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>, borrowed: &BitS
                 StatementKind::Assign(box (place, _))
                 | StatementKind::SetDiscriminant { place: box place, .. }
                 | StatementKind::Deinit(box place) => {
-                    if !place.is_indirect() && !borrowed.contains(place.local) {
+                    if !place.is_indirect() && !always_live.contains(place.local) {
                         live.seek_before_primary_effect(loc);
                         if !live.get().contains(place.local) {
                             patch.push(loc);
@@ -126,7 +135,6 @@ impl<'tcx> MirPass<'tcx> for DeadStoreElimination {
     }
 
     fn run_pass(&self, tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) {
-        let borrowed = borrowed_locals(body);
-        eliminate(tcx, body, &borrowed);
+        eliminate(tcx, body);
     }
 }
diff --git a/compiler/rustc_mir_transform/src/ssa.rs b/compiler/rustc_mir_transform/src/ssa.rs
index af9514ed6bb..fad58930e3a 100644
--- a/compiler/rustc_mir_transform/src/ssa.rs
+++ b/compiler/rustc_mir_transform/src/ssa.rs
@@ -15,7 +15,7 @@ use rustc_middle::mir::*;
 
 pub struct SsaLocals {
     /// Assignments to each local. This defines whether the local is SSA.
-    assignments: IndexVec<Local, Set1<LocationExtended>>,
+    assignments: IndexVec<Local, Set1<DefLocation>>,
     /// We visit the body in reverse postorder, to ensure each local is assigned before it is used.
     /// We remember the order in which we saw the assignments to compute the SSA values in a single
     /// pass.
@@ -27,55 +27,18 @@ pub struct SsaLocals {
     direct_uses: IndexVec<Local, u32>,
 }
 
-/// We often encounter MIR bodies with 1 or 2 basic blocks. In those cases, it's unnecessary to
-/// actually compute dominators, we can just compare block indices because bb0 is always the first
-/// block, and in any body all other blocks are always dominated by bb0.
-struct SmallDominators<'a> {
-    inner: Option<&'a Dominators<BasicBlock>>,
-}
-
-impl SmallDominators<'_> {
-    fn dominates(&self, first: Location, second: Location) -> bool {
-        if first.block == second.block {
-            first.statement_index <= second.statement_index
-        } else if let Some(inner) = &self.inner {
-            inner.dominates(first.block, second.block)
-        } else {
-            first.block < second.block
-        }
-    }
-
-    fn check_dominates(&mut self, set: &mut Set1<LocationExtended>, loc: Location) {
-        let assign_dominates = match *set {
-            Set1::Empty | Set1::Many => false,
-            Set1::One(LocationExtended::Arg) => true,
-            Set1::One(LocationExtended::Plain(assign)) => {
-                self.dominates(assign.successor_within_block(), loc)
-            }
-        };
-        // We are visiting a use that is not dominated by an assignment.
-        // Either there is a cycle involved, or we are reading for uninitialized local.
-        // Bail out.
-        if !assign_dominates {
-            *set = Set1::Many;
-        }
-    }
-}
-
 impl SsaLocals {
     pub fn new<'tcx>(body: &Body<'tcx>) -> SsaLocals {
         let assignment_order = Vec::with_capacity(body.local_decls.len());
 
         let assignments = IndexVec::from_elem(Set1::Empty, &body.local_decls);
-        let dominators =
-            if body.basic_blocks.len() > 2 { Some(body.basic_blocks.dominators()) } else { None };
-        let dominators = SmallDominators { inner: dominators };
+        let dominators = body.basic_blocks.dominators();
 
         let direct_uses = IndexVec::from_elem(0, &body.local_decls);
         let mut visitor = SsaVisitor { assignments, assignment_order, dominators, direct_uses };
 
         for local in body.args_iter() {
-            visitor.assignments[local] = Set1::One(LocationExtended::Arg);
+            visitor.assignments[local] = Set1::One(DefLocation::Argument);
         }
 
         // For SSA assignments, a RPO visit will see the assignment before it sees any use.
@@ -131,14 +94,7 @@ impl SsaLocals {
         location: Location,
     ) -> bool {
         match self.assignments[local] {
-            Set1::One(LocationExtended::Arg) => true,
-            Set1::One(LocationExtended::Plain(ass)) => {
-                if ass.block == location.block {
-                    ass.statement_index < location.statement_index
-                } else {
-                    dominators.dominates(ass.block, location.block)
-                }
-            }
+            Set1::One(def) => def.dominates(location, dominators),
             _ => false,
         }
     }
@@ -148,7 +104,7 @@ impl SsaLocals {
         body: &'a Body<'tcx>,
     ) -> impl Iterator<Item = (Local, &'a Rvalue<'tcx>, Location)> + 'a {
         self.assignment_order.iter().filter_map(|&local| {
-            if let Set1::One(LocationExtended::Plain(loc)) = self.assignments[local] {
+            if let Set1::One(DefLocation::Body(loc)) = self.assignments[local] {
                 // `loc` must point to a direct assignment to `local`.
                 let Either::Left(stmt) = body.stmt_at(loc) else { bug!() };
                 let Some((target, rvalue)) = stmt.kind.as_assign() else { bug!() };
@@ -166,7 +122,7 @@ impl SsaLocals {
         mut f: impl FnMut(Local, &mut Rvalue<'tcx>, Location),
     ) {
         for &local in &self.assignment_order {
-            if let Set1::One(LocationExtended::Plain(loc)) = self.assignments[local] {
+            if let Set1::One(DefLocation::Body(loc)) = self.assignments[local] {
                 // `loc` must point to a direct assignment to `local`.
                 let bbs = basic_blocks.as_mut_preserves_cfg();
                 let bb = &mut bbs[loc.block];
@@ -224,19 +180,29 @@ impl SsaLocals {
     }
 }
 
-#[derive(Copy, Clone, Debug, PartialEq, Eq)]
-enum LocationExtended {
-    Plain(Location),
-    Arg,
-}
-
 struct SsaVisitor<'a> {
-    dominators: SmallDominators<'a>,
-    assignments: IndexVec<Local, Set1<LocationExtended>>,
+    dominators: &'a Dominators<BasicBlock>,
+    assignments: IndexVec<Local, Set1<DefLocation>>,
     assignment_order: Vec<Local>,
     direct_uses: IndexVec<Local, u32>,
 }
 
+impl SsaVisitor<'_> {
+    fn check_dominates(&mut self, local: Local, loc: Location) {
+        let set = &mut self.assignments[local];
+        let assign_dominates = match *set {
+            Set1::Empty | Set1::Many => false,
+            Set1::One(def) => def.dominates(loc, self.dominators),
+        };
+        // We are visiting a use that is not dominated by an assignment.
+        // Either there is a cycle involved, or we are reading for uninitialized local.
+        // Bail out.
+        if !assign_dominates {
+            *set = Set1::Many;
+        }
+    }
+}
+
 impl<'tcx> Visitor<'tcx> for SsaVisitor<'_> {
     fn visit_local(&mut self, local: Local, ctxt: PlaceContext, loc: Location) {
         match ctxt {
@@ -254,7 +220,7 @@ impl<'tcx> Visitor<'tcx> for SsaVisitor<'_> {
                 self.assignments[local] = Set1::Many;
             }
             PlaceContext::NonMutatingUse(_) => {
-                self.dominators.check_dominates(&mut self.assignments[local], loc);
+                self.check_dominates(local, loc);
                 self.direct_uses[local] += 1;
             }
             PlaceContext::NonUse(_) => {}
@@ -269,7 +235,7 @@ impl<'tcx> Visitor<'tcx> for SsaVisitor<'_> {
                 let new_ctxt = PlaceContext::NonMutatingUse(NonMutatingUseContext::Copy);
 
                 self.visit_projection(place.as_ref(), new_ctxt, loc);
-                self.dominators.check_dominates(&mut self.assignments[place.local], loc);
+                self.check_dominates(place.local, loc);
             }
             return;
         } else {
@@ -280,7 +246,7 @@ impl<'tcx> Visitor<'tcx> for SsaVisitor<'_> {
 
     fn visit_assign(&mut self, place: &Place<'tcx>, rvalue: &Rvalue<'tcx>, loc: Location) {
         if let Some(local) = place.as_local() {
-            self.assignments[local].insert(LocationExtended::Plain(loc));
+            self.assignments[local].insert(DefLocation::Body(loc));
             if let Set1::One(_) = self.assignments[local] {
                 // Only record if SSA-like, to avoid growing the vector needlessly.
                 self.assignment_order.push(local);
@@ -356,7 +322,7 @@ fn compute_copy_classes(ssa: &mut SsaLocals, body: &Body<'_>) {
 #[derive(Debug)]
 pub(crate) struct StorageLiveLocals {
     /// Set of "StorageLive" statements for each local.
-    storage_live: IndexVec<Local, Set1<LocationExtended>>,
+    storage_live: IndexVec<Local, Set1<DefLocation>>,
 }
 
 impl StorageLiveLocals {
@@ -366,13 +332,13 @@ impl StorageLiveLocals {
     ) -> StorageLiveLocals {
         let mut storage_live = IndexVec::from_elem(Set1::Empty, &body.local_decls);
         for local in always_storage_live_locals.iter() {
-            storage_live[local] = Set1::One(LocationExtended::Arg);
+            storage_live[local] = Set1::One(DefLocation::Argument);
         }
         for (block, bbdata) in body.basic_blocks.iter_enumerated() {
             for (statement_index, statement) in bbdata.statements.iter().enumerate() {
                 if let StatementKind::StorageLive(local) = statement.kind {
                     storage_live[local]
-                        .insert(LocationExtended::Plain(Location { block, statement_index }));
+                        .insert(DefLocation::Body(Location { block, statement_index }));
                 }
             }
         }
diff --git a/compiler/rustc_serialize/src/collection_impls.rs b/compiler/rustc_serialize/src/collection_impls.rs
deleted file mode 100644
index 8f8c504117c..00000000000
--- a/compiler/rustc_serialize/src/collection_impls.rs
+++ /dev/null
@@ -1,279 +0,0 @@
-//! Implementations of serialization for structures found in liballoc
-
-use crate::{Decodable, Decoder, Encodable, Encoder};
-use smallvec::{Array, SmallVec};
-use std::collections::{BTreeMap, BTreeSet, HashMap, HashSet, LinkedList, VecDeque};
-use std::hash::{BuildHasher, Hash};
-use std::rc::Rc;
-use std::sync::Arc;
-use thin_vec::ThinVec;
-
-impl<S: Encoder, A: Array<Item: Encodable<S>>> Encodable<S> for SmallVec<A> {
-    fn encode(&self, s: &mut S) {
-        let slice: &[A::Item] = self;
-        slice.encode(s);
-    }
-}
-
-impl<D: Decoder, A: Array<Item: Decodable<D>>> Decodable<D> for SmallVec<A> {
-    fn decode(d: &mut D) -> SmallVec<A> {
-        let len = d.read_usize();
-        (0..len).map(|_| Decodable::decode(d)).collect()
-    }
-}
-
-impl<S: Encoder, T: Encodable<S>> Encodable<S> for ThinVec<T> {
-    fn encode(&self, s: &mut S) {
-        self.as_slice().encode(s);
-    }
-}
-
-impl<D: Decoder, T: Decodable<D>> Decodable<D> for ThinVec<T> {
-    fn decode(d: &mut D) -> ThinVec<T> {
-        let len = d.read_usize();
-        (0..len).map(|_| Decodable::decode(d)).collect()
-    }
-}
-
-impl<S: Encoder, T: Encodable<S>> Encodable<S> for LinkedList<T> {
-    fn encode(&self, s: &mut S) {
-        s.emit_usize(self.len());
-        for e in self.iter() {
-            e.encode(s);
-        }
-    }
-}
-
-impl<D: Decoder, T: Decodable<D>> Decodable<D> for LinkedList<T> {
-    fn decode(d: &mut D) -> LinkedList<T> {
-        let len = d.read_usize();
-        (0..len).map(|_| Decodable::decode(d)).collect()
-    }
-}
-
-impl<S: Encoder, T: Encodable<S>> Encodable<S> for VecDeque<T> {
-    fn encode(&self, s: &mut S) {
-        s.emit_usize(self.len());
-        for e in self.iter() {
-            e.encode(s);
-        }
-    }
-}
-
-impl<D: Decoder, T: Decodable<D>> Decodable<D> for VecDeque<T> {
-    fn decode(d: &mut D) -> VecDeque<T> {
-        let len = d.read_usize();
-        (0..len).map(|_| Decodable::decode(d)).collect()
-    }
-}
-
-impl<S: Encoder, K, V> Encodable<S> for BTreeMap<K, V>
-where
-    K: Encodable<S> + PartialEq + Ord,
-    V: Encodable<S>,
-{
-    fn encode(&self, e: &mut S) {
-        e.emit_usize(self.len());
-        for (key, val) in self.iter() {
-            key.encode(e);
-            val.encode(e);
-        }
-    }
-}
-
-impl<D: Decoder, K, V> Decodable<D> for BTreeMap<K, V>
-where
-    K: Decodable<D> + PartialEq + Ord,
-    V: Decodable<D>,
-{
-    fn decode(d: &mut D) -> BTreeMap<K, V> {
-        let len = d.read_usize();
-        let mut map = BTreeMap::new();
-        for _ in 0..len {
-            let key = Decodable::decode(d);
-            let val = Decodable::decode(d);
-            map.insert(key, val);
-        }
-        map
-    }
-}
-
-impl<S: Encoder, T> Encodable<S> for BTreeSet<T>
-where
-    T: Encodable<S> + PartialEq + Ord,
-{
-    fn encode(&self, s: &mut S) {
-        s.emit_usize(self.len());
-        for e in self.iter() {
-            e.encode(s);
-        }
-    }
-}
-
-impl<D: Decoder, T> Decodable<D> for BTreeSet<T>
-where
-    T: Decodable<D> + PartialEq + Ord,
-{
-    fn decode(d: &mut D) -> BTreeSet<T> {
-        let len = d.read_usize();
-        let mut set = BTreeSet::new();
-        for _ in 0..len {
-            set.insert(Decodable::decode(d));
-        }
-        set
-    }
-}
-
-impl<E: Encoder, K, V, S> Encodable<E> for HashMap<K, V, S>
-where
-    K: Encodable<E> + Eq,
-    V: Encodable<E>,
-    S: BuildHasher,
-{
-    fn encode(&self, e: &mut E) {
-        e.emit_usize(self.len());
-        for (key, val) in self.iter() {
-            key.encode(e);
-            val.encode(e);
-        }
-    }
-}
-
-impl<D: Decoder, K, V, S> Decodable<D> for HashMap<K, V, S>
-where
-    K: Decodable<D> + Hash + Eq,
-    V: Decodable<D>,
-    S: BuildHasher + Default,
-{
-    fn decode(d: &mut D) -> HashMap<K, V, S> {
-        let len = d.read_usize();
-        let state = Default::default();
-        let mut map = HashMap::with_capacity_and_hasher(len, state);
-        for _ in 0..len {
-            let key = Decodable::decode(d);
-            let val = Decodable::decode(d);
-            map.insert(key, val);
-        }
-        map
-    }
-}
-
-impl<E: Encoder, T, S> Encodable<E> for HashSet<T, S>
-where
-    T: Encodable<E> + Eq,
-    S: BuildHasher,
-{
-    fn encode(&self, s: &mut E) {
-        s.emit_usize(self.len());
-        for e in self.iter() {
-            e.encode(s);
-        }
-    }
-}
-
-impl<D: Decoder, T, S> Decodable<D> for HashSet<T, S>
-where
-    T: Decodable<D> + Hash + Eq,
-    S: BuildHasher + Default,
-{
-    fn decode(d: &mut D) -> HashSet<T, S> {
-        let len = d.read_usize();
-        let state = Default::default();
-        let mut set = HashSet::with_capacity_and_hasher(len, state);
-        for _ in 0..len {
-            set.insert(Decodable::decode(d));
-        }
-        set
-    }
-}
-
-impl<E: Encoder, K, V, S> Encodable<E> for indexmap::IndexMap<K, V, S>
-where
-    K: Encodable<E> + Hash + Eq,
-    V: Encodable<E>,
-    S: BuildHasher,
-{
-    fn encode(&self, e: &mut E) {
-        e.emit_usize(self.len());
-        for (key, val) in self.iter() {
-            key.encode(e);
-            val.encode(e);
-        }
-    }
-}
-
-impl<D: Decoder, K, V, S> Decodable<D> for indexmap::IndexMap<K, V, S>
-where
-    K: Decodable<D> + Hash + Eq,
-    V: Decodable<D>,
-    S: BuildHasher + Default,
-{
-    fn decode(d: &mut D) -> indexmap::IndexMap<K, V, S> {
-        let len = d.read_usize();
-        let state = Default::default();
-        let mut map = indexmap::IndexMap::with_capacity_and_hasher(len, state);
-        for _ in 0..len {
-            let key = Decodable::decode(d);
-            let val = Decodable::decode(d);
-            map.insert(key, val);
-        }
-        map
-    }
-}
-
-impl<E: Encoder, T, S> Encodable<E> for indexmap::IndexSet<T, S>
-where
-    T: Encodable<E> + Hash + Eq,
-    S: BuildHasher,
-{
-    fn encode(&self, s: &mut E) {
-        s.emit_usize(self.len());
-        for e in self.iter() {
-            e.encode(s);
-        }
-    }
-}
-
-impl<D: Decoder, T, S> Decodable<D> for indexmap::IndexSet<T, S>
-where
-    T: Decodable<D> + Hash + Eq,
-    S: BuildHasher + Default,
-{
-    fn decode(d: &mut D) -> indexmap::IndexSet<T, S> {
-        let len = d.read_usize();
-        let state = Default::default();
-        let mut set = indexmap::IndexSet::with_capacity_and_hasher(len, state);
-        for _ in 0..len {
-            set.insert(Decodable::decode(d));
-        }
-        set
-    }
-}
-
-impl<E: Encoder, T: Encodable<E>> Encodable<E> for Rc<[T]> {
-    fn encode(&self, s: &mut E) {
-        let slice: &[T] = self;
-        slice.encode(s);
-    }
-}
-
-impl<D: Decoder, T: Decodable<D>> Decodable<D> for Rc<[T]> {
-    fn decode(d: &mut D) -> Rc<[T]> {
-        let vec: Vec<T> = Decodable::decode(d);
-        vec.into()
-    }
-}
-
-impl<E: Encoder, T: Encodable<E>> Encodable<E> for Arc<[T]> {
-    fn encode(&self, s: &mut E) {
-        let slice: &[T] = self;
-        slice.encode(s);
-    }
-}
-
-impl<D: Decoder, T: Decodable<D>> Decodable<D> for Arc<[T]> {
-    fn decode(d: &mut D) -> Arc<[T]> {
-        let vec: Vec<T> = Decodable::decode(d);
-        vec.into()
-    }
-}
diff --git a/compiler/rustc_serialize/src/lib.rs b/compiler/rustc_serialize/src/lib.rs
index dd40b3cf028..5360aa9ea6a 100644
--- a/compiler/rustc_serialize/src/lib.rs
+++ b/compiler/rustc_serialize/src/lib.rs
@@ -1,25 +1,19 @@
 //! Support code for encoding and decoding types.
 
-/*
-Core encoding and decoding interfaces.
-*/
-
 #![doc(
     html_root_url = "https://doc.rust-lang.org/nightly/nightly-rustc/",
     html_playground_url = "https://play.rust-lang.org/",
     test(attr(allow(unused_variables), deny(warnings)))
 )]
-#![feature(never_type)]
+#![feature(allocator_api)]
 #![feature(associated_type_bounds)]
-#![feature(min_specialization)]
+#![feature(const_option)]
 #![feature(core_intrinsics)]
-#![feature(maybe_uninit_slice)]
-#![feature(new_uninit)]
-#![feature(allocator_api)]
+#![feature(inline_const)]
+#![feature(min_specialization)]
+#![feature(never_type)]
 #![feature(ptr_sub_ptr)]
 #![feature(slice_first_last_chunk)]
-#![feature(inline_const)]
-#![feature(const_option)]
 #![cfg_attr(test, feature(test))]
 #![allow(rustc::internal)]
 #![deny(rustc::untranslatable_diagnostic)]
@@ -27,7 +21,6 @@ Core encoding and decoding interfaces.
 
 pub use self::serialize::{Decodable, Decoder, Encodable, Encoder};
 
-mod collection_impls;
 mod serialize;
 
 pub mod leb128;
diff --git a/compiler/rustc_serialize/src/serialize.rs b/compiler/rustc_serialize/src/serialize.rs
index 06166cabc18..63bd3457eb9 100644
--- a/compiler/rustc_serialize/src/serialize.rs
+++ b/compiler/rustc_serialize/src/serialize.rs
@@ -1,12 +1,15 @@
 //! Support code for encoding and decoding types.
 
-use std::alloc::Allocator;
+use smallvec::{Array, SmallVec};
 use std::borrow::Cow;
 use std::cell::{Cell, RefCell};
+use std::collections::{BTreeMap, BTreeSet, HashMap, HashSet, VecDeque};
+use std::hash::{BuildHasher, Hash};
 use std::marker::PhantomData;
 use std::path;
 use std::rc::Rc;
 use std::sync::Arc;
+use thin_vec::ThinVec;
 
 /// A byte that [cannot occur in UTF8 sequences][utf8]. Used to mark the end of a string.
 /// This way we can skip validation and still be relatively sure that deserialization
@@ -273,9 +276,9 @@ impl<D: Decoder, T> Decodable<D> for PhantomData<T> {
     }
 }
 
-impl<D: Decoder, A: Allocator + Default, T: Decodable<D>> Decodable<D> for Box<[T], A> {
-    fn decode(d: &mut D) -> Box<[T], A> {
-        let v: Vec<T, A> = Decodable::decode(d);
+impl<D: Decoder, T: Decodable<D>> Decodable<D> for Box<[T]> {
+    fn decode(d: &mut D) -> Box<[T]> {
+        let v: Vec<T> = Decodable::decode(d);
         v.into_boxed_slice()
     }
 }
@@ -303,33 +306,20 @@ impl<S: Encoder, T: Encodable<S>> Encodable<S> for [T] {
 
 impl<S: Encoder, T: Encodable<S>> Encodable<S> for Vec<T> {
     fn encode(&self, s: &mut S) {
-        let slice: &[T] = self;
-        slice.encode(s);
+        self.as_slice().encode(s);
     }
 }
 
-impl<D: Decoder, T: Decodable<D>, A: Allocator + Default> Decodable<D> for Vec<T, A> {
-    default fn decode(d: &mut D) -> Vec<T, A> {
+impl<D: Decoder, T: Decodable<D>> Decodable<D> for Vec<T> {
+    default fn decode(d: &mut D) -> Vec<T> {
         let len = d.read_usize();
-        let allocator = A::default();
-        // SAFETY: we set the capacity in advance, only write elements, and
-        // only set the length at the end once the writing has succeeded.
-        let mut vec = Vec::with_capacity_in(len, allocator);
-        unsafe {
-            let ptr: *mut T = vec.as_mut_ptr();
-            for i in 0..len {
-                std::ptr::write(ptr.add(i), Decodable::decode(d));
-            }
-            vec.set_len(len);
-        }
-        vec
+        (0..len).map(|_| Decodable::decode(d)).collect()
     }
 }
 
 impl<S: Encoder, T: Encodable<S>, const N: usize> Encodable<S> for [T; N] {
     fn encode(&self, s: &mut S) {
-        let slice: &[T] = self;
-        slice.encode(s);
+        self.as_slice().encode(s);
     }
 }
 
@@ -497,15 +487,233 @@ impl<D: Decoder, T: Decodable<D>> Decodable<D> for Arc<T> {
     }
 }
 
-impl<S: Encoder, T: ?Sized + Encodable<S>, A: Allocator + Default> Encodable<S> for Box<T, A> {
+impl<S: Encoder, T: ?Sized + Encodable<S>> Encodable<S> for Box<T> {
     fn encode(&self, s: &mut S) {
         (**self).encode(s)
     }
 }
 
-impl<D: Decoder, A: Allocator + Default, T: Decodable<D>> Decodable<D> for Box<T, A> {
-    fn decode(d: &mut D) -> Box<T, A> {
-        let allocator = A::default();
-        Box::new_in(Decodable::decode(d), allocator)
+impl<D: Decoder, T: Decodable<D>> Decodable<D> for Box<T> {
+    fn decode(d: &mut D) -> Box<T> {
+        Box::new(Decodable::decode(d))
+    }
+}
+
+impl<S: Encoder, A: Array<Item: Encodable<S>>> Encodable<S> for SmallVec<A> {
+    fn encode(&self, s: &mut S) {
+        self.as_slice().encode(s);
+    }
+}
+
+impl<D: Decoder, A: Array<Item: Decodable<D>>> Decodable<D> for SmallVec<A> {
+    fn decode(d: &mut D) -> SmallVec<A> {
+        let len = d.read_usize();
+        (0..len).map(|_| Decodable::decode(d)).collect()
+    }
+}
+
+impl<S: Encoder, T: Encodable<S>> Encodable<S> for ThinVec<T> {
+    fn encode(&self, s: &mut S) {
+        self.as_slice().encode(s);
+    }
+}
+
+impl<D: Decoder, T: Decodable<D>> Decodable<D> for ThinVec<T> {
+    fn decode(d: &mut D) -> ThinVec<T> {
+        let len = d.read_usize();
+        (0..len).map(|_| Decodable::decode(d)).collect()
+    }
+}
+
+impl<S: Encoder, T: Encodable<S>> Encodable<S> for VecDeque<T> {
+    fn encode(&self, s: &mut S) {
+        s.emit_usize(self.len());
+        for e in self.iter() {
+            e.encode(s);
+        }
+    }
+}
+
+impl<D: Decoder, T: Decodable<D>> Decodable<D> for VecDeque<T> {
+    fn decode(d: &mut D) -> VecDeque<T> {
+        let len = d.read_usize();
+        (0..len).map(|_| Decodable::decode(d)).collect()
+    }
+}
+
+impl<S: Encoder, K, V> Encodable<S> for BTreeMap<K, V>
+where
+    K: Encodable<S> + PartialEq + Ord,
+    V: Encodable<S>,
+{
+    fn encode(&self, e: &mut S) {
+        e.emit_usize(self.len());
+        for (key, val) in self.iter() {
+            key.encode(e);
+            val.encode(e);
+        }
+    }
+}
+
+impl<D: Decoder, K, V> Decodable<D> for BTreeMap<K, V>
+where
+    K: Decodable<D> + PartialEq + Ord,
+    V: Decodable<D>,
+{
+    fn decode(d: &mut D) -> BTreeMap<K, V> {
+        let len = d.read_usize();
+        (0..len).map(|_| (Decodable::decode(d), Decodable::decode(d))).collect()
+    }
+}
+
+impl<S: Encoder, T> Encodable<S> for BTreeSet<T>
+where
+    T: Encodable<S> + PartialEq + Ord,
+{
+    fn encode(&self, s: &mut S) {
+        s.emit_usize(self.len());
+        for e in self.iter() {
+            e.encode(s);
+        }
+    }
+}
+
+impl<D: Decoder, T> Decodable<D> for BTreeSet<T>
+where
+    T: Decodable<D> + PartialEq + Ord,
+{
+    fn decode(d: &mut D) -> BTreeSet<T> {
+        let len = d.read_usize();
+        (0..len).map(|_| Decodable::decode(d)).collect()
+    }
+}
+
+impl<E: Encoder, K, V, S> Encodable<E> for HashMap<K, V, S>
+where
+    K: Encodable<E> + Eq,
+    V: Encodable<E>,
+    S: BuildHasher,
+{
+    fn encode(&self, e: &mut E) {
+        e.emit_usize(self.len());
+        for (key, val) in self.iter() {
+            key.encode(e);
+            val.encode(e);
+        }
+    }
+}
+
+impl<D: Decoder, K, V, S> Decodable<D> for HashMap<K, V, S>
+where
+    K: Decodable<D> + Hash + Eq,
+    V: Decodable<D>,
+    S: BuildHasher + Default,
+{
+    fn decode(d: &mut D) -> HashMap<K, V, S> {
+        let len = d.read_usize();
+        (0..len).map(|_| (Decodable::decode(d), Decodable::decode(d))).collect()
+    }
+}
+
+impl<E: Encoder, T, S> Encodable<E> for HashSet<T, S>
+where
+    T: Encodable<E> + Eq,
+    S: BuildHasher,
+{
+    fn encode(&self, s: &mut E) {
+        s.emit_usize(self.len());
+        for e in self.iter() {
+            e.encode(s);
+        }
+    }
+}
+
+impl<D: Decoder, T, S> Decodable<D> for HashSet<T, S>
+where
+    T: Decodable<D> + Hash + Eq,
+    S: BuildHasher + Default,
+{
+    fn decode(d: &mut D) -> HashSet<T, S> {
+        let len = d.read_usize();
+        (0..len).map(|_| Decodable::decode(d)).collect()
+    }
+}
+
+impl<E: Encoder, K, V, S> Encodable<E> for indexmap::IndexMap<K, V, S>
+where
+    K: Encodable<E> + Hash + Eq,
+    V: Encodable<E>,
+    S: BuildHasher,
+{
+    fn encode(&self, e: &mut E) {
+        e.emit_usize(self.len());
+        for (key, val) in self.iter() {
+            key.encode(e);
+            val.encode(e);
+        }
+    }
+}
+
+impl<D: Decoder, K, V, S> Decodable<D> for indexmap::IndexMap<K, V, S>
+where
+    K: Decodable<D> + Hash + Eq,
+    V: Decodable<D>,
+    S: BuildHasher + Default,
+{
+    fn decode(d: &mut D) -> indexmap::IndexMap<K, V, S> {
+        let len = d.read_usize();
+        (0..len).map(|_| (Decodable::decode(d), Decodable::decode(d))).collect()
+    }
+}
+
+impl<E: Encoder, T, S> Encodable<E> for indexmap::IndexSet<T, S>
+where
+    T: Encodable<E> + Hash + Eq,
+    S: BuildHasher,
+{
+    fn encode(&self, s: &mut E) {
+        s.emit_usize(self.len());
+        for e in self.iter() {
+            e.encode(s);
+        }
+    }
+}
+
+impl<D: Decoder, T, S> Decodable<D> for indexmap::IndexSet<T, S>
+where
+    T: Decodable<D> + Hash + Eq,
+    S: BuildHasher + Default,
+{
+    fn decode(d: &mut D) -> indexmap::IndexSet<T, S> {
+        let len = d.read_usize();
+        (0..len).map(|_| Decodable::decode(d)).collect()
+    }
+}
+
+impl<E: Encoder, T: Encodable<E>> Encodable<E> for Rc<[T]> {
+    fn encode(&self, s: &mut E) {
+        let slice: &[T] = self;
+        slice.encode(s);
+    }
+}
+
+impl<D: Decoder, T: Decodable<D>> Decodable<D> for Rc<[T]> {
+    fn decode(d: &mut D) -> Rc<[T]> {
+        let vec: Vec<T> = Decodable::decode(d);
+        vec.into()
+    }
+}
+
+impl<E: Encoder, T: Encodable<E>> Encodable<E> for Arc<[T]> {
+    fn encode(&self, s: &mut E) {
+        let slice: &[T] = self;
+        slice.encode(s);
+    }
+}
+
+impl<D: Decoder, T: Decodable<D>> Decodable<D> for Arc<[T]> {
+    fn decode(d: &mut D) -> Arc<[T]> {
+        let vec: Vec<T> = Decodable::decode(d);
+        vec.into()
     }
 }
diff --git a/compiler/rustc_target/src/spec/mod.rs b/compiler/rustc_target/src/spec/mod.rs
index 1bcb1f35315..d4774386e2e 100644
--- a/compiler/rustc_target/src/spec/mod.rs
+++ b/compiler/rustc_target/src/spec/mod.rs
@@ -184,8 +184,6 @@ pub enum LinkerFlavorCli {
     Ld,
     Lld(LldFlavor),
     Em,
-    BpfLinker,
-    PtxLinker,
 }
 
 impl LinkerFlavorCli {
@@ -199,9 +197,7 @@ impl LinkerFlavorCli {
             | LinkerFlavorCli::Msvc(Lld::Yes)
             | LinkerFlavorCli::EmCc
             | LinkerFlavorCli::Bpf
-            | LinkerFlavorCli::Ptx
-            | LinkerFlavorCli::BpfLinker
-            | LinkerFlavorCli::PtxLinker => true,
+            | LinkerFlavorCli::Ptx => true,
             LinkerFlavorCli::Gcc
             | LinkerFlavorCli::Ld
             | LinkerFlavorCli::Lld(..)
@@ -279,8 +275,6 @@ impl LinkerFlavor {
             LinkerFlavorCli::Lld(LldFlavor::Wasm) => LinkerFlavor::WasmLld(Cc::No),
             LinkerFlavorCli::Lld(LldFlavor::Link) => LinkerFlavor::Msvc(Lld::Yes),
             LinkerFlavorCli::Em => LinkerFlavor::EmCc,
-            LinkerFlavorCli::BpfLinker => LinkerFlavor::Bpf,
-            LinkerFlavorCli::PtxLinker => LinkerFlavor::Ptx,
         }
     }
 
@@ -299,8 +293,8 @@ impl LinkerFlavor {
             LinkerFlavor::Msvc(Lld::Yes) => LinkerFlavorCli::Lld(LldFlavor::Link),
             LinkerFlavor::Msvc(..) => LinkerFlavorCli::Msvc(Lld::No),
             LinkerFlavor::EmCc => LinkerFlavorCli::Em,
-            LinkerFlavor::Bpf => LinkerFlavorCli::BpfLinker,
-            LinkerFlavor::Ptx => LinkerFlavorCli::PtxLinker,
+            LinkerFlavor::Bpf => LinkerFlavorCli::Bpf,
+            LinkerFlavor::Ptx => LinkerFlavorCli::Ptx,
         }
     }
 
@@ -320,7 +314,6 @@ impl LinkerFlavor {
             LinkerFlavorCli::Ld => (Some(Cc::No), Some(Lld::No)),
             LinkerFlavorCli::Lld(_) => (Some(Cc::No), Some(Lld::Yes)),
             LinkerFlavorCli::Em => (Some(Cc::Yes), Some(Lld::Yes)),
-            LinkerFlavorCli::BpfLinker | LinkerFlavorCli::PtxLinker => (None, None),
         }
     }
 
@@ -519,8 +512,6 @@ linker_flavor_cli_impls! {
     (LinkerFlavorCli::Lld(LldFlavor::Link)) "lld-link"
     (LinkerFlavorCli::Lld(LldFlavor::Wasm)) "wasm-ld"
     (LinkerFlavorCli::Em) "em"
-    (LinkerFlavorCli::BpfLinker) "bpf-linker"
-    (LinkerFlavorCli::PtxLinker) "ptx-linker"
 }
 
 impl ToJson for LinkerFlavorCli {
diff --git a/src/doc/rustc/src/codegen-options/index.md b/src/doc/rustc/src/codegen-options/index.md
index d72543c7e02..cfbe1e09cde 100644
--- a/src/doc/rustc/src/codegen-options/index.md
+++ b/src/doc/rustc/src/codegen-options/index.md
@@ -249,11 +249,9 @@ flavor. Valid options are:
 * `gcc`: use the `cc` executable, which is typically gcc or clang on many systems.
 * `ld`: use the `ld` executable.
 * `msvc`: use the `link.exe` executable from Microsoft Visual Studio MSVC.
-* `ptx-linker`: use
-  [`rust-ptx-linker`](https://github.com/denzp/rust-ptx-linker) for Nvidia
-  NVPTX GPGPU support.
-* `bpf-linker`: use
-  [`bpf-linker`](https://github.com/alessandrod/bpf-linker) for eBPF support.
+* `ptx`: use [`rust-ptx-linker`](https://github.com/denzp/rust-ptx-linker)
+  for Nvidia NVPTX GPGPU support.
+* `bpf`: use [`bpf-linker`](https://github.com/alessandrod/bpf-linker) for eBPF support.
 * `wasm-ld`: use the [`wasm-ld`](https://lld.llvm.org/WebAssembly.html)
   executable, a port of LLVM `lld` for WebAssembly.
 * `ld64.lld`: use the LLVM `lld` executable with the [`-flavor darwin`
diff --git a/tests/codegen/debug-fndef-size.rs b/tests/codegen/debug-fndef-size.rs
new file mode 100644
index 00000000000..80eb35fa32a
--- /dev/null
+++ b/tests/codegen/debug-fndef-size.rs
@@ -0,0 +1,18 @@
+// Verify that `i32::cmp` FnDef type is declared with size 0 and align 1 in LLVM debuginfo.
+// compile-flags: -O -g -Cno-prepopulate-passes
+// ignore-msvc the types are mangled differently
+
+use std::cmp::Ordering;
+
+fn foo<F: FnOnce(&i32, &i32) -> Ordering>(v1: i32, v2: i32, compare: F) -> Ordering {
+    compare(&v1, &v2)
+}
+
+pub fn main() {
+    foo(0, 1, i32::cmp);
+}
+
+// CHECK: %compare.dbg.spill = alloca {}, align 1
+// CHECK: call void @llvm.dbg.declare(metadata ptr %compare.dbg.spill, metadata ![[VAR:.*]], metadata !DIExpression()), !dbg !{{.*}}
+// CHECK: ![[TYPE:.*]] = !DIDerivedType(tag: DW_TAG_pointer_type, name: "fn(&i32, &i32) -> core::cmp::Ordering", baseType: !{{.*}}, align: 1, dwarfAddressSpace: {{.*}})
+// CHECK: ![[VAR]] = !DILocalVariable(name: "compare", scope: !{{.*}}, file: !{{.*}}, line: {{.*}}, type: ![[TYPE]], align: 1)
diff --git a/tests/incremental/hashes/for_loops.rs b/tests/incremental/hashes/for_loops.rs
index 193e792c843..98c762e4097 100644
--- a/tests/incremental/hashes/for_loops.rs
+++ b/tests/incremental/hashes/for_loops.rs
@@ -28,9 +28,9 @@ pub fn change_loop_body() {
 }
 
 #[cfg(not(any(cfail1,cfail4)))]
-#[rustc_clean(cfg="cfail2", except="hir_owner_nodes")]
+#[rustc_clean(cfg="cfail2", except="hir_owner_nodes, optimized_mir")]
 #[rustc_clean(cfg="cfail3")]
-#[rustc_clean(cfg="cfail5", except="hir_owner_nodes")]
+#[rustc_clean(cfg="cfail5", except="hir_owner_nodes, optimized_mir")]
 #[rustc_clean(cfg="cfail6")]
 pub fn change_loop_body() {
     let mut _x = 0;
@@ -180,7 +180,7 @@ pub fn add_loop_label_to_break() {
 #[cfg(not(any(cfail1,cfail4)))]
 #[rustc_clean(cfg="cfail2", except="hir_owner_nodes")]
 #[rustc_clean(cfg="cfail3")]
-#[rustc_clean(cfg="cfail5", except="hir_owner_nodes")]
+#[rustc_clean(cfg="cfail5", except="hir_owner_nodes, optimized_mir")]
 #[rustc_clean(cfg="cfail6")]
 pub fn add_loop_label_to_break() {
     let mut _x = 0;
diff --git a/tests/incremental/hashes/loop_expressions.rs b/tests/incremental/hashes/loop_expressions.rs
index 87b86479d07..13e37bd59f8 100644
--- a/tests/incremental/hashes/loop_expressions.rs
+++ b/tests/incremental/hashes/loop_expressions.rs
@@ -28,9 +28,9 @@ pub fn change_loop_body() {
 }
 
 #[cfg(not(any(cfail1,cfail4)))]
-#[rustc_clean(cfg="cfail2", except="hir_owner_nodes")]
+#[rustc_clean(cfg="cfail2", except="hir_owner_nodes, optimized_mir")]
 #[rustc_clean(cfg="cfail3")]
-#[rustc_clean(cfg="cfail5", except="hir_owner_nodes")]
+#[rustc_clean(cfg="cfail5", except="hir_owner_nodes, optimized_mir")]
 #[rustc_clean(cfg="cfail6")]
 pub fn change_loop_body() {
     let mut _x = 0;
diff --git a/tests/incremental/hashes/while_loops.rs b/tests/incremental/hashes/while_loops.rs
index c1cc0b62bc2..077d76fdd43 100644
--- a/tests/incremental/hashes/while_loops.rs
+++ b/tests/incremental/hashes/while_loops.rs
@@ -28,9 +28,9 @@ pub fn change_loop_body() {
 }
 
 #[cfg(not(any(cfail1,cfail4)))]
-#[rustc_clean(cfg="cfail2", except="hir_owner_nodes")]
+#[rustc_clean(cfg="cfail2", except="hir_owner_nodes, optimized_mir")]
 #[rustc_clean(cfg="cfail3")]
-#[rustc_clean(cfg="cfail5", except="hir_owner_nodes")]
+#[rustc_clean(cfg="cfail5", except="hir_owner_nodes, optimized_mir")]
 #[rustc_clean(cfg="cfail6")]
 pub fn change_loop_body() {
     let mut _x = 0;
@@ -53,9 +53,9 @@ pub fn change_loop_condition() {
 }
 
 #[cfg(not(any(cfail1,cfail4)))]
-#[rustc_clean(cfg="cfail2", except="hir_owner_nodes")]
+#[rustc_clean(cfg="cfail2", except="hir_owner_nodes, optimized_mir")]
 #[rustc_clean(cfg="cfail3")]
-#[rustc_clean(cfg="cfail5", except="hir_owner_nodes")]
+#[rustc_clean(cfg="cfail5", except="hir_owner_nodes, optimized_mir")]
 #[rustc_clean(cfg="cfail6")]
 pub fn change_loop_condition() {
     let mut _x = 0;
@@ -211,7 +211,7 @@ pub fn change_continue_label() {
 #[cfg(not(any(cfail1,cfail4)))]
 #[rustc_clean(cfg="cfail2", except="hir_owner_nodes")]
 #[rustc_clean(cfg="cfail3")]
-#[rustc_clean(cfg="cfail5", except="hir_owner_nodes,optimized_mir")]
+#[rustc_clean(cfg="cfail5", except="hir_owner_nodes")]
 #[rustc_clean(cfg="cfail6")]
 pub fn change_continue_label() {
     let mut _x = 0;
diff --git a/tests/mir-opt/dead-store-elimination/cycle.cycle.DeadStoreElimination.diff b/tests/mir-opt/dead-store-elimination/cycle.cycle.DeadStoreElimination.diff
new file mode 100644
index 00000000000..cf73358dc52
--- /dev/null
+++ b/tests/mir-opt/dead-store-elimination/cycle.cycle.DeadStoreElimination.diff
@@ -0,0 +1,29 @@
+- // MIR for `cycle` before DeadStoreElimination
++ // MIR for `cycle` after DeadStoreElimination
+  
+  fn cycle(_1: i32, _2: i32, _3: i32) -> () {
+      let mut _0: ();
+      let mut _4: bool;
+-     let mut _5: i32;
+  
+      bb0: {
+          _4 = cond() -> [return: bb1, unwind continue];
+      }
+  
+      bb1: {
+          switchInt(_4) -> [1: bb2, otherwise: bb3];
+      }
+  
+      bb2: {
+-         _5 = _3;
+-         _3 = _2;
+-         _2 = _1;
+-         _1 = _5;
+          _4 = cond() -> [return: bb1, unwind continue];
+      }
+  
+      bb3: {
+          return;
+      }
+  }
+  
diff --git a/tests/mir-opt/dead-store-elimination/cycle.cycle.DeadStoreElimination.panic-abort.diff b/tests/mir-opt/dead-store-elimination/cycle.cycle.DeadStoreElimination.panic-abort.diff
deleted file mode 100644
index 6221d478041..00000000000
--- a/tests/mir-opt/dead-store-elimination/cycle.cycle.DeadStoreElimination.panic-abort.diff
+++ /dev/null
@@ -1,73 +0,0 @@
-- // MIR for `cycle` before DeadStoreElimination
-+ // MIR for `cycle` after DeadStoreElimination
-  
-  fn cycle(_1: i32, _2: i32, _3: i32) -> () {
-      debug x => _1;
-      debug y => _2;
-      debug z => _3;
-      let mut _0: ();
--     let mut _4: ();
--     let mut _5: bool;
--     let _6: i32;
--     let mut _7: i32;
--     let mut _8: i32;
--     let mut _9: i32;
--     let mut _10: !;
--     let _11: ();
--     let mut _12: !;
-+     let mut _4: bool;
-+     let _5: i32;
-      scope 1 {
--         debug temp => _6;
-+         debug temp => _5;
-      }
-  
-      bb0: {
-          goto -> bb1;
-      }
-  
-      bb1: {
--         StorageLive(_5);
--         _5 = cond() -> [return: bb2, unwind unreachable];
-+         StorageLive(_4);
-+         _4 = cond() -> [return: bb2, unwind unreachable];
-      }
-  
-      bb2: {
--         switchInt(move _5) -> [0: bb4, otherwise: bb3];
-+         switchInt(move _4) -> [0: bb4, otherwise: bb3];
-      }
-  
-      bb3: {
--         StorageLive(_6);
--         _6 = _3;
--         StorageLive(_7);
--         _7 = _2;
--         _3 = move _7;
--         StorageDead(_7);
--         StorageLive(_8);
--         _8 = _1;
--         _2 = move _8;
--         StorageDead(_8);
--         StorageLive(_9);
--         _9 = _6;
--         _1 = move _9;
--         StorageDead(_9);
--         _4 = const ();
--         StorageDead(_6);
-+         StorageLive(_5);
-          StorageDead(_5);
-+         StorageDead(_4);
-          goto -> bb1;
-      }
-  
-      bb4: {
--         StorageLive(_11);
-          _0 = const ();
--         StorageDead(_11);
--         StorageDead(_5);
-+         StorageDead(_4);
-          return;
-      }
-  }
-  
diff --git a/tests/mir-opt/dead-store-elimination/cycle.cycle.DeadStoreElimination.panic-unwind.diff b/tests/mir-opt/dead-store-elimination/cycle.cycle.DeadStoreElimination.panic-unwind.diff
deleted file mode 100644
index 4b922e05e10..00000000000
--- a/tests/mir-opt/dead-store-elimination/cycle.cycle.DeadStoreElimination.panic-unwind.diff
+++ /dev/null
@@ -1,73 +0,0 @@
-- // MIR for `cycle` before DeadStoreElimination
-+ // MIR for `cycle` after DeadStoreElimination
-  
-  fn cycle(_1: i32, _2: i32, _3: i32) -> () {
-      debug x => _1;
-      debug y => _2;
-      debug z => _3;
-      let mut _0: ();
--     let mut _4: ();
--     let mut _5: bool;
--     let _6: i32;
--     let mut _7: i32;
--     let mut _8: i32;
--     let mut _9: i32;
--     let mut _10: !;
--     let _11: ();
--     let mut _12: !;
-+     let mut _4: bool;
-+     let _5: i32;
-      scope 1 {
--         debug temp => _6;
-+         debug temp => _5;
-      }
-  
-      bb0: {
-          goto -> bb1;
-      }
-  
-      bb1: {
--         StorageLive(_5);
--         _5 = cond() -> [return: bb2, unwind continue];
-+         StorageLive(_4);
-+         _4 = cond() -> [return: bb2, unwind continue];
-      }
-  
-      bb2: {
--         switchInt(move _5) -> [0: bb4, otherwise: bb3];
-+         switchInt(move _4) -> [0: bb4, otherwise: bb3];
-      }
-  
-      bb3: {
--         StorageLive(_6);
--         _6 = _3;
--         StorageLive(_7);
--         _7 = _2;
--         _3 = move _7;
--         StorageDead(_7);
--         StorageLive(_8);
--         _8 = _1;
--         _2 = move _8;
--         StorageDead(_8);
--         StorageLive(_9);
--         _9 = _6;
--         _1 = move _9;
--         StorageDead(_9);
--         _4 = const ();
--         StorageDead(_6);
-+         StorageLive(_5);
-          StorageDead(_5);
-+         StorageDead(_4);
-          goto -> bb1;
-      }
-  
-      bb4: {
--         StorageLive(_11);
-          _0 = const ();
--         StorageDead(_11);
--         StorageDead(_5);
-+         StorageDead(_4);
-          return;
-      }
-  }
-  
diff --git a/tests/mir-opt/dead-store-elimination/cycle.rs b/tests/mir-opt/dead-store-elimination/cycle.rs
index cd34fe96e8c..e3def2f65da 100644
--- a/tests/mir-opt/dead-store-elimination/cycle.rs
+++ b/tests/mir-opt/dead-store-elimination/cycle.rs
@@ -1,21 +1,40 @@
-// EMIT_MIR_FOR_EACH_PANIC_STRATEGY
+// This example is interesting because the non-transitive version of `MaybeLiveLocals` would
+// report that *all* of these stores are live.
+//
+// needs-unwind
 // unit-test: DeadStoreElimination
 
+#![feature(core_intrinsics, custom_mir)]
+use std::intrinsics::mir::*;
+
 #[inline(never)]
 fn cond() -> bool {
     false
 }
 
 // EMIT_MIR cycle.cycle.DeadStoreElimination.diff
+#[custom_mir(dialect = "runtime", phase = "post-cleanup")]
 fn cycle(mut x: i32, mut y: i32, mut z: i32) {
-    // This example is interesting because the non-transitive version of `MaybeLiveLocals` would
-    // report that *all* of these stores are live.
-    while cond() {
-        let temp = z;
-        z = y;
-        y = x;
-        x = temp;
-    }
+    // We use custom MIR to avoid generating debuginfo, that would force to preserve writes.
+    mir!(
+        let condition: bool;
+        {
+            Call(condition = cond(), bb1)
+        }
+        bb1 = {
+            match condition { true => bb2, _ => ret }
+        }
+        bb2 = {
+            let temp = z;
+            z = y;
+            y = x;
+            x = temp;
+            Call(condition = cond(), bb1)
+        }
+        ret = {
+            Return()
+        }
+    )
 }
 
 fn main() {
diff --git a/tests/mir-opt/dest-prop/dead_stores_better.f.DestinationPropagation.after.panic-abort.mir b/tests/mir-opt/dest-prop/dead_stores_better.f.DestinationPropagation.after.panic-abort.mir
index a3ec0901075..eb160fc194a 100644
--- a/tests/mir-opt/dest-prop/dead_stores_better.f.DestinationPropagation.after.panic-abort.mir
+++ b/tests/mir-opt/dest-prop/dead_stores_better.f.DestinationPropagation.after.panic-abort.mir
@@ -7,15 +7,16 @@ fn f(_1: usize) -> usize {
     let mut _3: usize;
     let mut _4: usize;
     scope 1 {
-        debug b => _1;
+        debug b => _3;
     }
 
     bb0: {
         nop;
+        _3 = _1;
+        _1 = const 5_usize;
         nop;
         nop;
-        nop;
-        nop;
+        _1 = move _3;
         nop;
         nop;
         nop;
diff --git a/tests/mir-opt/dest-prop/dead_stores_better.f.DestinationPropagation.after.panic-unwind.mir b/tests/mir-opt/dest-prop/dead_stores_better.f.DestinationPropagation.after.panic-unwind.mir
index 185feb4b418..9147de2ec47 100644
--- a/tests/mir-opt/dest-prop/dead_stores_better.f.DestinationPropagation.after.panic-unwind.mir
+++ b/tests/mir-opt/dest-prop/dead_stores_better.f.DestinationPropagation.after.panic-unwind.mir
@@ -7,15 +7,16 @@ fn f(_1: usize) -> usize {
     let mut _3: usize;
     let mut _4: usize;
     scope 1 {
-        debug b => _1;
+        debug b => _3;
     }
 
     bb0: {
         nop;
+        _3 = _1;
+        _1 = const 5_usize;
         nop;
         nop;
-        nop;
-        nop;
+        _1 = move _3;
         nop;
         nop;
         nop;
diff --git a/tests/mir-opt/dest-prop/union.main.DestinationPropagation.panic-abort.diff b/tests/mir-opt/dest-prop/union.main.DestinationPropagation.panic-abort.diff
index 459a9c442b3..d5e58265dcc 100644
--- a/tests/mir-opt/dest-prop/union.main.DestinationPropagation.panic-abort.diff
+++ b/tests/mir-opt/dest-prop/union.main.DestinationPropagation.panic-abort.diff
@@ -22,8 +22,10 @@
       }
   
       bb1: {
+          _1 = Un { us: move _2 };
           StorageDead(_2);
           StorageLive(_3);
+          _3 = (_1.0: u32);
           StorageDead(_3);
           StorageDead(_1);
           return;
diff --git a/tests/mir-opt/dest-prop/union.main.DestinationPropagation.panic-unwind.diff b/tests/mir-opt/dest-prop/union.main.DestinationPropagation.panic-unwind.diff
index d2eef90582d..5eaaeba135b 100644
--- a/tests/mir-opt/dest-prop/union.main.DestinationPropagation.panic-unwind.diff
+++ b/tests/mir-opt/dest-prop/union.main.DestinationPropagation.panic-unwind.diff
@@ -22,8 +22,10 @@
       }
   
       bb1: {
+          _1 = Un { us: move _2 };
           StorageDead(_2);
           StorageLive(_3);
+          _3 = (_1.0: u32);
           StorageDead(_3);
           StorageDead(_1);
           return;
diff --git a/tests/mir-opt/issue_101973.inner.ConstProp.panic-abort.diff b/tests/mir-opt/issue_101973.inner.ConstProp.panic-abort.diff
index ce490e894f0..3748d148380 100644
--- a/tests/mir-opt/issue_101973.inner.ConstProp.panic-abort.diff
+++ b/tests/mir-opt/issue_101973.inner.ConstProp.panic-abort.diff
@@ -33,6 +33,7 @@
           StorageLive(_2);
           StorageLive(_3);
           StorageLive(_4);
+          _4 = const 0_u32;
           StorageLive(_15);
           StorageLive(_14);
           _14 = Shr(_1, const 0_i32);
diff --git a/tests/mir-opt/issue_101973.inner.ConstProp.panic-unwind.diff b/tests/mir-opt/issue_101973.inner.ConstProp.panic-unwind.diff
index 254557b9947..9dab4233c56 100644
--- a/tests/mir-opt/issue_101973.inner.ConstProp.panic-unwind.diff
+++ b/tests/mir-opt/issue_101973.inner.ConstProp.panic-unwind.diff
@@ -33,6 +33,7 @@
           StorageLive(_2);
           StorageLive(_3);
           StorageLive(_4);
+          _4 = const 0_u32;
           StorageLive(_15);
           StorageLive(_14);
           _14 = Shr(_1, const 0_i32);
diff --git a/tests/mir-opt/issues/issue_59352.num_to_digit.PreCodegen.after.panic-abort.mir b/tests/mir-opt/issues/issue_59352.num_to_digit.PreCodegen.after.panic-abort.mir
index 55ccf6a8b45..5d25c655700 100644
--- a/tests/mir-opt/issues/issue_59352.num_to_digit.PreCodegen.after.panic-abort.mir
+++ b/tests/mir-opt/issues/issue_59352.num_to_digit.PreCodegen.after.panic-abort.mir
@@ -3,60 +3,61 @@
 fn num_to_digit(_1: char) -> u32 {
     debug num => _1;
     let mut _0: u32;
-    let mut _4: std::option::Option<u32>;
+    let mut _5: std::option::Option<u32>;
     scope 1 (inlined char::methods::<impl char>::is_digit) {
         debug self => _1;
         debug radix => const 8_u32;
         let _2: std::option::Option<u32>;
-        let mut _7: &std::option::Option<u32>;
+        let mut _3: &std::option::Option<u32>;
         scope 2 (inlined Option::<u32>::is_some) {
-            debug self => _7;
-            let mut _3: isize;
+            debug self => _3;
+            let mut _4: isize;
         }
     }
     scope 3 (inlined #[track_caller] Option::<u32>::unwrap) {
-        debug self => _4;
-        let mut _5: isize;
-        let mut _6: !;
+        debug self => _5;
+        let mut _6: isize;
+        let mut _7: !;
         scope 4 {
             debug val => _0;
         }
     }
 
     bb0: {
-        StorageLive(_7);
+        StorageLive(_3);
         StorageLive(_2);
         _2 = char::methods::<impl char>::to_digit(_1, const 8_u32) -> [return: bb1, unwind unreachable];
     }
 
     bb1: {
-        StorageLive(_3);
-        _3 = discriminant(_2);
-        StorageDead(_7);
+        _3 = &_2;
+        StorageLive(_4);
+        _4 = discriminant(_2);
+        StorageDead(_3);
         StorageDead(_2);
-        switchInt(move _3) -> [1: bb2, otherwise: bb7];
+        switchInt(move _4) -> [1: bb2, otherwise: bb7];
     }
 
     bb2: {
-        StorageDead(_3);
-        StorageLive(_4);
-        _4 = char::methods::<impl char>::to_digit(move _1, const 8_u32) -> [return: bb3, unwind unreachable];
+        StorageDead(_4);
+        StorageLive(_5);
+        _5 = char::methods::<impl char>::to_digit(move _1, const 8_u32) -> [return: bb3, unwind unreachable];
     }
 
     bb3: {
-        StorageLive(_5);
-        _5 = discriminant(_4);
-        switchInt(move _5) -> [0: bb4, 1: bb5, otherwise: bb6];
+        StorageLive(_6);
+        _6 = discriminant(_5);
+        switchInt(move _6) -> [0: bb4, 1: bb5, otherwise: bb6];
     }
 
     bb4: {
-        _6 = core::panicking::panic(const "called `Option::unwrap()` on a `None` value") -> unwind unreachable;
+        _7 = core::panicking::panic(const "called `Option::unwrap()` on a `None` value") -> unwind unreachable;
     }
 
     bb5: {
-        _0 = move ((_4 as Some).0: u32);
+        _0 = move ((_5 as Some).0: u32);
+        StorageDead(_6);
         StorageDead(_5);
-        StorageDead(_4);
         goto -> bb8;
     }
 
@@ -65,7 +66,7 @@ fn num_to_digit(_1: char) -> u32 {
     }
 
     bb7: {
-        StorageDead(_3);
+        StorageDead(_4);
         _0 = const 0_u32;
         goto -> bb8;
     }
diff --git a/tests/mir-opt/issues/issue_59352.num_to_digit.PreCodegen.after.panic-unwind.mir b/tests/mir-opt/issues/issue_59352.num_to_digit.PreCodegen.after.panic-unwind.mir
index cb70a83e7f8..4677c0108e3 100644
--- a/tests/mir-opt/issues/issue_59352.num_to_digit.PreCodegen.after.panic-unwind.mir
+++ b/tests/mir-opt/issues/issue_59352.num_to_digit.PreCodegen.after.panic-unwind.mir
@@ -3,60 +3,61 @@
 fn num_to_digit(_1: char) -> u32 {
     debug num => _1;
     let mut _0: u32;
-    let mut _4: std::option::Option<u32>;
+    let mut _5: std::option::Option<u32>;
     scope 1 (inlined char::methods::<impl char>::is_digit) {
         debug self => _1;
         debug radix => const 8_u32;
         let _2: std::option::Option<u32>;
-        let mut _7: &std::option::Option<u32>;
+        let mut _3: &std::option::Option<u32>;
         scope 2 (inlined Option::<u32>::is_some) {
-            debug self => _7;
-            let mut _3: isize;
+            debug self => _3;
+            let mut _4: isize;
         }
     }
     scope 3 (inlined #[track_caller] Option::<u32>::unwrap) {
-        debug self => _4;
-        let mut _5: isize;
-        let mut _6: !;
+        debug self => _5;
+        let mut _6: isize;
+        let mut _7: !;
         scope 4 {
             debug val => _0;
         }
     }
 
     bb0: {
-        StorageLive(_7);
+        StorageLive(_3);
         StorageLive(_2);
         _2 = char::methods::<impl char>::to_digit(_1, const 8_u32) -> [return: bb1, unwind continue];
     }
 
     bb1: {
-        StorageLive(_3);
-        _3 = discriminant(_2);
-        StorageDead(_7);
+        _3 = &_2;
+        StorageLive(_4);
+        _4 = discriminant(_2);
+        StorageDead(_3);
         StorageDead(_2);
-        switchInt(move _3) -> [1: bb2, otherwise: bb7];
+        switchInt(move _4) -> [1: bb2, otherwise: bb7];
     }
 
     bb2: {
-        StorageDead(_3);
-        StorageLive(_4);
-        _4 = char::methods::<impl char>::to_digit(move _1, const 8_u32) -> [return: bb3, unwind continue];
+        StorageDead(_4);
+        StorageLive(_5);
+        _5 = char::methods::<impl char>::to_digit(move _1, const 8_u32) -> [return: bb3, unwind continue];
     }
 
     bb3: {
-        StorageLive(_5);
-        _5 = discriminant(_4);
-        switchInt(move _5) -> [0: bb4, 1: bb5, otherwise: bb6];
+        StorageLive(_6);
+        _6 = discriminant(_5);
+        switchInt(move _6) -> [0: bb4, 1: bb5, otherwise: bb6];
     }
 
     bb4: {
-        _6 = core::panicking::panic(const "called `Option::unwrap()` on a `None` value") -> unwind continue;
+        _7 = core::panicking::panic(const "called `Option::unwrap()` on a `None` value") -> unwind continue;
     }
 
     bb5: {
-        _0 = move ((_4 as Some).0: u32);
+        _0 = move ((_5 as Some).0: u32);
+        StorageDead(_6);
         StorageDead(_5);
-        StorageDead(_4);
         goto -> bb8;
     }
 
@@ -65,7 +66,7 @@ fn num_to_digit(_1: char) -> u32 {
     }
 
     bb7: {
-        StorageDead(_3);
+        StorageDead(_4);
         _0 = const 0_u32;
         goto -> bb8;
     }
diff --git a/tests/mir-opt/pre-codegen/checked_ops.step_forward.PreCodegen.after.mir b/tests/mir-opt/pre-codegen/checked_ops.step_forward.PreCodegen.after.mir
index e3c81061a46..cf7feef0051 100644
--- a/tests/mir-opt/pre-codegen/checked_ops.step_forward.PreCodegen.after.mir
+++ b/tests/mir-opt/pre-codegen/checked_ops.step_forward.PreCodegen.after.mir
@@ -8,61 +8,62 @@ fn step_forward(_1: u32, _2: usize) -> u32 {
         debug start => _1;
         debug n => _2;
         let _3: std::option::Option<u32>;
-        let mut _6: bool;
-        let mut _7: u32;
-        let mut _8: &std::option::Option<u32>;
+        let mut _4: &std::option::Option<u32>;
+        let mut _7: bool;
+        let mut _8: u32;
         scope 2 {
         }
         scope 3 (inlined Option::<u32>::is_none) {
-            debug self => _8;
-            let mut _5: bool;
+            debug self => _4;
+            let mut _6: bool;
             scope 4 (inlined Option::<u32>::is_some) {
-                debug self => _8;
-                let mut _4: isize;
+                debug self => _4;
+                let mut _5: isize;
             }
         }
         scope 5 (inlined core::num::<impl u32>::wrapping_add) {
             debug self => _1;
-            debug rhs => _7;
+            debug rhs => _8;
         }
     }
 
     bb0: {
-        StorageLive(_6);
-        StorageLive(_8);
+        StorageLive(_7);
+        StorageLive(_4);
         StorageLive(_3);
         _3 = <u32 as Step>::forward_checked(_1, _2) -> [return: bb1, unwind continue];
     }
 
     bb1: {
+        _4 = &_3;
+        StorageLive(_6);
         StorageLive(_5);
-        StorageLive(_4);
-        _4 = discriminant(_3);
-        _5 = Eq(_4, const 1_isize);
-        StorageDead(_4);
-        _6 = Not(move _5);
+        _5 = discriminant(_3);
+        _6 = Eq(_5, const 1_isize);
         StorageDead(_5);
-        switchInt(move _6) -> [0: bb2, otherwise: bb3];
+        _7 = Not(move _6);
+        StorageDead(_6);
+        switchInt(move _7) -> [0: bb2, otherwise: bb3];
     }
 
     bb2: {
         StorageDead(_3);
-        StorageDead(_8);
+        StorageDead(_4);
         goto -> bb4;
     }
 
     bb3: {
         StorageDead(_3);
-        StorageDead(_8);
+        StorageDead(_4);
         assert(!const true, "attempt to compute `{} + {}`, which would overflow", const _, const 1_u32) -> [success: bb4, unwind continue];
     }
 
     bb4: {
-        StorageDead(_6);
-        StorageLive(_7);
-        _7 = _2 as u32 (IntToInt);
-        _0 = Add(_1, _7);
         StorageDead(_7);
+        StorageLive(_8);
+        _8 = _2 as u32 (IntToInt);
+        _0 = Add(_1, _8);
+        StorageDead(_8);
         return;
     }
 }
diff --git a/tests/mir-opt/pre-codegen/loops.filter_mapped.PreCodegen.after.mir b/tests/mir-opt/pre-codegen/loops.filter_mapped.PreCodegen.after.mir
index 4db829a5ec3..2fbe5088268 100644
--- a/tests/mir-opt/pre-codegen/loops.filter_mapped.PreCodegen.after.mir
+++ b/tests/mir-opt/pre-codegen/loops.filter_mapped.PreCodegen.after.mir
@@ -7,20 +7,20 @@ fn filter_mapped(_1: impl Iterator<Item = T>, _2: impl Fn(T) -> Option<U>) -> ()
     let mut _3: std::iter::FilterMap<impl Iterator<Item = T>, impl Fn(T) -> Option<U>>;
     let mut _4: std::iter::FilterMap<impl Iterator<Item = T>, impl Fn(T) -> Option<U>>;
     let mut _5: std::iter::FilterMap<impl Iterator<Item = T>, impl Fn(T) -> Option<U>>;
-    let mut _8: std::option::Option<U>;
-    let mut _9: isize;
-    let _11: ();
-    let mut _12: &mut std::iter::FilterMap<impl Iterator<Item = T>, impl Fn(T) -> Option<U>>;
+    let mut _6: &mut std::iter::FilterMap<impl Iterator<Item = T>, impl Fn(T) -> Option<U>>;
+    let mut _9: std::option::Option<U>;
+    let mut _10: isize;
+    let _12: ();
     scope 1 {
         debug iter => _5;
-        let _10: U;
+        let _11: U;
         scope 2 {
-            debug x => _10;
+            debug x => _11;
         }
         scope 4 (inlined <FilterMap<impl Iterator<Item = T>, impl Fn(T) -> Option<U>> as Iterator>::next) {
-            debug self => _12;
-            let mut _6: &mut impl Iterator<Item = T>;
-            let mut _7: &mut impl Fn(T) -> Option<U>;
+            debug self => _6;
+            let mut _7: &mut impl Iterator<Item = T>;
+            let mut _8: &mut impl Fn(T) -> Option<U>;
         }
     }
     scope 3 (inlined <FilterMap<impl Iterator<Item = T>, impl Fn(T) -> Option<U>> as IntoIterator>::into_iter) {
@@ -42,23 +42,24 @@ fn filter_mapped(_1: impl Iterator<Item = T>, _2: impl Fn(T) -> Option<U>) -> ()
     }
 
     bb2: {
-        StorageLive(_8);
-        StorageLive(_6);
-        _6 = &mut (_5.0: impl Iterator<Item = T>);
+        StorageLive(_9);
+        _6 = &mut _5;
         StorageLive(_7);
-        _7 = &mut (_5.1: impl Fn(T) -> Option<U>);
-        _8 = <impl Iterator<Item = T> as Iterator>::find_map::<U, &mut impl Fn(T) -> Option<U>>(move _6, move _7) -> [return: bb3, unwind: bb9];
+        _7 = &mut (_5.0: impl Iterator<Item = T>);
+        StorageLive(_8);
+        _8 = &mut (_5.1: impl Fn(T) -> Option<U>);
+        _9 = <impl Iterator<Item = T> as Iterator>::find_map::<U, &mut impl Fn(T) -> Option<U>>(move _7, move _8) -> [return: bb3, unwind: bb9];
     }
 
     bb3: {
+        StorageDead(_8);
         StorageDead(_7);
-        StorageDead(_6);
-        _9 = discriminant(_8);
-        switchInt(move _9) -> [0: bb4, 1: bb6, otherwise: bb8];
+        _10 = discriminant(_9);
+        switchInt(move _10) -> [0: bb4, 1: bb6, otherwise: bb8];
     }
 
     bb4: {
-        StorageDead(_8);
+        StorageDead(_9);
         drop(_5) -> [return: bb5, unwind continue];
     }
 
@@ -69,12 +70,12 @@ fn filter_mapped(_1: impl Iterator<Item = T>, _2: impl Fn(T) -> Option<U>) -> ()
     }
 
     bb6: {
-        _10 = move ((_8 as Some).0: U);
-        _11 = opaque::<U>(move _10) -> [return: bb7, unwind: bb9];
+        _11 = move ((_9 as Some).0: U);
+        _12 = opaque::<U>(move _11) -> [return: bb7, unwind: bb9];
     }
 
     bb7: {
-        StorageDead(_8);
+        StorageDead(_9);
         goto -> bb2;
     }
 
diff --git a/tests/mir-opt/pre-codegen/loops.int_range.PreCodegen.after.mir b/tests/mir-opt/pre-codegen/loops.int_range.PreCodegen.after.mir
index 0d79f2de10d..49f685cfacd 100644
--- a/tests/mir-opt/pre-codegen/loops.int_range.PreCodegen.after.mir
+++ b/tests/mir-opt/pre-codegen/loops.int_range.PreCodegen.after.mir
@@ -6,35 +6,35 @@ fn int_range(_1: usize, _2: usize) -> () {
     let mut _0: ();
     let mut _3: std::ops::Range<usize>;
     let mut _4: std::ops::Range<usize>;
-    let mut _8: std::option::Option<usize>;
-    let mut _11: isize;
-    let _13: ();
-    let mut _14: &mut std::ops::Range<usize>;
+    let mut _5: &mut std::ops::Range<usize>;
+    let mut _11: std::option::Option<usize>;
+    let mut _14: isize;
+    let _16: ();
     scope 1 {
         debug iter => _4;
-        let _12: usize;
+        let _15: usize;
         scope 2 {
-            debug i => _12;
+            debug i => _15;
         }
         scope 4 (inlined iter::range::<impl Iterator for std::ops::Range<usize>>::next) {
-            debug self => _14;
+            debug self => _5;
             scope 5 (inlined <std::ops::Range<usize> as iter::range::RangeIteratorImpl>::spec_next) {
-                debug self => _14;
-                let mut _7: bool;
-                let _9: usize;
-                let mut _10: usize;
-                let mut _15: &usize;
-                let mut _16: &usize;
+                debug self => _5;
+                let mut _6: &usize;
+                let mut _7: &usize;
+                let mut _10: bool;
+                let _12: usize;
+                let mut _13: usize;
                 scope 6 {
-                    debug old => _9;
+                    debug old => _12;
                     scope 7 {
                     }
                 }
                 scope 8 (inlined cmp::impls::<impl PartialOrd for usize>::lt) {
-                    debug self => _15;
-                    debug other => _16;
-                    let mut _5: usize;
-                    let mut _6: usize;
+                    debug self => _6;
+                    debug other => _7;
+                    let mut _8: usize;
+                    let mut _9: usize;
                 }
             }
         }
@@ -51,63 +51,66 @@ fn int_range(_1: usize, _2: usize) -> () {
     }
 
     bb1: {
+        StorageLive(_11);
+        _5 = &mut _4;
+        StorageLive(_12);
+        StorageLive(_10);
+        StorageLive(_6);
+        _6 = &(_4.0: usize);
+        StorageLive(_7);
+        _7 = &(_4.1: usize);
         StorageLive(_8);
+        _8 = (_4.0: usize);
         StorageLive(_9);
-        StorageLive(_7);
-        StorageLive(_15);
-        StorageLive(_16);
-        StorageLive(_5);
-        _5 = (_4.0: usize);
-        StorageLive(_6);
-        _6 = (_4.1: usize);
-        _7 = Lt(move _5, move _6);
-        StorageDead(_6);
-        StorageDead(_5);
-        switchInt(move _7) -> [0: bb2, otherwise: bb3];
+        _9 = (_4.1: usize);
+        _10 = Lt(move _8, move _9);
+        StorageDead(_9);
+        StorageDead(_8);
+        switchInt(move _10) -> [0: bb2, otherwise: bb3];
     }
 
     bb2: {
-        StorageDead(_16);
-        StorageDead(_15);
-        _8 = Option::<usize>::None;
+        StorageDead(_7);
+        StorageDead(_6);
+        _11 = Option::<usize>::None;
         goto -> bb5;
     }
 
     bb3: {
-        StorageDead(_16);
-        StorageDead(_15);
-        _9 = (_4.0: usize);
-        StorageLive(_10);
-        _10 = <usize as Step>::forward_unchecked(_9, const 1_usize) -> [return: bb4, unwind continue];
+        StorageDead(_7);
+        StorageDead(_6);
+        _12 = (_4.0: usize);
+        StorageLive(_13);
+        _13 = <usize as Step>::forward_unchecked(_12, const 1_usize) -> [return: bb4, unwind continue];
     }
 
     bb4: {
-        (_4.0: usize) = move _10;
-        StorageDead(_10);
-        _8 = Option::<usize>::Some(_9);
+        (_4.0: usize) = move _13;
+        StorageDead(_13);
+        _11 = Option::<usize>::Some(_12);
         goto -> bb5;
     }
 
     bb5: {
-        StorageDead(_7);
-        StorageDead(_9);
-        _11 = discriminant(_8);
-        switchInt(move _11) -> [0: bb6, 1: bb7, otherwise: bb9];
+        StorageDead(_10);
+        StorageDead(_12);
+        _14 = discriminant(_11);
+        switchInt(move _14) -> [0: bb6, 1: bb7, otherwise: bb9];
     }
 
     bb6: {
-        StorageDead(_8);
+        StorageDead(_11);
         StorageDead(_4);
         return;
     }
 
     bb7: {
-        _12 = ((_8 as Some).0: usize);
-        _13 = opaque::<usize>(move _12) -> [return: bb8, unwind continue];
+        _15 = ((_11 as Some).0: usize);
+        _16 = opaque::<usize>(move _15) -> [return: bb8, unwind continue];
     }
 
     bb8: {
-        StorageDead(_8);
+        StorageDead(_11);
         goto -> bb1;
     }
 
diff --git a/tests/mir-opt/pre-codegen/range_iter.forward_loop.PreCodegen.after.panic-abort.mir b/tests/mir-opt/pre-codegen/range_iter.forward_loop.PreCodegen.after.panic-abort.mir
index 9664ccfb094..91c3731f492 100644
--- a/tests/mir-opt/pre-codegen/range_iter.forward_loop.PreCodegen.after.panic-abort.mir
+++ b/tests/mir-opt/pre-codegen/range_iter.forward_loop.PreCodegen.after.panic-abort.mir
@@ -7,37 +7,37 @@ fn forward_loop(_1: u32, _2: u32, _3: impl Fn(u32)) -> () {
     let mut _0: ();
     let mut _4: std::ops::Range<u32>;
     let mut _5: std::ops::Range<u32>;
-    let mut _9: std::option::Option<u32>;
-    let mut _12: isize;
-    let mut _14: &impl Fn(u32);
-    let mut _15: (u32,);
-    let _16: ();
-    let mut _17: &mut std::ops::Range<u32>;
+    let mut _6: &mut std::ops::Range<u32>;
+    let mut _12: std::option::Option<u32>;
+    let mut _15: isize;
+    let mut _17: &impl Fn(u32);
+    let mut _18: (u32,);
+    let _19: ();
     scope 1 {
         debug iter => _5;
-        let _13: u32;
+        let _16: u32;
         scope 2 {
-            debug x => _13;
+            debug x => _16;
         }
         scope 4 (inlined iter::range::<impl Iterator for std::ops::Range<u32>>::next) {
-            debug self => _17;
+            debug self => _6;
             scope 5 (inlined <std::ops::Range<u32> as iter::range::RangeIteratorImpl>::spec_next) {
-                debug self => _17;
-                let mut _8: bool;
-                let _10: u32;
-                let mut _11: u32;
-                let mut _18: &u32;
-                let mut _19: &u32;
+                debug self => _6;
+                let mut _7: &u32;
+                let mut _8: &u32;
+                let mut _11: bool;
+                let _13: u32;
+                let mut _14: u32;
                 scope 6 {
-                    debug old => _10;
+                    debug old => _13;
                     scope 7 {
                     }
                 }
                 scope 8 (inlined cmp::impls::<impl PartialOrd for u32>::lt) {
-                    debug self => _18;
-                    debug other => _19;
-                    let mut _6: u32;
-                    let mut _7: u32;
+                    debug self => _7;
+                    debug other => _8;
+                    let mut _9: u32;
+                    let mut _10: u32;
                 }
             }
         }
@@ -54,52 +54,55 @@ fn forward_loop(_1: u32, _2: u32, _3: impl Fn(u32)) -> () {
     }
 
     bb1: {
+        StorageLive(_12);
+        _6 = &mut _5;
+        StorageLive(_13);
+        StorageLive(_11);
+        StorageLive(_7);
+        _7 = &(_5.0: u32);
+        StorageLive(_8);
+        _8 = &(_5.1: u32);
         StorageLive(_9);
+        _9 = (_5.0: u32);
         StorageLive(_10);
-        StorageLive(_8);
-        StorageLive(_18);
-        StorageLive(_19);
-        StorageLive(_6);
-        _6 = (_5.0: u32);
-        StorageLive(_7);
-        _7 = (_5.1: u32);
-        _8 = Lt(move _6, move _7);
-        StorageDead(_7);
-        StorageDead(_6);
-        switchInt(move _8) -> [0: bb2, otherwise: bb3];
+        _10 = (_5.1: u32);
+        _11 = Lt(move _9, move _10);
+        StorageDead(_10);
+        StorageDead(_9);
+        switchInt(move _11) -> [0: bb2, otherwise: bb3];
     }
 
     bb2: {
-        StorageDead(_19);
-        StorageDead(_18);
-        _9 = Option::<u32>::None;
+        StorageDead(_8);
+        StorageDead(_7);
+        _12 = Option::<u32>::None;
         goto -> bb5;
     }
 
     bb3: {
-        StorageDead(_19);
-        StorageDead(_18);
-        _10 = (_5.0: u32);
-        StorageLive(_11);
-        _11 = <u32 as Step>::forward_unchecked(_10, const 1_usize) -> [return: bb4, unwind unreachable];
+        StorageDead(_8);
+        StorageDead(_7);
+        _13 = (_5.0: u32);
+        StorageLive(_14);
+        _14 = <u32 as Step>::forward_unchecked(_13, const 1_usize) -> [return: bb4, unwind unreachable];
     }
 
     bb4: {
-        (_5.0: u32) = move _11;
-        StorageDead(_11);
-        _9 = Option::<u32>::Some(_10);
+        (_5.0: u32) = move _14;
+        StorageDead(_14);
+        _12 = Option::<u32>::Some(_13);
         goto -> bb5;
     }
 
     bb5: {
-        StorageDead(_8);
-        StorageDead(_10);
-        _12 = discriminant(_9);
-        switchInt(move _12) -> [0: bb6, 1: bb8, otherwise: bb10];
+        StorageDead(_11);
+        StorageDead(_13);
+        _15 = discriminant(_12);
+        switchInt(move _15) -> [0: bb6, 1: bb8, otherwise: bb10];
     }
 
     bb6: {
-        StorageDead(_9);
+        StorageDead(_12);
         StorageDead(_5);
         drop(_3) -> [return: bb7, unwind unreachable];
     }
@@ -109,18 +112,18 @@ fn forward_loop(_1: u32, _2: u32, _3: impl Fn(u32)) -> () {
     }
 
     bb8: {
-        _13 = ((_9 as Some).0: u32);
-        StorageLive(_14);
-        _14 = &_3;
-        StorageLive(_15);
-        _15 = (_13,);
-        _16 = <impl Fn(u32) as Fn<(u32,)>>::call(move _14, move _15) -> [return: bb9, unwind unreachable];
+        _16 = ((_12 as Some).0: u32);
+        StorageLive(_17);
+        _17 = &_3;
+        StorageLive(_18);
+        _18 = (_16,);
+        _19 = <impl Fn(u32) as Fn<(u32,)>>::call(move _17, move _18) -> [return: bb9, unwind unreachable];
     }
 
     bb9: {
-        StorageDead(_15);
-        StorageDead(_14);
-        StorageDead(_9);
+        StorageDead(_18);
+        StorageDead(_17);
+        StorageDead(_12);
         goto -> bb1;
     }
 
diff --git a/tests/mir-opt/pre-codegen/range_iter.forward_loop.PreCodegen.after.panic-unwind.mir b/tests/mir-opt/pre-codegen/range_iter.forward_loop.PreCodegen.after.panic-unwind.mir
index dc8b46b6c08..f76de02c9d1 100644
--- a/tests/mir-opt/pre-codegen/range_iter.forward_loop.PreCodegen.after.panic-unwind.mir
+++ b/tests/mir-opt/pre-codegen/range_iter.forward_loop.PreCodegen.after.panic-unwind.mir
@@ -7,37 +7,37 @@ fn forward_loop(_1: u32, _2: u32, _3: impl Fn(u32)) -> () {
     let mut _0: ();
     let mut _4: std::ops::Range<u32>;
     let mut _5: std::ops::Range<u32>;
-    let mut _9: std::option::Option<u32>;
-    let mut _12: isize;
-    let mut _14: &impl Fn(u32);
-    let mut _15: (u32,);
-    let _16: ();
-    let mut _17: &mut std::ops::Range<u32>;
+    let mut _6: &mut std::ops::Range<u32>;
+    let mut _12: std::option::Option<u32>;
+    let mut _15: isize;
+    let mut _17: &impl Fn(u32);
+    let mut _18: (u32,);
+    let _19: ();
     scope 1 {
         debug iter => _5;
-        let _13: u32;
+        let _16: u32;
         scope 2 {
-            debug x => _13;
+            debug x => _16;
         }
         scope 4 (inlined iter::range::<impl Iterator for std::ops::Range<u32>>::next) {
-            debug self => _17;
+            debug self => _6;
             scope 5 (inlined <std::ops::Range<u32> as iter::range::RangeIteratorImpl>::spec_next) {
-                debug self => _17;
-                let mut _8: bool;
-                let _10: u32;
-                let mut _11: u32;
-                let mut _18: &u32;
-                let mut _19: &u32;
+                debug self => _6;
+                let mut _7: &u32;
+                let mut _8: &u32;
+                let mut _11: bool;
+                let _13: u32;
+                let mut _14: u32;
                 scope 6 {
-                    debug old => _10;
+                    debug old => _13;
                     scope 7 {
                     }
                 }
                 scope 8 (inlined cmp::impls::<impl PartialOrd for u32>::lt) {
-                    debug self => _18;
-                    debug other => _19;
-                    let mut _6: u32;
-                    let mut _7: u32;
+                    debug self => _7;
+                    debug other => _8;
+                    let mut _9: u32;
+                    let mut _10: u32;
                 }
             }
         }
@@ -54,52 +54,55 @@ fn forward_loop(_1: u32, _2: u32, _3: impl Fn(u32)) -> () {
     }
 
     bb1: {
+        StorageLive(_12);
+        _6 = &mut _5;
+        StorageLive(_13);
+        StorageLive(_11);
+        StorageLive(_7);
+        _7 = &(_5.0: u32);
+        StorageLive(_8);
+        _8 = &(_5.1: u32);
         StorageLive(_9);
+        _9 = (_5.0: u32);
         StorageLive(_10);
-        StorageLive(_8);
-        StorageLive(_18);
-        StorageLive(_19);
-        StorageLive(_6);
-        _6 = (_5.0: u32);
-        StorageLive(_7);
-        _7 = (_5.1: u32);
-        _8 = Lt(move _6, move _7);
-        StorageDead(_7);
-        StorageDead(_6);
-        switchInt(move _8) -> [0: bb2, otherwise: bb3];
+        _10 = (_5.1: u32);
+        _11 = Lt(move _9, move _10);
+        StorageDead(_10);
+        StorageDead(_9);
+        switchInt(move _11) -> [0: bb2, otherwise: bb3];
     }
 
     bb2: {
-        StorageDead(_19);
-        StorageDead(_18);
-        _9 = Option::<u32>::None;
+        StorageDead(_8);
+        StorageDead(_7);
+        _12 = Option::<u32>::None;
         goto -> bb5;
     }
 
     bb3: {
-        StorageDead(_19);
-        StorageDead(_18);
-        _10 = (_5.0: u32);
-        StorageLive(_11);
-        _11 = <u32 as Step>::forward_unchecked(_10, const 1_usize) -> [return: bb4, unwind: bb11];
+        StorageDead(_8);
+        StorageDead(_7);
+        _13 = (_5.0: u32);
+        StorageLive(_14);
+        _14 = <u32 as Step>::forward_unchecked(_13, const 1_usize) -> [return: bb4, unwind: bb11];
     }
 
     bb4: {
-        (_5.0: u32) = move _11;
-        StorageDead(_11);
-        _9 = Option::<u32>::Some(_10);
+        (_5.0: u32) = move _14;
+        StorageDead(_14);
+        _12 = Option::<u32>::Some(_13);
         goto -> bb5;
     }
 
     bb5: {
-        StorageDead(_8);
-        StorageDead(_10);
-        _12 = discriminant(_9);
-        switchInt(move _12) -> [0: bb6, 1: bb8, otherwise: bb10];
+        StorageDead(_11);
+        StorageDead(_13);
+        _15 = discriminant(_12);
+        switchInt(move _15) -> [0: bb6, 1: bb8, otherwise: bb10];
     }
 
     bb6: {
-        StorageDead(_9);
+        StorageDead(_12);
         StorageDead(_5);
         drop(_3) -> [return: bb7, unwind continue];
     }
@@ -109,18 +112,18 @@ fn forward_loop(_1: u32, _2: u32, _3: impl Fn(u32)) -> () {
     }
 
     bb8: {
-        _13 = ((_9 as Some).0: u32);
-        StorageLive(_14);
-        _14 = &_3;
-        StorageLive(_15);
-        _15 = (_13,);
-        _16 = <impl Fn(u32) as Fn<(u32,)>>::call(move _14, move _15) -> [return: bb9, unwind: bb11];
+        _16 = ((_12 as Some).0: u32);
+        StorageLive(_17);
+        _17 = &_3;
+        StorageLive(_18);
+        _18 = (_16,);
+        _19 = <impl Fn(u32) as Fn<(u32,)>>::call(move _17, move _18) -> [return: bb9, unwind: bb11];
     }
 
     bb9: {
-        StorageDead(_15);
-        StorageDead(_14);
-        StorageDead(_9);
+        StorageDead(_18);
+        StorageDead(_17);
+        StorageDead(_12);
         goto -> bb1;
     }
 
diff --git a/tests/mir-opt/pre-codegen/range_iter.range_iter_next.PreCodegen.after.panic-abort.mir b/tests/mir-opt/pre-codegen/range_iter.range_iter_next.PreCodegen.after.panic-abort.mir
index fff713b5a79..a7824f36d50 100644
--- a/tests/mir-opt/pre-codegen/range_iter.range_iter_next.PreCodegen.after.panic-abort.mir
+++ b/tests/mir-opt/pre-codegen/range_iter.range_iter_next.PreCodegen.after.panic-abort.mir
@@ -7,65 +7,67 @@ fn range_iter_next(_1: &mut std::ops::Range<u32>) -> Option<u32> {
         debug self => _1;
         scope 2 (inlined <std::ops::Range<u32> as iter::range::RangeIteratorImpl>::spec_next) {
             debug self => _1;
-            let mut _4: bool;
-            let _5: u32;
-            let mut _6: u32;
-            let mut _7: &u32;
-            let mut _8: &u32;
+            let mut _2: &u32;
+            let mut _3: &u32;
+            let mut _6: bool;
+            let _7: u32;
+            let mut _8: u32;
             scope 3 {
-                debug old => _5;
+                debug old => _7;
                 scope 4 {
                 }
             }
             scope 5 (inlined cmp::impls::<impl PartialOrd for u32>::lt) {
-                debug self => _7;
-                debug other => _8;
-                let mut _2: u32;
-                let mut _3: u32;
+                debug self => _2;
+                debug other => _3;
+                let mut _4: u32;
+                let mut _5: u32;
             }
         }
     }
 
     bb0: {
-        StorageLive(_5);
-        StorageLive(_4);
         StorageLive(_7);
-        StorageLive(_8);
+        StorageLive(_6);
         StorageLive(_2);
-        _2 = ((*_1).0: u32);
+        _2 = &((*_1).0: u32);
         StorageLive(_3);
-        _3 = ((*_1).1: u32);
-        _4 = Lt(move _2, move _3);
-        StorageDead(_3);
-        StorageDead(_2);
-        switchInt(move _4) -> [0: bb1, otherwise: bb2];
+        _3 = &((*_1).1: u32);
+        StorageLive(_4);
+        _4 = ((*_1).0: u32);
+        StorageLive(_5);
+        _5 = ((*_1).1: u32);
+        _6 = Lt(move _4, move _5);
+        StorageDead(_5);
+        StorageDead(_4);
+        switchInt(move _6) -> [0: bb1, otherwise: bb2];
     }
 
     bb1: {
-        StorageDead(_8);
-        StorageDead(_7);
+        StorageDead(_3);
+        StorageDead(_2);
         _0 = Option::<u32>::None;
         goto -> bb4;
     }
 
     bb2: {
-        StorageDead(_8);
-        StorageDead(_7);
-        _5 = ((*_1).0: u32);
-        StorageLive(_6);
-        _6 = <u32 as Step>::forward_unchecked(_5, const 1_usize) -> [return: bb3, unwind unreachable];
+        StorageDead(_3);
+        StorageDead(_2);
+        _7 = ((*_1).0: u32);
+        StorageLive(_8);
+        _8 = <u32 as Step>::forward_unchecked(_7, const 1_usize) -> [return: bb3, unwind unreachable];
     }
 
     bb3: {
-        ((*_1).0: u32) = move _6;
-        StorageDead(_6);
-        _0 = Option::<u32>::Some(_5);
+        ((*_1).0: u32) = move _8;
+        StorageDead(_8);
+        _0 = Option::<u32>::Some(_7);
         goto -> bb4;
     }
 
     bb4: {
-        StorageDead(_4);
-        StorageDead(_5);
+        StorageDead(_6);
+        StorageDead(_7);
         return;
     }
 }
diff --git a/tests/mir-opt/pre-codegen/range_iter.range_iter_next.PreCodegen.after.panic-unwind.mir b/tests/mir-opt/pre-codegen/range_iter.range_iter_next.PreCodegen.after.panic-unwind.mir
index cc12c0122b7..83c9e6c1af2 100644
--- a/tests/mir-opt/pre-codegen/range_iter.range_iter_next.PreCodegen.after.panic-unwind.mir
+++ b/tests/mir-opt/pre-codegen/range_iter.range_iter_next.PreCodegen.after.panic-unwind.mir
@@ -7,65 +7,67 @@ fn range_iter_next(_1: &mut std::ops::Range<u32>) -> Option<u32> {
         debug self => _1;
         scope 2 (inlined <std::ops::Range<u32> as iter::range::RangeIteratorImpl>::spec_next) {
             debug self => _1;
-            let mut _4: bool;
-            let _5: u32;
-            let mut _6: u32;
-            let mut _7: &u32;
-            let mut _8: &u32;
+            let mut _2: &u32;
+            let mut _3: &u32;
+            let mut _6: bool;
+            let _7: u32;
+            let mut _8: u32;
             scope 3 {
-                debug old => _5;
+                debug old => _7;
                 scope 4 {
                 }
             }
             scope 5 (inlined cmp::impls::<impl PartialOrd for u32>::lt) {
-                debug self => _7;
-                debug other => _8;
-                let mut _2: u32;
-                let mut _3: u32;
+                debug self => _2;
+                debug other => _3;
+                let mut _4: u32;
+                let mut _5: u32;
             }
         }
     }
 
     bb0: {
-        StorageLive(_5);
-        StorageLive(_4);
         StorageLive(_7);
-        StorageLive(_8);
+        StorageLive(_6);
         StorageLive(_2);
-        _2 = ((*_1).0: u32);
+        _2 = &((*_1).0: u32);
         StorageLive(_3);
-        _3 = ((*_1).1: u32);
-        _4 = Lt(move _2, move _3);
-        StorageDead(_3);
-        StorageDead(_2);
-        switchInt(move _4) -> [0: bb1, otherwise: bb2];
+        _3 = &((*_1).1: u32);
+        StorageLive(_4);
+        _4 = ((*_1).0: u32);
+        StorageLive(_5);
+        _5 = ((*_1).1: u32);
+        _6 = Lt(move _4, move _5);
+        StorageDead(_5);
+        StorageDead(_4);
+        switchInt(move _6) -> [0: bb1, otherwise: bb2];
     }
 
     bb1: {
-        StorageDead(_8);
-        StorageDead(_7);
+        StorageDead(_3);
+        StorageDead(_2);
         _0 = Option::<u32>::None;
         goto -> bb4;
     }
 
     bb2: {
-        StorageDead(_8);
-        StorageDead(_7);
-        _5 = ((*_1).0: u32);
-        StorageLive(_6);
-        _6 = <u32 as Step>::forward_unchecked(_5, const 1_usize) -> [return: bb3, unwind continue];
+        StorageDead(_3);
+        StorageDead(_2);
+        _7 = ((*_1).0: u32);
+        StorageLive(_8);
+        _8 = <u32 as Step>::forward_unchecked(_7, const 1_usize) -> [return: bb3, unwind continue];
     }
 
     bb3: {
-        ((*_1).0: u32) = move _6;
-        StorageDead(_6);
-        _0 = Option::<u32>::Some(_5);
+        ((*_1).0: u32) = move _8;
+        StorageDead(_8);
+        _0 = Option::<u32>::Some(_7);
         goto -> bb4;
     }
 
     bb4: {
-        StorageDead(_4);
-        StorageDead(_5);
+        StorageDead(_6);
+        StorageDead(_7);
         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 9c10e96b0ea..b35d3a105ba 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
@@ -10,74 +10,74 @@ fn variant_a::{closure#0}(_1: &mut {closure@$DIR/slice_filter.rs:7:25: 7:39}, _2
     let _8: &usize;
     let mut _9: &(usize, usize, usize, usize);
     let _10: &usize;
-    let _11: &usize;
-    let mut _16: bool;
-    let _17: &usize;
-    let mut _22: bool;
-    let _23: &usize;
-    let mut _28: bool;
-    let _29: &usize;
-    let mut _34: &&usize;
+    let mut _11: &&usize;
+    let _12: &usize;
+    let mut _13: &&usize;
+    let mut _18: bool;
+    let mut _19: &&usize;
+    let _20: &usize;
+    let mut _21: &&usize;
+    let mut _26: bool;
+    let mut _27: &&usize;
+    let _28: &usize;
+    let mut _29: &&usize;
+    let mut _34: bool;
     let mut _35: &&usize;
-    let mut _36: &&usize;
+    let _36: &usize;
     let mut _37: &&usize;
-    let mut _38: &&usize;
-    let mut _39: &&usize;
-    let mut _40: &&usize;
-    let mut _41: &&usize;
     scope 1 {
         debug a => _4;
         debug b => _6;
         debug c => _8;
         debug d => _10;
         scope 2 (inlined cmp::impls::<impl PartialOrd for &usize>::le) {
-            debug self => _34;
-            debug other => _35;
-            let mut _12: &usize;
-            let mut _13: &usize;
+            debug self => _11;
+            debug other => _13;
+            let mut _14: &usize;
+            let mut _15: &usize;
             scope 3 (inlined cmp::impls::<impl PartialOrd for usize>::le) {
-                debug self => _12;
-                debug other => _13;
-                let mut _14: usize;
-                let mut _15: usize;
+                debug self => _14;
+                debug other => _15;
+                let mut _16: usize;
+                let mut _17: usize;
             }
         }
         scope 4 (inlined cmp::impls::<impl PartialOrd for &usize>::le) {
-            debug self => _36;
-            debug other => _37;
-            let mut _18: &usize;
-            let mut _19: &usize;
+            debug self => _19;
+            debug other => _21;
+            let mut _22: &usize;
+            let mut _23: &usize;
             scope 5 (inlined cmp::impls::<impl PartialOrd for usize>::le) {
-                debug self => _18;
-                debug other => _19;
-                let mut _20: usize;
-                let mut _21: usize;
+                debug self => _22;
+                debug other => _23;
+                let mut _24: usize;
+                let mut _25: usize;
             }
         }
         scope 6 (inlined cmp::impls::<impl PartialOrd for &usize>::le) {
-            debug self => _38;
-            debug other => _39;
-            let mut _24: &usize;
-            let mut _25: &usize;
-            scope 7 (inlined cmp::impls::<impl PartialOrd for usize>::le) {
-                debug self => _24;
-                debug other => _25;
-                let mut _26: usize;
-                let mut _27: usize;
-            }
-        }
-        scope 8 (inlined cmp::impls::<impl PartialOrd for &usize>::le) {
-            debug self => _40;
-            debug other => _41;
+            debug self => _27;
+            debug other => _29;
             let mut _30: &usize;
             let mut _31: &usize;
-            scope 9 (inlined cmp::impls::<impl PartialOrd for usize>::le) {
+            scope 7 (inlined cmp::impls::<impl PartialOrd for usize>::le) {
                 debug self => _30;
                 debug other => _31;
                 let mut _32: usize;
                 let mut _33: usize;
             }
         }
+        scope 8 (inlined cmp::impls::<impl PartialOrd for &usize>::le) {
+            debug self => _35;
+            debug other => _37;
+            let mut _38: &usize;
+            let mut _39: &usize;
+            scope 9 (inlined cmp::impls::<impl PartialOrd for usize>::le) {
+                debug self => _38;
+                debug other => _39;
+                let mut _40: usize;
+                let mut _41: usize;
+            }
+        }
     }
 
     bb0: {
@@ -93,139 +93,147 @@ fn variant_a::{closure#0}(_1: &mut {closure@$DIR/slice_filter.rs:7:25: 7:39}, _2
         StorageLive(_10);
         _9 = deref_copy (*_2);
         _10 = &((*_9).3: usize);
-        StorageLive(_16);
-        StorageLive(_34);
-        StorageLive(_35);
+        StorageLive(_18);
         StorageLive(_11);
-        _11 = _8;
-        StorageLive(_12);
+        _11 = &_4;
         StorageLive(_13);
-        _12 = deref_copy _4;
-        _13 = deref_copy _11;
+        StorageLive(_12);
+        _12 = _8;
+        _13 = &_12;
         StorageLive(_14);
-        _14 = (*_12);
         StorageLive(_15);
-        _15 = (*_13);
-        _16 = Le(move _14, move _15);
+        _14 = deref_copy _4;
+        _15 = deref_copy _12;
+        StorageLive(_16);
+        _16 = (*_14);
+        StorageLive(_17);
+        _17 = (*_15);
+        _18 = Le(move _16, move _17);
+        StorageDead(_17);
+        StorageDead(_16);
         StorageDead(_15);
         StorageDead(_14);
-        StorageDead(_13);
-        StorageDead(_12);
-        switchInt(move _16) -> [0: bb1, otherwise: bb2];
+        switchInt(move _18) -> [0: bb1, otherwise: bb2];
     }
 
     bb1: {
+        StorageDead(_12);
+        StorageDead(_13);
         StorageDead(_11);
-        StorageDead(_35);
-        StorageDead(_34);
         goto -> bb4;
     }
 
     bb2: {
+        StorageDead(_12);
+        StorageDead(_13);
         StorageDead(_11);
-        StorageDead(_35);
-        StorageDead(_34);
-        StorageLive(_22);
-        StorageLive(_36);
-        StorageLive(_37);
-        StorageLive(_17);
-        _17 = _6;
-        StorageLive(_18);
+        StorageLive(_26);
         StorageLive(_19);
-        _18 = deref_copy _10;
-        _19 = deref_copy _17;
-        StorageLive(_20);
-        _20 = (*_18);
+        _19 = &_10;
         StorageLive(_21);
-        _21 = (*_19);
-        _22 = Le(move _20, move _21);
-        StorageDead(_21);
-        StorageDead(_20);
-        StorageDead(_19);
-        StorageDead(_18);
-        switchInt(move _22) -> [0: bb3, otherwise: bb8];
-    }
-
-    bb3: {
-        StorageDead(_17);
-        StorageDead(_37);
-        StorageDead(_36);
-        goto -> bb4;
-    }
-
-    bb4: {
-        StorageLive(_28);
-        StorageLive(_38);
-        StorageLive(_39);
+        StorageLive(_20);
+        _20 = _6;
+        _21 = &_20;
+        StorageLive(_22);
         StorageLive(_23);
-        _23 = _4;
+        _22 = deref_copy _10;
+        _23 = deref_copy _20;
         StorageLive(_24);
+        _24 = (*_22);
         StorageLive(_25);
-        _24 = deref_copy _8;
-        _25 = deref_copy _23;
-        StorageLive(_26);
-        _26 = (*_24);
-        StorageLive(_27);
-        _27 = (*_25);
-        _28 = Le(move _26, move _27);
-        StorageDead(_27);
-        StorageDead(_26);
+        _25 = (*_23);
+        _26 = Le(move _24, move _25);
         StorageDead(_25);
         StorageDead(_24);
-        switchInt(move _28) -> [0: bb5, otherwise: bb6];
+        StorageDead(_23);
+        StorageDead(_22);
+        switchInt(move _26) -> [0: bb3, otherwise: bb8];
     }
 
-    bb5: {
-        StorageDead(_23);
-        StorageDead(_39);
-        StorageDead(_38);
-        _0 = const false;
-        goto -> bb7;
+    bb3: {
+        StorageDead(_20);
+        StorageDead(_21);
+        StorageDead(_19);
+        goto -> bb4;
     }
 
-    bb6: {
-        StorageDead(_23);
-        StorageDead(_39);
-        StorageDead(_38);
-        StorageLive(_40);
-        StorageLive(_41);
+    bb4: {
+        StorageLive(_34);
+        StorageLive(_27);
+        _27 = &_8;
         StorageLive(_29);
-        _29 = _10;
+        StorageLive(_28);
+        _28 = _4;
+        _29 = &_28;
         StorageLive(_30);
         StorageLive(_31);
-        _30 = deref_copy _6;
-        _31 = deref_copy _29;
+        _30 = deref_copy _8;
+        _31 = deref_copy _28;
         StorageLive(_32);
         _32 = (*_30);
         StorageLive(_33);
         _33 = (*_31);
-        _0 = Le(move _32, move _33);
+        _34 = Le(move _32, move _33);
         StorageDead(_33);
         StorageDead(_32);
         StorageDead(_31);
         StorageDead(_30);
+        switchInt(move _34) -> [0: bb5, otherwise: bb6];
+    }
+
+    bb5: {
+        StorageDead(_28);
         StorageDead(_29);
+        StorageDead(_27);
+        _0 = const false;
+        goto -> bb7;
+    }
+
+    bb6: {
+        StorageDead(_28);
+        StorageDead(_29);
+        StorageDead(_27);
+        StorageLive(_35);
+        _35 = &_6;
+        StorageLive(_37);
+        StorageLive(_36);
+        _36 = _10;
+        _37 = &_36;
+        StorageLive(_38);
+        StorageLive(_39);
+        _38 = deref_copy _6;
+        _39 = deref_copy _36;
+        StorageLive(_40);
+        _40 = (*_38);
+        StorageLive(_41);
+        _41 = (*_39);
+        _0 = Le(move _40, move _41);
         StorageDead(_41);
         StorageDead(_40);
+        StorageDead(_39);
+        StorageDead(_38);
+        StorageDead(_36);
+        StorageDead(_37);
+        StorageDead(_35);
         goto -> bb7;
     }
 
     bb7: {
-        StorageDead(_28);
+        StorageDead(_34);
         goto -> bb9;
     }
 
     bb8: {
-        StorageDead(_17);
-        StorageDead(_37);
-        StorageDead(_36);
+        StorageDead(_20);
+        StorageDead(_21);
+        StorageDead(_19);
         _0 = const true;
         goto -> bb9;
     }
 
     bb9: {
-        StorageDead(_22);
-        StorageDead(_16);
+        StorageDead(_26);
+        StorageDead(_18);
         StorageDead(_10);
         StorageDead(_8);
         StorageDead(_6);
diff --git a/tests/mir-opt/pre-codegen/slice_index.slice_get_unchecked_mut_range.PreCodegen.after.panic-abort.mir b/tests/mir-opt/pre-codegen/slice_index.slice_get_unchecked_mut_range.PreCodegen.after.panic-abort.mir
index 2fd669aeeb6..729841ec5ea 100644
--- a/tests/mir-opt/pre-codegen/slice_index.slice_get_unchecked_mut_range.PreCodegen.after.panic-abort.mir
+++ b/tests/mir-opt/pre-codegen/slice_index.slice_get_unchecked_mut_range.PreCodegen.after.panic-abort.mir
@@ -19,11 +19,9 @@ fn slice_get_unchecked_mut_range(_1: &mut [u32], _2: std::ops::Range<usize>) ->
                 debug slice => _5;
                 let mut _7: *mut u32;
                 let mut _8: *mut u32;
-                let _15: usize;
-                let _16: usize;
                 scope 4 {
-                    debug ((this: std::ops::Range<usize>).0: usize) => _15;
-                    debug ((this: std::ops::Range<usize>).1: usize) => _16;
+                    debug ((this: std::ops::Range<usize>).0: usize) => _3;
+                    debug ((this: std::ops::Range<usize>).1: usize) => _4;
                     scope 5 {
                         let _6: usize;
                         scope 6 {
@@ -56,8 +54,8 @@ fn slice_get_unchecked_mut_range(_1: &mut [u32], _2: std::ops::Range<usize>) ->
                             }
                         }
                         scope 7 (inlined <std::ops::Range<usize> as SliceIndex<[T]>>::get_unchecked_mut::runtime::<u32>) {
-                            debug ((this: std::ops::Range<usize>).0: usize) => _15;
-                            debug ((this: std::ops::Range<usize>).1: usize) => _16;
+                            debug ((this: std::ops::Range<usize>).0: usize) => _3;
+                            debug ((this: std::ops::Range<usize>).1: usize) => _4;
                             debug slice => _5;
                             scope 8 (inlined ptr::mut_ptr::<impl *mut [u32]>::len) {
                                 debug self => _5;
@@ -82,8 +80,6 @@ fn slice_get_unchecked_mut_range(_1: &mut [u32], _2: std::ops::Range<usize>) ->
         _5 = &raw mut (*_1);
         StorageLive(_6);
         StorageLive(_14);
-        StorageLive(_15);
-        StorageLive(_16);
         _6 = SubUnchecked(_4, _3);
         StorageLive(_8);
         StorageLive(_7);
@@ -104,8 +100,6 @@ fn slice_get_unchecked_mut_range(_1: &mut [u32], _2: std::ops::Range<usize>) ->
         StorageDead(_12);
         StorageDead(_9);
         StorageDead(_8);
-        StorageDead(_16);
-        StorageDead(_15);
         StorageDead(_14);
         StorageDead(_6);
         StorageDead(_5);
diff --git a/tests/mir-opt/pre-codegen/slice_index.slice_get_unchecked_mut_range.PreCodegen.after.panic-unwind.mir b/tests/mir-opt/pre-codegen/slice_index.slice_get_unchecked_mut_range.PreCodegen.after.panic-unwind.mir
index 2fd669aeeb6..729841ec5ea 100644
--- a/tests/mir-opt/pre-codegen/slice_index.slice_get_unchecked_mut_range.PreCodegen.after.panic-unwind.mir
+++ b/tests/mir-opt/pre-codegen/slice_index.slice_get_unchecked_mut_range.PreCodegen.after.panic-unwind.mir
@@ -19,11 +19,9 @@ fn slice_get_unchecked_mut_range(_1: &mut [u32], _2: std::ops::Range<usize>) ->
                 debug slice => _5;
                 let mut _7: *mut u32;
                 let mut _8: *mut u32;
-                let _15: usize;
-                let _16: usize;
                 scope 4 {
-                    debug ((this: std::ops::Range<usize>).0: usize) => _15;
-                    debug ((this: std::ops::Range<usize>).1: usize) => _16;
+                    debug ((this: std::ops::Range<usize>).0: usize) => _3;
+                    debug ((this: std::ops::Range<usize>).1: usize) => _4;
                     scope 5 {
                         let _6: usize;
                         scope 6 {
@@ -56,8 +54,8 @@ fn slice_get_unchecked_mut_range(_1: &mut [u32], _2: std::ops::Range<usize>) ->
                             }
                         }
                         scope 7 (inlined <std::ops::Range<usize> as SliceIndex<[T]>>::get_unchecked_mut::runtime::<u32>) {
-                            debug ((this: std::ops::Range<usize>).0: usize) => _15;
-                            debug ((this: std::ops::Range<usize>).1: usize) => _16;
+                            debug ((this: std::ops::Range<usize>).0: usize) => _3;
+                            debug ((this: std::ops::Range<usize>).1: usize) => _4;
                             debug slice => _5;
                             scope 8 (inlined ptr::mut_ptr::<impl *mut [u32]>::len) {
                                 debug self => _5;
@@ -82,8 +80,6 @@ fn slice_get_unchecked_mut_range(_1: &mut [u32], _2: std::ops::Range<usize>) ->
         _5 = &raw mut (*_1);
         StorageLive(_6);
         StorageLive(_14);
-        StorageLive(_15);
-        StorageLive(_16);
         _6 = SubUnchecked(_4, _3);
         StorageLive(_8);
         StorageLive(_7);
@@ -104,8 +100,6 @@ fn slice_get_unchecked_mut_range(_1: &mut [u32], _2: std::ops::Range<usize>) ->
         StorageDead(_12);
         StorageDead(_9);
         StorageDead(_8);
-        StorageDead(_16);
-        StorageDead(_15);
         StorageDead(_14);
         StorageDead(_6);
         StorageDead(_5);
diff --git a/tests/mir-opt/pre-codegen/slice_iter.range_loop.PreCodegen.after.panic-abort.mir b/tests/mir-opt/pre-codegen/slice_iter.range_loop.PreCodegen.after.panic-abort.mir
index 4afe2eda188..ac1de7b4c90 100644
--- a/tests/mir-opt/pre-codegen/slice_iter.range_loop.PreCodegen.after.panic-abort.mir
+++ b/tests/mir-opt/pre-codegen/slice_iter.range_loop.PreCodegen.after.panic-abort.mir
@@ -7,43 +7,43 @@ fn range_loop(_1: &[T], _2: impl Fn(usize, &T)) -> () {
     let mut _3: usize;
     let mut _4: std::ops::Range<usize>;
     let mut _5: std::ops::Range<usize>;
-    let mut _9: std::option::Option<usize>;
-    let mut _12: isize;
-    let mut _14: usize;
-    let mut _15: bool;
-    let mut _17: &impl Fn(usize, &T);
-    let mut _18: (usize, &T);
-    let _19: ();
-    let mut _20: &mut std::ops::Range<usize>;
+    let mut _6: &mut std::ops::Range<usize>;
+    let mut _12: std::option::Option<usize>;
+    let mut _15: isize;
+    let mut _17: usize;
+    let mut _18: bool;
+    let mut _20: &impl Fn(usize, &T);
+    let mut _21: (usize, &T);
+    let _22: ();
     scope 1 {
         debug iter => _5;
-        let _13: usize;
+        let _16: usize;
         scope 2 {
-            debug i => _13;
-            let _16: &T;
+            debug i => _16;
+            let _19: &T;
             scope 3 {
-                debug x => _16;
+                debug x => _19;
             }
         }
         scope 5 (inlined iter::range::<impl Iterator for std::ops::Range<usize>>::next) {
-            debug self => _20;
+            debug self => _6;
             scope 6 (inlined <std::ops::Range<usize> as iter::range::RangeIteratorImpl>::spec_next) {
-                debug self => _20;
-                let mut _8: bool;
-                let _10: usize;
-                let mut _11: usize;
-                let mut _21: &usize;
-                let mut _22: &usize;
+                debug self => _6;
+                let mut _7: &usize;
+                let mut _8: &usize;
+                let mut _11: bool;
+                let _13: usize;
+                let mut _14: usize;
                 scope 7 {
-                    debug old => _10;
+                    debug old => _13;
                     scope 8 {
                     }
                 }
                 scope 9 (inlined cmp::impls::<impl PartialOrd for usize>::lt) {
-                    debug self => _21;
-                    debug other => _22;
-                    let mut _6: usize;
-                    let mut _7: usize;
+                    debug self => _7;
+                    debug other => _8;
+                    let mut _9: usize;
+                    let mut _10: usize;
                 }
             }
         }
@@ -63,52 +63,55 @@ fn range_loop(_1: &[T], _2: impl Fn(usize, &T)) -> () {
     }
 
     bb1: {
+        StorageLive(_12);
+        _6 = &mut _5;
+        StorageLive(_13);
+        StorageLive(_11);
+        StorageLive(_7);
+        _7 = &(_5.0: usize);
+        StorageLive(_8);
+        _8 = &(_5.1: usize);
         StorageLive(_9);
+        _9 = (_5.0: usize);
         StorageLive(_10);
-        StorageLive(_8);
-        StorageLive(_21);
-        StorageLive(_22);
-        StorageLive(_6);
-        _6 = (_5.0: usize);
-        StorageLive(_7);
-        _7 = (_5.1: usize);
-        _8 = Lt(move _6, move _7);
-        StorageDead(_7);
-        StorageDead(_6);
-        switchInt(move _8) -> [0: bb2, otherwise: bb3];
+        _10 = (_5.1: usize);
+        _11 = Lt(move _9, move _10);
+        StorageDead(_10);
+        StorageDead(_9);
+        switchInt(move _11) -> [0: bb2, otherwise: bb3];
     }
 
     bb2: {
-        StorageDead(_22);
-        StorageDead(_21);
-        _9 = Option::<usize>::None;
+        StorageDead(_8);
+        StorageDead(_7);
+        _12 = Option::<usize>::None;
         goto -> bb5;
     }
 
     bb3: {
-        StorageDead(_22);
-        StorageDead(_21);
-        _10 = (_5.0: usize);
-        StorageLive(_11);
-        _11 = <usize as Step>::forward_unchecked(_10, const 1_usize) -> [return: bb4, unwind unreachable];
+        StorageDead(_8);
+        StorageDead(_7);
+        _13 = (_5.0: usize);
+        StorageLive(_14);
+        _14 = <usize as Step>::forward_unchecked(_13, const 1_usize) -> [return: bb4, unwind unreachable];
     }
 
     bb4: {
-        (_5.0: usize) = move _11;
-        StorageDead(_11);
-        _9 = Option::<usize>::Some(_10);
+        (_5.0: usize) = move _14;
+        StorageDead(_14);
+        _12 = Option::<usize>::Some(_13);
         goto -> bb5;
     }
 
     bb5: {
-        StorageDead(_8);
-        StorageDead(_10);
-        _12 = discriminant(_9);
-        switchInt(move _12) -> [0: bb6, 1: bb8, otherwise: bb11];
+        StorageDead(_11);
+        StorageDead(_13);
+        _15 = discriminant(_12);
+        switchInt(move _15) -> [0: bb6, 1: bb8, otherwise: bb11];
     }
 
     bb6: {
-        StorageDead(_9);
+        StorageDead(_12);
         StorageDead(_5);
         drop(_2) -> [return: bb7, unwind unreachable];
     }
@@ -118,25 +121,25 @@ fn range_loop(_1: &[T], _2: impl Fn(usize, &T)) -> () {
     }
 
     bb8: {
-        _13 = ((_9 as Some).0: usize);
-        _14 = Len((*_1));
-        _15 = Lt(_13, _14);
-        assert(move _15, "index out of bounds: the length is {} but the index is {}", move _14, _13) -> [success: bb9, unwind unreachable];
+        _16 = ((_12 as Some).0: usize);
+        _17 = Len((*_1));
+        _18 = Lt(_16, _17);
+        assert(move _18, "index out of bounds: the length is {} but the index is {}", move _17, _16) -> [success: bb9, unwind unreachable];
     }
 
     bb9: {
-        _16 = &(*_1)[_13];
-        StorageLive(_17);
-        _17 = &_2;
-        StorageLive(_18);
-        _18 = (_13, _16);
-        _19 = <impl Fn(usize, &T) as Fn<(usize, &T)>>::call(move _17, move _18) -> [return: bb10, unwind unreachable];
+        _19 = &(*_1)[_16];
+        StorageLive(_20);
+        _20 = &_2;
+        StorageLive(_21);
+        _21 = (_16, _19);
+        _22 = <impl Fn(usize, &T) as Fn<(usize, &T)>>::call(move _20, move _21) -> [return: bb10, unwind unreachable];
     }
 
     bb10: {
-        StorageDead(_18);
-        StorageDead(_17);
-        StorageDead(_9);
+        StorageDead(_21);
+        StorageDead(_20);
+        StorageDead(_12);
         goto -> bb1;
     }
 
diff --git a/tests/mir-opt/pre-codegen/slice_iter.range_loop.PreCodegen.after.panic-unwind.mir b/tests/mir-opt/pre-codegen/slice_iter.range_loop.PreCodegen.after.panic-unwind.mir
index 48092608d9c..3c49ecf95a1 100644
--- a/tests/mir-opt/pre-codegen/slice_iter.range_loop.PreCodegen.after.panic-unwind.mir
+++ b/tests/mir-opt/pre-codegen/slice_iter.range_loop.PreCodegen.after.panic-unwind.mir
@@ -7,43 +7,43 @@ fn range_loop(_1: &[T], _2: impl Fn(usize, &T)) -> () {
     let mut _3: usize;
     let mut _4: std::ops::Range<usize>;
     let mut _5: std::ops::Range<usize>;
-    let mut _9: std::option::Option<usize>;
-    let mut _12: isize;
-    let mut _14: usize;
-    let mut _15: bool;
-    let mut _17: &impl Fn(usize, &T);
-    let mut _18: (usize, &T);
-    let _19: ();
-    let mut _20: &mut std::ops::Range<usize>;
+    let mut _6: &mut std::ops::Range<usize>;
+    let mut _12: std::option::Option<usize>;
+    let mut _15: isize;
+    let mut _17: usize;
+    let mut _18: bool;
+    let mut _20: &impl Fn(usize, &T);
+    let mut _21: (usize, &T);
+    let _22: ();
     scope 1 {
         debug iter => _5;
-        let _13: usize;
+        let _16: usize;
         scope 2 {
-            debug i => _13;
-            let _16: &T;
+            debug i => _16;
+            let _19: &T;
             scope 3 {
-                debug x => _16;
+                debug x => _19;
             }
         }
         scope 5 (inlined iter::range::<impl Iterator for std::ops::Range<usize>>::next) {
-            debug self => _20;
+            debug self => _6;
             scope 6 (inlined <std::ops::Range<usize> as iter::range::RangeIteratorImpl>::spec_next) {
-                debug self => _20;
-                let mut _8: bool;
-                let _10: usize;
-                let mut _11: usize;
-                let mut _21: &usize;
-                let mut _22: &usize;
+                debug self => _6;
+                let mut _7: &usize;
+                let mut _8: &usize;
+                let mut _11: bool;
+                let _13: usize;
+                let mut _14: usize;
                 scope 7 {
-                    debug old => _10;
+                    debug old => _13;
                     scope 8 {
                     }
                 }
                 scope 9 (inlined cmp::impls::<impl PartialOrd for usize>::lt) {
-                    debug self => _21;
-                    debug other => _22;
-                    let mut _6: usize;
-                    let mut _7: usize;
+                    debug self => _7;
+                    debug other => _8;
+                    let mut _9: usize;
+                    let mut _10: usize;
                 }
             }
         }
@@ -63,52 +63,55 @@ fn range_loop(_1: &[T], _2: impl Fn(usize, &T)) -> () {
     }
 
     bb1: {
+        StorageLive(_12);
+        _6 = &mut _5;
+        StorageLive(_13);
+        StorageLive(_11);
+        StorageLive(_7);
+        _7 = &(_5.0: usize);
+        StorageLive(_8);
+        _8 = &(_5.1: usize);
         StorageLive(_9);
+        _9 = (_5.0: usize);
         StorageLive(_10);
-        StorageLive(_8);
-        StorageLive(_21);
-        StorageLive(_22);
-        StorageLive(_6);
-        _6 = (_5.0: usize);
-        StorageLive(_7);
-        _7 = (_5.1: usize);
-        _8 = Lt(move _6, move _7);
-        StorageDead(_7);
-        StorageDead(_6);
-        switchInt(move _8) -> [0: bb2, otherwise: bb3];
+        _10 = (_5.1: usize);
+        _11 = Lt(move _9, move _10);
+        StorageDead(_10);
+        StorageDead(_9);
+        switchInt(move _11) -> [0: bb2, otherwise: bb3];
     }
 
     bb2: {
-        StorageDead(_22);
-        StorageDead(_21);
-        _9 = Option::<usize>::None;
+        StorageDead(_8);
+        StorageDead(_7);
+        _12 = Option::<usize>::None;
         goto -> bb5;
     }
 
     bb3: {
-        StorageDead(_22);
-        StorageDead(_21);
-        _10 = (_5.0: usize);
-        StorageLive(_11);
-        _11 = <usize as Step>::forward_unchecked(_10, const 1_usize) -> [return: bb4, unwind: bb12];
+        StorageDead(_8);
+        StorageDead(_7);
+        _13 = (_5.0: usize);
+        StorageLive(_14);
+        _14 = <usize as Step>::forward_unchecked(_13, const 1_usize) -> [return: bb4, unwind: bb12];
     }
 
     bb4: {
-        (_5.0: usize) = move _11;
-        StorageDead(_11);
-        _9 = Option::<usize>::Some(_10);
+        (_5.0: usize) = move _14;
+        StorageDead(_14);
+        _12 = Option::<usize>::Some(_13);
         goto -> bb5;
     }
 
     bb5: {
-        StorageDead(_8);
-        StorageDead(_10);
-        _12 = discriminant(_9);
-        switchInt(move _12) -> [0: bb6, 1: bb8, otherwise: bb11];
+        StorageDead(_11);
+        StorageDead(_13);
+        _15 = discriminant(_12);
+        switchInt(move _15) -> [0: bb6, 1: bb8, otherwise: bb11];
     }
 
     bb6: {
-        StorageDead(_9);
+        StorageDead(_12);
         StorageDead(_5);
         drop(_2) -> [return: bb7, unwind continue];
     }
@@ -118,25 +121,25 @@ fn range_loop(_1: &[T], _2: impl Fn(usize, &T)) -> () {
     }
 
     bb8: {
-        _13 = ((_9 as Some).0: usize);
-        _14 = Len((*_1));
-        _15 = Lt(_13, _14);
-        assert(move _15, "index out of bounds: the length is {} but the index is {}", move _14, _13) -> [success: bb9, unwind: bb12];
+        _16 = ((_12 as Some).0: usize);
+        _17 = Len((*_1));
+        _18 = Lt(_16, _17);
+        assert(move _18, "index out of bounds: the length is {} but the index is {}", move _17, _16) -> [success: bb9, unwind: bb12];
     }
 
     bb9: {
-        _16 = &(*_1)[_13];
-        StorageLive(_17);
-        _17 = &_2;
-        StorageLive(_18);
-        _18 = (_13, _16);
-        _19 = <impl Fn(usize, &T) as Fn<(usize, &T)>>::call(move _17, move _18) -> [return: bb10, unwind: bb12];
+        _19 = &(*_1)[_16];
+        StorageLive(_20);
+        _20 = &_2;
+        StorageLive(_21);
+        _21 = (_16, _19);
+        _22 = <impl Fn(usize, &T) as Fn<(usize, &T)>>::call(move _20, move _21) -> [return: bb10, unwind: bb12];
     }
 
     bb10: {
-        StorageDead(_18);
-        StorageDead(_17);
-        StorageDead(_9);
+        StorageDead(_21);
+        StorageDead(_20);
+        StorageDead(_12);
         goto -> bb1;
     }
 
diff --git a/tests/mir-opt/pre-codegen/slice_iter.reverse_loop.PreCodegen.after.panic-abort.mir b/tests/mir-opt/pre-codegen/slice_iter.reverse_loop.PreCodegen.after.panic-abort.mir
index 549cb4f46a0..f3760463fe0 100644
--- a/tests/mir-opt/pre-codegen/slice_iter.reverse_loop.PreCodegen.after.panic-abort.mir
+++ b/tests/mir-opt/pre-codegen/slice_iter.reverse_loop.PreCodegen.after.panic-abort.mir
@@ -7,21 +7,21 @@ fn reverse_loop(_1: &[T], _2: impl Fn(&T)) -> () {
     let mut _13: std::slice::Iter<'_, T>;
     let mut _14: std::iter::Rev<std::slice::Iter<'_, T>>;
     let mut _15: std::iter::Rev<std::slice::Iter<'_, T>>;
-    let mut _17: std::option::Option<&T>;
-    let mut _18: isize;
-    let mut _20: &impl Fn(&T);
-    let mut _21: (&T,);
-    let _22: ();
-    let mut _23: &mut std::iter::Rev<std::slice::Iter<'_, T>>;
+    let mut _16: &mut std::iter::Rev<std::slice::Iter<'_, T>>;
+    let mut _18: std::option::Option<&T>;
+    let mut _19: isize;
+    let mut _21: &impl Fn(&T);
+    let mut _22: (&T,);
+    let _23: ();
     scope 1 {
         debug iter => _15;
-        let _19: &T;
+        let _20: &T;
         scope 2 {
-            debug x => _19;
+            debug x => _20;
         }
         scope 25 (inlined <Rev<std::slice::Iter<'_, T>> as Iterator>::next) {
-            debug self => _23;
-            let mut _16: &mut std::slice::Iter<'_, T>;
+            debug self => _16;
+            let mut _17: &mut std::slice::Iter<'_, T>;
         }
     }
     scope 3 (inlined core::slice::<impl [T]>::iter) {
@@ -153,20 +153,21 @@ fn reverse_loop(_1: &[T], _2: impl Fn(&T)) -> () {
     }
 
     bb4: {
+        StorageLive(_18);
+        _16 = &mut _15;
         StorageLive(_17);
-        StorageLive(_16);
-        _16 = &mut (_15.0: std::slice::Iter<'_, T>);
-        _17 = <std::slice::Iter<'_, T> as DoubleEndedIterator>::next_back(move _16) -> [return: bb5, unwind unreachable];
+        _17 = &mut (_15.0: std::slice::Iter<'_, T>);
+        _18 = <std::slice::Iter<'_, T> as DoubleEndedIterator>::next_back(move _17) -> [return: bb5, unwind unreachable];
     }
 
     bb5: {
-        StorageDead(_16);
-        _18 = discriminant(_17);
-        switchInt(move _18) -> [0: bb6, 1: bb8, otherwise: bb10];
+        StorageDead(_17);
+        _19 = discriminant(_18);
+        switchInt(move _19) -> [0: bb6, 1: bb8, otherwise: bb10];
     }
 
     bb6: {
-        StorageDead(_17);
+        StorageDead(_18);
         StorageDead(_15);
         drop(_2) -> [return: bb7, unwind unreachable];
     }
@@ -176,18 +177,18 @@ fn reverse_loop(_1: &[T], _2: impl Fn(&T)) -> () {
     }
 
     bb8: {
-        _19 = ((_17 as Some).0: &T);
-        StorageLive(_20);
-        _20 = &_2;
+        _20 = ((_18 as Some).0: &T);
         StorageLive(_21);
-        _21 = (_19,);
-        _22 = <impl Fn(&T) as Fn<(&T,)>>::call(move _20, move _21) -> [return: bb9, unwind unreachable];
+        _21 = &_2;
+        StorageLive(_22);
+        _22 = (_20,);
+        _23 = <impl Fn(&T) as Fn<(&T,)>>::call(move _21, move _22) -> [return: bb9, unwind unreachable];
     }
 
     bb9: {
+        StorageDead(_22);
         StorageDead(_21);
-        StorageDead(_20);
-        StorageDead(_17);
+        StorageDead(_18);
         goto -> bb4;
     }
 
diff --git a/tests/mir-opt/pre-codegen/slice_iter.reverse_loop.PreCodegen.after.panic-unwind.mir b/tests/mir-opt/pre-codegen/slice_iter.reverse_loop.PreCodegen.after.panic-unwind.mir
index 3cdc49f6056..e63f8b89308 100644
--- a/tests/mir-opt/pre-codegen/slice_iter.reverse_loop.PreCodegen.after.panic-unwind.mir
+++ b/tests/mir-opt/pre-codegen/slice_iter.reverse_loop.PreCodegen.after.panic-unwind.mir
@@ -7,21 +7,21 @@ fn reverse_loop(_1: &[T], _2: impl Fn(&T)) -> () {
     let mut _13: std::slice::Iter<'_, T>;
     let mut _14: std::iter::Rev<std::slice::Iter<'_, T>>;
     let mut _15: std::iter::Rev<std::slice::Iter<'_, T>>;
-    let mut _17: std::option::Option<&T>;
-    let mut _18: isize;
-    let mut _20: &impl Fn(&T);
-    let mut _21: (&T,);
-    let _22: ();
-    let mut _23: &mut std::iter::Rev<std::slice::Iter<'_, T>>;
+    let mut _16: &mut std::iter::Rev<std::slice::Iter<'_, T>>;
+    let mut _18: std::option::Option<&T>;
+    let mut _19: isize;
+    let mut _21: &impl Fn(&T);
+    let mut _22: (&T,);
+    let _23: ();
     scope 1 {
         debug iter => _15;
-        let _19: &T;
+        let _20: &T;
         scope 2 {
-            debug x => _19;
+            debug x => _20;
         }
         scope 25 (inlined <Rev<std::slice::Iter<'_, T>> as Iterator>::next) {
-            debug self => _23;
-            let mut _16: &mut std::slice::Iter<'_, T>;
+            debug self => _16;
+            let mut _17: &mut std::slice::Iter<'_, T>;
         }
     }
     scope 3 (inlined core::slice::<impl [T]>::iter) {
@@ -153,20 +153,21 @@ fn reverse_loop(_1: &[T], _2: impl Fn(&T)) -> () {
     }
 
     bb4: {
+        StorageLive(_18);
+        _16 = &mut _15;
         StorageLive(_17);
-        StorageLive(_16);
-        _16 = &mut (_15.0: std::slice::Iter<'_, T>);
-        _17 = <std::slice::Iter<'_, T> as DoubleEndedIterator>::next_back(move _16) -> [return: bb5, unwind: bb11];
+        _17 = &mut (_15.0: std::slice::Iter<'_, T>);
+        _18 = <std::slice::Iter<'_, T> as DoubleEndedIterator>::next_back(move _17) -> [return: bb5, unwind: bb11];
     }
 
     bb5: {
-        StorageDead(_16);
-        _18 = discriminant(_17);
-        switchInt(move _18) -> [0: bb6, 1: bb8, otherwise: bb10];
+        StorageDead(_17);
+        _19 = discriminant(_18);
+        switchInt(move _19) -> [0: bb6, 1: bb8, otherwise: bb10];
     }
 
     bb6: {
-        StorageDead(_17);
+        StorageDead(_18);
         StorageDead(_15);
         drop(_2) -> [return: bb7, unwind continue];
     }
@@ -176,18 +177,18 @@ fn reverse_loop(_1: &[T], _2: impl Fn(&T)) -> () {
     }
 
     bb8: {
-        _19 = ((_17 as Some).0: &T);
-        StorageLive(_20);
-        _20 = &_2;
+        _20 = ((_18 as Some).0: &T);
         StorageLive(_21);
-        _21 = (_19,);
-        _22 = <impl Fn(&T) as Fn<(&T,)>>::call(move _20, move _21) -> [return: bb9, unwind: bb11];
+        _21 = &_2;
+        StorageLive(_22);
+        _22 = (_20,);
+        _23 = <impl Fn(&T) as Fn<(&T,)>>::call(move _21, move _22) -> [return: bb9, unwind: bb11];
     }
 
     bb9: {
+        StorageDead(_22);
         StorageDead(_21);
-        StorageDead(_20);
-        StorageDead(_17);
+        StorageDead(_18);
         goto -> bb4;
     }
 
diff --git a/tests/ui/linkage-attr/unstable-flavor.bpf.stderr b/tests/ui/linkage-attr/unstable-flavor.bpf.stderr
index 594a461769b..819da2fb017 100644
--- a/tests/ui/linkage-attr/unstable-flavor.bpf.stderr
+++ b/tests/ui/linkage-attr/unstable-flavor.bpf.stderr
@@ -1,2 +1,2 @@
-error: the linker flavor `bpf-linker` is unstable, the `-Z unstable-options` flag must also be passed to use the unstable values
+error: the linker flavor `bpf` is unstable, the `-Z unstable-options` flag must also be passed to use the unstable values
 
diff --git a/tests/ui/linkage-attr/unstable-flavor.ptx.stderr b/tests/ui/linkage-attr/unstable-flavor.ptx.stderr
index 714c09df53f..2ebdc1a9033 100644
--- a/tests/ui/linkage-attr/unstable-flavor.ptx.stderr
+++ b/tests/ui/linkage-attr/unstable-flavor.ptx.stderr
@@ -1,2 +1,2 @@
-error: the linker flavor `ptx-linker` is unstable, the `-Z unstable-options` flag must also be passed to use the unstable values
+error: the linker flavor `ptx` is unstable, the `-Z unstable-options` flag must also be passed to use the unstable values
 
diff --git a/tests/ui/linkage-attr/unstable-flavor.rs b/tests/ui/linkage-attr/unstable-flavor.rs
index b58fd055fdc..c2c16b28bff 100644
--- a/tests/ui/linkage-attr/unstable-flavor.rs
+++ b/tests/ui/linkage-attr/unstable-flavor.rs
@@ -3,11 +3,11 @@
 // caller). If it passes, all the other unstable options are rejected as well.
 //
 // revisions: bpf ptx
-// [bpf] compile-flags: --target=bpfel-unknown-none -C linker-flavor=bpf-linker --crate-type=rlib
-// [bpf] error-pattern: linker flavor `bpf-linker` is unstable, the `-Z unstable-options` flag
+// [bpf] compile-flags: --target=bpfel-unknown-none -C linker-flavor=bpf --crate-type=rlib
+// [bpf] error-pattern: linker flavor `bpf` is unstable, the `-Z unstable-options` flag
 // [bpf] needs-llvm-components:
-// [ptx] compile-flags: --target=nvptx64-nvidia-cuda -C linker-flavor=ptx-linker --crate-type=rlib
-// [ptx] error-pattern: linker flavor `ptx-linker` is unstable, the `-Z unstable-options` flag
+// [ptx] compile-flags: --target=nvptx64-nvidia-cuda -C linker-flavor=ptx --crate-type=rlib
+// [ptx] error-pattern: linker flavor `ptx` is unstable, the `-Z unstable-options` flag
 // [ptx] needs-llvm-components:
 
 #![feature(no_core)]