From d8f39d32f89e33842d8ffc9222f88b45058c4a28 Mon Sep 17 00:00:00 2001 From: Ohad Ravid Date: Tue, 3 Jun 2025 07:36:50 +0300 Subject: [PATCH 01/14] Added a mir-opt test for generating storage statements for scoped locals --- ...sue_141649.main.CopyProp.panic-unwind.diff | 100 ++++++++++++++++++ tests/mir-opt/copy-prop/issue_141649.rs | 27 +++++ 2 files changed, 127 insertions(+) create mode 100644 tests/mir-opt/copy-prop/issue_141649.main.CopyProp.panic-unwind.diff create mode 100644 tests/mir-opt/copy-prop/issue_141649.rs diff --git a/tests/mir-opt/copy-prop/issue_141649.main.CopyProp.panic-unwind.diff b/tests/mir-opt/copy-prop/issue_141649.main.CopyProp.panic-unwind.diff new file mode 100644 index 0000000000000..e02fe72a47a7b --- /dev/null +++ b/tests/mir-opt/copy-prop/issue_141649.main.CopyProp.panic-unwind.diff @@ -0,0 +1,100 @@ +- // MIR for `main` before CopyProp ++ // MIR for `main` after CopyProp + + fn main() -> () { + let mut _0: (); + let _1: (); + let _2: main::S; + let _3: (); + let mut _4: main::S; + let _5: (); + let _6: main::S; + let _7: (); + let mut _8: main::S; + let _9: (); + let _10: main::C; + let _11: (); + let mut _12: main::C; + let _13: main::C; + let _14: (); + let mut _15: main::C; + scope 1 { + debug s1 => _2; + } + scope 2 { + debug s2 => _6; + } + scope 3 { + debug c1 => _10; + } + scope 4 { + debug c2 => _13; + } + + bb0: { +- StorageLive(_1); +- StorageLive(_2); + _2 = S(const 1_usize, const 2_usize); + StorageLive(_3); +- StorageLive(_4); +- _4 = move _2; +- _3 = std::mem::drop::(move _4) -> [return: bb1, unwind continue]; ++ _3 = std::mem::drop::(move _2) -> [return: bb1, unwind continue]; + } + + bb1: { +- StorageDead(_4); + StorageDead(_3); +- _1 = const (); +- StorageDead(_2); +- StorageDead(_1); +- StorageLive(_5); +- StorageLive(_6); + _6 = S(const 3_usize, const 4_usize); + StorageLive(_7); +- StorageLive(_8); +- _8 = move _6; +- _7 = std::mem::drop::(move _8) -> [return: bb2, unwind continue]; ++ _7 = std::mem::drop::(move _6) -> [return: bb2, unwind continue]; + } + + bb2: { +- StorageDead(_8); + StorageDead(_7); +- _5 = const (); +- StorageDead(_6); +- StorageDead(_5); +- StorageLive(_9); +- StorageLive(_10); + _10 = C(const 1_usize, const 2_usize); + StorageLive(_11); +- StorageLive(_12); +- _12 = copy _10; +- _11 = std::mem::drop::(move _12) -> [return: bb3, unwind continue]; ++ _11 = std::mem::drop::(copy _10) -> [return: bb3, unwind continue]; + } + + bb3: { +- StorageDead(_12); + StorageDead(_11); +- _9 = const (); +- StorageDead(_10); +- StorageDead(_9); +- StorageLive(_13); + _13 = C(const 3_usize, const 4_usize); + StorageLive(_14); +- StorageLive(_15); +- _15 = copy _13; +- _14 = std::mem::drop::(move _15) -> [return: bb4, unwind continue]; ++ _14 = std::mem::drop::(copy _13) -> [return: bb4, unwind continue]; + } + + bb4: { +- StorageDead(_15); + StorageDead(_14); + _0 = const (); +- StorageDead(_13); + return; + } + } + diff --git a/tests/mir-opt/copy-prop/issue_141649.rs b/tests/mir-opt/copy-prop/issue_141649.rs new file mode 100644 index 0000000000000..3227c47bcc72c --- /dev/null +++ b/tests/mir-opt/copy-prop/issue_141649.rs @@ -0,0 +1,27 @@ +// skip-filecheck +// EMIT_MIR_FOR_EACH_PANIC_STRATEGY +//@ test-mir-pass: CopyProp + +// EMIT_MIR issue_141649.main.CopyProp.diff +fn main() { + struct S(usize, usize); + { + let s1 = S(1, 2); + drop(s1); + } + { + let s2 = S(3, 4); + drop(s2); + } + + #[derive(Clone, Copy)] + struct C(usize, usize); + { + let c1 = C(1, 2); + drop(c1); + } + { + let c2 = C(3, 4); + drop(c2); + } +} From 2679fffb9d6e93d834d905dcc9ada705b199921f Mon Sep 17 00:00:00 2001 From: Ohad Ravid Date: Tue, 3 Jun 2025 07:49:56 +0300 Subject: [PATCH 02/14] Implement `MaybeUninitializedLocals` analysis for `copy_prop` mir-opt to remove fewer storage statements --- .../src/impls/initialized.rs | 74 +++++++++ compiler/rustc_mir_dataflow/src/impls/mod.rs | 2 +- compiler/rustc_mir_transform/src/copy_prop.rs | 96 +++++++++++- ...rrowed_storage_not_removed.f.CopyProp.diff | 21 +++ .../copy_prop_borrowed_storage_not_removed.rs | 30 ++++ ...rop_storage_twice.dead_twice.CopyProp.diff | 28 ++++ ...rop_storage_twice.live_twice.CopyProp.diff | 27 ++++ .../copy-prop/copy_prop_storage_twice.rs | 61 ++++++++ .../cycle.main.CopyProp.panic-abort.diff | 4 +- .../cycle.main.CopyProp.panic-unwind.diff | 4 +- ...res_79191.f.CopyProp.after.panic-abort.mir | 2 + ...es_79191.f.CopyProp.after.panic-unwind.mir | 2 + ...es_better.f.CopyProp.after.panic-abort.mir | 2 + ...s_better.f.CopyProp.after.panic-unwind.mir | 2 + ...ssue_107511.main.CopyProp.panic-abort.diff | 4 +- ...sue_107511.main.CopyProp.panic-unwind.diff | 4 +- ...ssue_141649.main.CopyProp.panic-abort.diff | 142 ++++++++++++++++++ ...sue_141649.main.CopyProp.panic-unwind.diff | 100 ++++++++---- tests/mir-opt/copy-prop/issue_141649.rs | 11 ++ ...41649_debug.main.CopyProp.panic-abort.diff | 100 ++++++++++++ ...1649_debug.main.CopyProp.panic-unwind.diff | 100 ++++++++++++ tests/mir-opt/copy-prop/issue_141649_debug.rs | 29 ++++ ...reborrow.demiraw.CopyProp.panic-abort.diff | 4 +- ...eborrow.demiraw.CopyProp.panic-unwind.diff | 4 +- .../reborrow.miraw.CopyProp.panic-abort.diff | 4 +- .../reborrow.miraw.CopyProp.panic-unwind.diff | 4 +- .../reborrow.remut.CopyProp.panic-abort.diff | 4 +- .../reborrow.remut.CopyProp.panic-unwind.diff | 4 +- .../reborrow.reraw.CopyProp.panic-abort.diff | 4 +- .../reborrow.reraw.CopyProp.panic-unwind.diff | 4 +- ....foo.SimplifyLocals-final.panic-abort.diff | 2 + ...foo.SimplifyLocals-final.panic-unwind.diff | 2 + 32 files changed, 823 insertions(+), 58 deletions(-) create mode 100644 tests/mir-opt/copy-prop/copy_prop_borrowed_storage_not_removed.f.CopyProp.diff create mode 100644 tests/mir-opt/copy-prop/copy_prop_borrowed_storage_not_removed.rs create mode 100644 tests/mir-opt/copy-prop/copy_prop_storage_twice.dead_twice.CopyProp.diff create mode 100644 tests/mir-opt/copy-prop/copy_prop_storage_twice.live_twice.CopyProp.diff create mode 100644 tests/mir-opt/copy-prop/copy_prop_storage_twice.rs create mode 100644 tests/mir-opt/copy-prop/issue_141649.main.CopyProp.panic-abort.diff create mode 100644 tests/mir-opt/copy-prop/issue_141649_debug.main.CopyProp.panic-abort.diff create mode 100644 tests/mir-opt/copy-prop/issue_141649_debug.main.CopyProp.panic-unwind.diff create mode 100644 tests/mir-opt/copy-prop/issue_141649_debug.rs diff --git a/compiler/rustc_mir_dataflow/src/impls/initialized.rs b/compiler/rustc_mir_dataflow/src/impls/initialized.rs index 18165b0b9bd08..961a6d42891ed 100644 --- a/compiler/rustc_mir_dataflow/src/impls/initialized.rs +++ b/compiler/rustc_mir_dataflow/src/impls/initialized.rs @@ -558,6 +558,80 @@ impl<'tcx> Analysis<'tcx> for MaybeUninitializedPlaces<'_, 'tcx> { } } +/// A dataflow analysis that tracks locals that are maybe uninitialized. +/// +/// This is a simpler analysis than `MaybeUninitializedPlaces`, because it does not track +/// individual fields. +pub struct MaybeUninitializedLocals; + +impl MaybeUninitializedLocals { + pub fn new() -> Self { + Self {} + } +} + +impl<'tcx> Analysis<'tcx> for MaybeUninitializedLocals { + type Domain = DenseBitSet; + + const NAME: &'static str = "maybe_uninit_locals"; + + fn bottom_value(&self, body: &Body<'tcx>) -> Self::Domain { + // bottom = all locals are initialized. + DenseBitSet::new_empty(body.local_decls.len()) + } + + fn initialize_start_block(&self, body: &Body<'tcx>, state: &mut Self::Domain) { + // All locals start as uninitialized... + state.insert_all(); + // ...except for arguments, which are definitely initialized. + for arg in body.args_iter() { + state.remove(arg); + } + } + + fn apply_primary_statement_effect( + &mut self, + state: &mut Self::Domain, + statement: &mir::Statement<'tcx>, + _location: Location, + ) { + match statement.kind { + // An assignment makes a local initialized. + mir::StatementKind::Assign(box (place, _)) => { + if let Some(local) = place.as_local() { + state.remove(local); + } + } + // Deinit makes the local uninitialized. + mir::StatementKind::Deinit(box place) => { + // A deinit makes a local uninitialized. + if let Some(local) = place.as_local() { + state.insert(local); + } + } + // Storage{Live,Dead} makes a local uninitialized. + mir::StatementKind::StorageLive(local) | mir::StatementKind::StorageDead(local) => { + state.insert(local); + } + _ => {} + } + } + + fn apply_call_return_effect( + &mut self, + state: &mut Self::Domain, + _block: mir::BasicBlock, + return_places: CallReturnPlaces<'_, 'tcx>, + ) { + // The return place of a call is initialized. + return_places.for_each(|place| { + if let Some(local) = place.as_local() { + state.remove(local); + } + }); + } +} + /// There can be many more `InitIndex` than there are locals in a MIR body. /// We use a mixed bitset to avoid paying too high a memory footprint. pub type EverInitializedPlacesDomain = MixedBitSet; diff --git a/compiler/rustc_mir_dataflow/src/impls/mod.rs b/compiler/rustc_mir_dataflow/src/impls/mod.rs index 3f29b819a6d18..695298529c19c 100644 --- a/compiler/rustc_mir_dataflow/src/impls/mod.rs +++ b/compiler/rustc_mir_dataflow/src/impls/mod.rs @@ -6,7 +6,7 @@ mod storage_liveness; pub use self::borrowed_locals::{MaybeBorrowedLocals, borrowed_locals}; pub use self::initialized::{ EverInitializedPlaces, EverInitializedPlacesDomain, MaybeInitializedPlaces, - MaybeUninitializedPlaces, MaybeUninitializedPlacesDomain, + MaybeUninitializedLocals, MaybeUninitializedPlaces, MaybeUninitializedPlacesDomain, }; pub use self::liveness::{ MaybeLiveLocals, MaybeTransitiveLiveLocals, TransferFunction as LivenessTransferFunction, diff --git a/compiler/rustc_mir_transform/src/copy_prop.rs b/compiler/rustc_mir_transform/src/copy_prop.rs index cddeefca68174..d6d1ebda033c6 100644 --- a/compiler/rustc_mir_transform/src/copy_prop.rs +++ b/compiler/rustc_mir_transform/src/copy_prop.rs @@ -3,6 +3,8 @@ use rustc_index::bit_set::DenseBitSet; use rustc_middle::mir::visit::*; use rustc_middle::mir::*; use rustc_middle::ty::TyCtxt; +use rustc_mir_dataflow::impls::MaybeUninitializedLocals; +use rustc_mir_dataflow::{Analysis, ResultsCursor}; use tracing::{debug, instrument}; use crate::ssa::SsaLocals; @@ -16,7 +18,7 @@ use crate::ssa::SsaLocals; /// _d = move? _c /// where each of the locals is only assigned once. /// -/// We want to replace all those locals by `_a`, either copied or moved. +/// We want to replace all those locals by `_a` (the "head"), either copied or moved. pub(super) struct CopyProp; impl<'tcx> crate::MirPass<'tcx> for CopyProp { @@ -30,15 +32,30 @@ impl<'tcx> crate::MirPass<'tcx> for CopyProp { let typing_env = body.typing_env(tcx); let ssa = SsaLocals::new(tcx, body, typing_env); - debug!(borrowed_locals = ?ssa.borrowed_locals()); + let borrowed_locals = ssa.borrowed_locals().clone(); + + debug!(?borrowed_locals); debug!(copy_classes = ?ssa.copy_classes()); let mut any_replacement = false; - let mut storage_to_remove = DenseBitSet::new_empty(body.local_decls.len()); + let fully_moved = fully_moved_locals(&ssa, body); + debug!(?fully_moved); + + let mut head_storage_to_check = DenseBitSet::new_empty(fully_moved.domain_size()); + let mut storage_to_remove = DenseBitSet::new_empty(fully_moved.domain_size()); + for (local, &head) in ssa.copy_classes().iter_enumerated() { if local != head { any_replacement = true; - storage_to_remove.insert(head); + // We need to determine if we can keep the head's storage statements (which enables better optimizations). + // For every local's usage location, if the head is maybe-uninitialized, we'll need to remove it's storage statements. + head_storage_to_check.insert(head); + + if borrowed_locals.contains(local) { + // To keep the storage of a head, we require that none of the locals in it's copy class are borrowed, + // since otherwise we cannot easily identify when it is used. + storage_to_remove.insert(head); + } } } @@ -49,6 +66,29 @@ impl<'tcx> crate::MirPass<'tcx> for CopyProp { let fully_moved = fully_moved_locals(&ssa, body); debug!(?fully_moved); + // Debug builds have no use for the storage statements, so avoid extra work. + let storage_to_remove = if any_replacement && tcx.sess.emit_lifetime_markers() { + let maybe_uninit = MaybeUninitializedLocals::new() + .iterate_to_fixpoint(tcx, body, Some("mir_opt::copy_prop")) + .into_results_cursor(body); + + let mut storage_checker = StorageChecker { + maybe_uninit, + copy_classes: ssa.copy_classes(), + head_storage_to_check, + storage_to_remove, + }; + + storage_checker.visit_body(body); + + storage_checker.storage_to_remove + } else { + // Conservatively remove all storage statements for the head locals. + head_storage_to_check + }; + + debug!(?storage_to_remove); + Replacer { tcx, copy_classes: ssa.copy_classes(), fully_moved, storage_to_remove } .visit_body_preserves_cfg(body); @@ -154,3 +194,51 @@ impl<'tcx> MutVisitor<'tcx> for Replacer<'_, 'tcx> { } } } + +// Marks heads of copy classes that are maybe uninitialized at the location of a local +// as needing storage statement removal. +struct StorageChecker<'a, 'tcx> { + maybe_uninit: ResultsCursor<'a, 'tcx, MaybeUninitializedLocals>, + copy_classes: &'a IndexSlice, + head_storage_to_check: DenseBitSet, + storage_to_remove: DenseBitSet, +} + +impl<'a, 'tcx> Visitor<'tcx> for StorageChecker<'a, 'tcx> { + fn visit_local(&mut self, local: Local, context: PlaceContext, loc: Location) { + // We don't need to check storage statements and statements for which the local doesn't need to be initialized. + match context { + PlaceContext::MutatingUse( + MutatingUseContext::Store + | MutatingUseContext::Call + | MutatingUseContext::Yield + | MutatingUseContext::AsmOutput, + ) + | PlaceContext::NonUse(_) => { + return; + } + _ => {} + }; + + let head = self.copy_classes[local]; + + // The head must be initialized at the location of the local, otherwise we must remove it's storage statements. + if self.head_storage_to_check.contains(head) { + self.maybe_uninit.seek_before_primary_effect(loc); + + if self.maybe_uninit.get().contains(head) { + debug!( + ?loc, + ?context, + ?local, + ?head, + "found a head at a location in which it is maybe uninit, marking head for storage statement removal" + ); + self.storage_to_remove.insert(head); + + // Once we found a use of the head that is maybe uninit, we do not need to check it again. + self.head_storage_to_check.remove(head); + } + } + } +} diff --git a/tests/mir-opt/copy-prop/copy_prop_borrowed_storage_not_removed.f.CopyProp.diff b/tests/mir-opt/copy-prop/copy_prop_borrowed_storage_not_removed.f.CopyProp.diff new file mode 100644 index 0000000000000..782b053cf2240 --- /dev/null +++ b/tests/mir-opt/copy-prop/copy_prop_borrowed_storage_not_removed.f.CopyProp.diff @@ -0,0 +1,21 @@ +- // MIR for `f` before CopyProp ++ // MIR for `f` after CopyProp + + fn f(_1: (T, T)) -> T { + let mut _0: T; + let mut _2: T; + let mut _3: T; + let mut _4: &T; + + bb0: { +- StorageLive(_2); + _2 = copy (_1.0: T); +- _3 = copy _2; +- _4 = &_3; +- StorageDead(_2); ++ _4 = &_2; + _0 = copy (*_4); + return; + } + } + diff --git a/tests/mir-opt/copy-prop/copy_prop_borrowed_storage_not_removed.rs b/tests/mir-opt/copy-prop/copy_prop_borrowed_storage_not_removed.rs new file mode 100644 index 0000000000000..39a3fda47a8e5 --- /dev/null +++ b/tests/mir-opt/copy-prop/copy_prop_borrowed_storage_not_removed.rs @@ -0,0 +1,30 @@ +// skip-filecheck +//@ test-mir-pass: CopyProp + +#![feature(custom_mir, core_intrinsics, freeze)] + +// Check that we remove the storage statements if one of the locals is borrowed, +// and the head isn't borrowed. + +use std::intrinsics::mir::*; +use std::marker::Freeze; + +// EMIT_MIR copy_prop_borrowed_storage_not_removed.f.CopyProp.diff + +#[custom_mir(dialect = "runtime")] +pub fn f(_1: (T, T)) -> T { + mir! { + let _2: T; + let _3: T; + let _4: &T; + { + StorageLive(_2); + _2 = _1.0; + _3 = _2; + _4 = &_3; + StorageDead(_2); + RET = *_4; + Return() + } + } +} diff --git a/tests/mir-opt/copy-prop/copy_prop_storage_twice.dead_twice.CopyProp.diff b/tests/mir-opt/copy-prop/copy_prop_storage_twice.dead_twice.CopyProp.diff new file mode 100644 index 0000000000000..0eb86de527219 --- /dev/null +++ b/tests/mir-opt/copy-prop/copy_prop_storage_twice.dead_twice.CopyProp.diff @@ -0,0 +1,28 @@ +- // MIR for `dead_twice` before CopyProp ++ // MIR for `dead_twice` after CopyProp + + fn dead_twice(_1: T) -> T { + let mut _0: T; + let mut _2: T; + let mut _3: T; + let mut _4: T; + + bb0: { +- StorageLive(_2); + _2 = opaque::(move _1) -> [return: bb1, unwind unreachable]; + } + + bb1: { +- _4 = move _2; +- StorageDead(_2); +- StorageLive(_2); +- _0 = opaque::(move _4) -> [return: bb2, unwind unreachable]; ++ _0 = opaque::(move _2) -> [return: bb2, unwind unreachable]; + } + + bb2: { +- StorageDead(_2); + return; + } + } + diff --git a/tests/mir-opt/copy-prop/copy_prop_storage_twice.live_twice.CopyProp.diff b/tests/mir-opt/copy-prop/copy_prop_storage_twice.live_twice.CopyProp.diff new file mode 100644 index 0000000000000..01b59b547eaa8 --- /dev/null +++ b/tests/mir-opt/copy-prop/copy_prop_storage_twice.live_twice.CopyProp.diff @@ -0,0 +1,27 @@ +- // MIR for `live_twice` before CopyProp ++ // MIR for `live_twice` after CopyProp + + fn live_twice(_1: T) -> T { + let mut _0: T; + let mut _2: T; + let mut _3: T; + let mut _4: T; + + bb0: { +- StorageLive(_2); + _2 = opaque::(move _1) -> [return: bb1, unwind unreachable]; + } + + bb1: { +- _4 = move _2; +- StorageLive(_2); +- _0 = opaque::(copy _4) -> [return: bb2, unwind unreachable]; ++ _0 = opaque::(copy _2) -> [return: bb2, unwind unreachable]; + } + + bb2: { +- StorageDead(_2); + return; + } + } + diff --git a/tests/mir-opt/copy-prop/copy_prop_storage_twice.rs b/tests/mir-opt/copy-prop/copy_prop_storage_twice.rs new file mode 100644 index 0000000000000..421bb55d62ecc --- /dev/null +++ b/tests/mir-opt/copy-prop/copy_prop_storage_twice.rs @@ -0,0 +1,61 @@ +// skip-filecheck +//@ test-mir-pass: CopyProp +//@ compile-flags: -Zlint-mir=false + +#![feature(custom_mir, core_intrinsics)] + +// Check that we remove the storage statements if the head +// becomes uninitialized before it is used again. + +use std::intrinsics::mir::*; + +// EMIT_MIR copy_prop_storage_twice.dead_twice.CopyProp.diff +// EMIT_MIR copy_prop_storage_twice.live_twice.CopyProp.diff + +#[custom_mir(dialect = "runtime")] +pub fn dead_twice(_1: T) -> T { + mir! { + let _2: T; + let _3: T; + { + StorageLive(_2); + Call(_2 = opaque(Move(_1)), ReturnTo(bb1), UnwindUnreachable()) + } + bb1 = { + let _3 = Move(_2); + StorageDead(_2); + StorageLive(_2); + Call(RET = opaque(Move(_3)), ReturnTo(bb2), UnwindUnreachable()) + } + bb2 = { + StorageDead(_2); + Return() + } + } +} + +#[custom_mir(dialect = "runtime")] +pub fn live_twice(_1: T) -> T { + mir! { + let _2: T; + let _3: T; + { + StorageLive(_2); + Call(_2 = opaque(Move(_1)), ReturnTo(bb1), UnwindUnreachable()) + } + bb1 = { + let _3 = Move(_2); + StorageLive(_2); + Call(RET = opaque(_3), ReturnTo(bb2), UnwindUnreachable()) + } + bb2 = { + StorageDead(_2); + Return() + } + } +} + +#[inline(never)] +fn opaque(a: T) -> T { + a +} diff --git a/tests/mir-opt/copy-prop/cycle.main.CopyProp.panic-abort.diff b/tests/mir-opt/copy-prop/cycle.main.CopyProp.panic-abort.diff index d133091e6a438..f11685467fd7d 100644 --- a/tests/mir-opt/copy-prop/cycle.main.CopyProp.panic-abort.diff +++ b/tests/mir-opt/copy-prop/cycle.main.CopyProp.panic-abort.diff @@ -26,7 +26,7 @@ } bb1: { -- StorageLive(_2); + StorageLive(_2); _2 = copy _1; - StorageLive(_3); - _3 = copy _2; @@ -46,7 +46,7 @@ StorageDead(_5); _0 = const (); - StorageDead(_3); -- StorageDead(_2); + StorageDead(_2); StorageDead(_1); return; } diff --git a/tests/mir-opt/copy-prop/cycle.main.CopyProp.panic-unwind.diff b/tests/mir-opt/copy-prop/cycle.main.CopyProp.panic-unwind.diff index bd4ad737cec13..bf5d8d20b7a10 100644 --- a/tests/mir-opt/copy-prop/cycle.main.CopyProp.panic-unwind.diff +++ b/tests/mir-opt/copy-prop/cycle.main.CopyProp.panic-unwind.diff @@ -26,7 +26,7 @@ } bb1: { -- StorageLive(_2); + StorageLive(_2); _2 = copy _1; - StorageLive(_3); - _3 = copy _2; @@ -46,7 +46,7 @@ StorageDead(_5); _0 = const (); - StorageDead(_3); -- StorageDead(_2); + StorageDead(_2); StorageDead(_1); return; } diff --git a/tests/mir-opt/copy-prop/dead_stores_79191.f.CopyProp.after.panic-abort.mir b/tests/mir-opt/copy-prop/dead_stores_79191.f.CopyProp.after.panic-abort.mir index 4781fdfd902a4..90bd2b8e07a8f 100644 --- a/tests/mir-opt/copy-prop/dead_stores_79191.f.CopyProp.after.panic-abort.mir +++ b/tests/mir-opt/copy-prop/dead_stores_79191.f.CopyProp.after.panic-abort.mir @@ -11,6 +11,7 @@ fn f(_1: usize) -> usize { } bb0: { + StorageLive(_2); _2 = copy _1; _1 = const 5_usize; _1 = copy _2; @@ -21,6 +22,7 @@ fn f(_1: usize) -> usize { bb1: { StorageDead(_4); + StorageDead(_2); return; } } diff --git a/tests/mir-opt/copy-prop/dead_stores_79191.f.CopyProp.after.panic-unwind.mir b/tests/mir-opt/copy-prop/dead_stores_79191.f.CopyProp.after.panic-unwind.mir index f5fded45c13b4..72b51f0b60a7b 100644 --- a/tests/mir-opt/copy-prop/dead_stores_79191.f.CopyProp.after.panic-unwind.mir +++ b/tests/mir-opt/copy-prop/dead_stores_79191.f.CopyProp.after.panic-unwind.mir @@ -11,6 +11,7 @@ fn f(_1: usize) -> usize { } bb0: { + StorageLive(_2); _2 = copy _1; _1 = const 5_usize; _1 = copy _2; @@ -21,6 +22,7 @@ fn f(_1: usize) -> usize { bb1: { StorageDead(_4); + StorageDead(_2); return; } } diff --git a/tests/mir-opt/copy-prop/dead_stores_better.f.CopyProp.after.panic-abort.mir b/tests/mir-opt/copy-prop/dead_stores_better.f.CopyProp.after.panic-abort.mir index 4781fdfd902a4..90bd2b8e07a8f 100644 --- a/tests/mir-opt/copy-prop/dead_stores_better.f.CopyProp.after.panic-abort.mir +++ b/tests/mir-opt/copy-prop/dead_stores_better.f.CopyProp.after.panic-abort.mir @@ -11,6 +11,7 @@ fn f(_1: usize) -> usize { } bb0: { + StorageLive(_2); _2 = copy _1; _1 = const 5_usize; _1 = copy _2; @@ -21,6 +22,7 @@ fn f(_1: usize) -> usize { bb1: { StorageDead(_4); + StorageDead(_2); return; } } diff --git a/tests/mir-opt/copy-prop/dead_stores_better.f.CopyProp.after.panic-unwind.mir b/tests/mir-opt/copy-prop/dead_stores_better.f.CopyProp.after.panic-unwind.mir index f5fded45c13b4..72b51f0b60a7b 100644 --- a/tests/mir-opt/copy-prop/dead_stores_better.f.CopyProp.after.panic-unwind.mir +++ b/tests/mir-opt/copy-prop/dead_stores_better.f.CopyProp.after.panic-unwind.mir @@ -11,6 +11,7 @@ fn f(_1: usize) -> usize { } bb0: { + StorageLive(_2); _2 = copy _1; _1 = const 5_usize; _1 = copy _2; @@ -21,6 +22,7 @@ fn f(_1: usize) -> usize { bb1: { StorageDead(_4); + StorageDead(_2); return; } } diff --git a/tests/mir-opt/copy-prop/issue_107511.main.CopyProp.panic-abort.diff b/tests/mir-opt/copy-prop/issue_107511.main.CopyProp.panic-abort.diff index 689083dfc1d3a..fb2aa9c055a64 100644 --- a/tests/mir-opt/copy-prop/issue_107511.main.CopyProp.panic-abort.diff +++ b/tests/mir-opt/copy-prop/issue_107511.main.CopyProp.panic-abort.diff @@ -86,7 +86,7 @@ } bb6: { -- StorageLive(_16); + StorageLive(_16); _16 = copy ((_11 as Some).0: usize); StorageLive(_17); - StorageLive(_18); @@ -116,7 +116,7 @@ StorageDead(_17); - StorageDead(_18); - _10 = const (); -- StorageDead(_16); + StorageDead(_16); StorageDead(_13); StorageDead(_11); - StorageDead(_10); diff --git a/tests/mir-opt/copy-prop/issue_107511.main.CopyProp.panic-unwind.diff b/tests/mir-opt/copy-prop/issue_107511.main.CopyProp.panic-unwind.diff index 7f768a9f834d9..df3a7793bfdd3 100644 --- a/tests/mir-opt/copy-prop/issue_107511.main.CopyProp.panic-unwind.diff +++ b/tests/mir-opt/copy-prop/issue_107511.main.CopyProp.panic-unwind.diff @@ -86,7 +86,7 @@ } bb6: { -- StorageLive(_16); + StorageLive(_16); _16 = copy ((_11 as Some).0: usize); StorageLive(_17); - StorageLive(_18); @@ -116,7 +116,7 @@ StorageDead(_17); - StorageDead(_18); - _10 = const (); -- StorageDead(_16); + StorageDead(_16); StorageDead(_13); StorageDead(_11); - StorageDead(_10); diff --git a/tests/mir-opt/copy-prop/issue_141649.main.CopyProp.panic-abort.diff b/tests/mir-opt/copy-prop/issue_141649.main.CopyProp.panic-abort.diff new file mode 100644 index 0000000000000..c68bfb1b8e94a --- /dev/null +++ b/tests/mir-opt/copy-prop/issue_141649.main.CopyProp.panic-abort.diff @@ -0,0 +1,142 @@ +- // MIR for `main` before CopyProp ++ // MIR for `main` after CopyProp + + fn main() -> () { + let mut _0: (); + let _1: (); + let _2: main::S; + let _3: (); + let mut _4: main::S; + let _5: (); + let _6: main::S; + let _7: (); + let mut _8: main::S; + let _9: (); + let _10: main::S; + let _12: &main::S; + let mut _13: &main::S; + let _14: (); + let mut _15: main::S; + let _16: (); + let _17: main::C; + let _18: (); + let mut _19: main::C; + let _20: main::C; + let _21: (); + let mut _22: main::C; + scope 1 { + debug s1 => _2; + } + scope 2 { + debug s2 => _6; + } + scope 3 { + debug s3 => _10; + let _11: &main::S; + scope 4 { + debug borrowed_s3 => _11; + } + } + scope 5 { + debug c1 => _17; + } + scope 6 { + debug c2 => _20; + } + + bb0: { +- StorageLive(_1); + StorageLive(_2); + _2 = S(const 1_usize, const 2_usize); + StorageLive(_3); +- StorageLive(_4); +- _4 = move _2; +- _3 = std::mem::drop::(move _4) -> [return: bb1, unwind unreachable]; ++ _3 = std::mem::drop::(move _2) -> [return: bb1, unwind unreachable]; + } + + bb1: { +- StorageDead(_4); + StorageDead(_3); +- _1 = const (); + StorageDead(_2); +- StorageDead(_1); +- StorageLive(_5); + StorageLive(_6); + _6 = S(const 3_usize, const 4_usize); + StorageLive(_7); +- StorageLive(_8); +- _8 = move _6; +- _7 = std::mem::drop::(move _8) -> [return: bb2, unwind unreachable]; ++ _7 = std::mem::drop::(move _6) -> [return: bb2, unwind unreachable]; + } + + bb2: { +- StorageDead(_8); + StorageDead(_7); +- _5 = const (); + StorageDead(_6); +- StorageDead(_5); +- StorageLive(_9); + StorageLive(_10); + _10 = S(const 5_usize, const 6_usize); + StorageLive(_11); + _11 = &_10; + StorageLive(_12); +- StorageLive(_13); +- _13 = copy _11; +- _12 = opaque::<&S>(move _13) -> [return: bb3, unwind unreachable]; ++ _12 = opaque::<&S>(copy _11) -> [return: bb3, unwind unreachable]; + } + + bb3: { +- StorageDead(_13); + StorageDead(_12); + StorageLive(_14); +- StorageLive(_15); +- _15 = move _10; +- _14 = std::mem::drop::(move _15) -> [return: bb4, unwind unreachable]; ++ _14 = std::mem::drop::(move _10) -> [return: bb4, unwind unreachable]; + } + + bb4: { +- StorageDead(_15); + StorageDead(_14); +- _9 = const (); + StorageDead(_11); + StorageDead(_10); +- StorageDead(_9); +- StorageLive(_16); + StorageLive(_17); + _17 = C(const 1_usize, const 2_usize); + StorageLive(_18); +- StorageLive(_19); +- _19 = copy _17; +- _18 = std::mem::drop::(move _19) -> [return: bb5, unwind unreachable]; ++ _18 = std::mem::drop::(copy _17) -> [return: bb5, unwind unreachable]; + } + + bb5: { +- StorageDead(_19); + StorageDead(_18); +- _16 = const (); + StorageDead(_17); +- StorageDead(_16); + StorageLive(_20); + _20 = C(const 3_usize, const 4_usize); + StorageLive(_21); +- StorageLive(_22); +- _22 = copy _20; +- _21 = std::mem::drop::(move _22) -> [return: bb6, unwind unreachable]; ++ _21 = std::mem::drop::(copy _20) -> [return: bb6, unwind unreachable]; + } + + bb6: { +- StorageDead(_22); + StorageDead(_21); + _0 = const (); + StorageDead(_20); + return; + } + } + diff --git a/tests/mir-opt/copy-prop/issue_141649.main.CopyProp.panic-unwind.diff b/tests/mir-opt/copy-prop/issue_141649.main.CopyProp.panic-unwind.diff index e02fe72a47a7b..3535a9840f685 100644 --- a/tests/mir-opt/copy-prop/issue_141649.main.CopyProp.panic-unwind.diff +++ b/tests/mir-opt/copy-prop/issue_141649.main.CopyProp.panic-unwind.diff @@ -12,12 +12,18 @@ let _7: (); let mut _8: main::S; let _9: (); - let _10: main::C; - let _11: (); - let mut _12: main::C; - let _13: main::C; + let _10: main::S; + let _12: &main::S; + let mut _13: &main::S; let _14: (); - let mut _15: main::C; + let mut _15: main::S; + let _16: (); + let _17: main::C; + let _18: (); + let mut _19: main::C; + let _20: main::C; + let _21: (); + let mut _22: main::C; scope 1 { debug s1 => _2; } @@ -25,15 +31,22 @@ debug s2 => _6; } scope 3 { - debug c1 => _10; + debug s3 => _10; + let _11: &main::S; + scope 4 { + debug borrowed_s3 => _11; + } } - scope 4 { - debug c2 => _13; + scope 5 { + debug c1 => _17; + } + scope 6 { + debug c2 => _20; } bb0: { - StorageLive(_1); -- StorageLive(_2); + StorageLive(_2); _2 = S(const 1_usize, const 2_usize); StorageLive(_3); - StorageLive(_4); @@ -46,10 +59,10 @@ - StorageDead(_4); StorageDead(_3); - _1 = const (); -- StorageDead(_2); + StorageDead(_2); - StorageDead(_1); - StorageLive(_5); -- StorageLive(_6); + StorageLive(_6); _6 = S(const 3_usize, const 4_usize); StorageLive(_7); - StorageLive(_8); @@ -62,38 +75,67 @@ - StorageDead(_8); StorageDead(_7); - _5 = const (); -- StorageDead(_6); + StorageDead(_6); - StorageDead(_5); - StorageLive(_9); -- StorageLive(_10); - _10 = C(const 1_usize, const 2_usize); + StorageLive(_10); + _10 = S(const 5_usize, const 6_usize); StorageLive(_11); -- StorageLive(_12); -- _12 = copy _10; -- _11 = std::mem::drop::(move _12) -> [return: bb3, unwind continue]; -+ _11 = std::mem::drop::(copy _10) -> [return: bb3, unwind continue]; + _11 = &_10; + StorageLive(_12); +- StorageLive(_13); +- _13 = copy _11; +- _12 = opaque::<&S>(move _13) -> [return: bb3, unwind continue]; ++ _12 = opaque::<&S>(copy _11) -> [return: bb3, unwind continue]; } bb3: { -- StorageDead(_12); - StorageDead(_11); -- _9 = const (); -- StorageDead(_10); -- StorageDead(_9); -- StorageLive(_13); - _13 = C(const 3_usize, const 4_usize); +- StorageDead(_13); + StorageDead(_12); StorageLive(_14); - StorageLive(_15); -- _15 = copy _13; -- _14 = std::mem::drop::(move _15) -> [return: bb4, unwind continue]; -+ _14 = std::mem::drop::(copy _13) -> [return: bb4, unwind continue]; +- _15 = move _10; +- _14 = std::mem::drop::(move _15) -> [return: bb4, unwind continue]; ++ _14 = std::mem::drop::(move _10) -> [return: bb4, unwind continue]; } bb4: { - StorageDead(_15); StorageDead(_14); +- _9 = const (); + StorageDead(_11); + StorageDead(_10); +- StorageDead(_9); +- StorageLive(_16); + StorageLive(_17); + _17 = C(const 1_usize, const 2_usize); + StorageLive(_18); +- StorageLive(_19); +- _19 = copy _17; +- _18 = std::mem::drop::(move _19) -> [return: bb5, unwind continue]; ++ _18 = std::mem::drop::(copy _17) -> [return: bb5, unwind continue]; + } + + bb5: { +- StorageDead(_19); + StorageDead(_18); +- _16 = const (); + StorageDead(_17); +- StorageDead(_16); + StorageLive(_20); + _20 = C(const 3_usize, const 4_usize); + StorageLive(_21); +- StorageLive(_22); +- _22 = copy _20; +- _21 = std::mem::drop::(move _22) -> [return: bb6, unwind continue]; ++ _21 = std::mem::drop::(copy _20) -> [return: bb6, unwind continue]; + } + + bb6: { +- StorageDead(_22); + StorageDead(_21); _0 = const (); -- StorageDead(_13); + StorageDead(_20); return; } } diff --git a/tests/mir-opt/copy-prop/issue_141649.rs b/tests/mir-opt/copy-prop/issue_141649.rs index 3227c47bcc72c..e3b9062d65101 100644 --- a/tests/mir-opt/copy-prop/issue_141649.rs +++ b/tests/mir-opt/copy-prop/issue_141649.rs @@ -13,6 +13,12 @@ fn main() { let s2 = S(3, 4); drop(s2); } + { + let s3 = S(5, 6); + let borrowed_s3 = &s3; + opaque(borrowed_s3); + drop(s3); + } #[derive(Clone, Copy)] struct C(usize, usize); @@ -25,3 +31,8 @@ fn main() { drop(c2); } } + +#[inline(never)] +fn opaque(a: T) -> T { + a +} diff --git a/tests/mir-opt/copy-prop/issue_141649_debug.main.CopyProp.panic-abort.diff b/tests/mir-opt/copy-prop/issue_141649_debug.main.CopyProp.panic-abort.diff new file mode 100644 index 0000000000000..93629b0f9f3f9 --- /dev/null +++ b/tests/mir-opt/copy-prop/issue_141649_debug.main.CopyProp.panic-abort.diff @@ -0,0 +1,100 @@ +- // MIR for `main` before CopyProp ++ // MIR for `main` after CopyProp + + fn main() -> () { + let mut _0: (); + let _1: (); + let _2: main::S; + let _3: (); + let mut _4: main::S; + let _5: (); + let _6: main::S; + let _7: (); + let mut _8: main::S; + let _9: (); + let _10: main::C; + let _11: (); + let mut _12: main::C; + let _13: main::C; + let _14: (); + let mut _15: main::C; + scope 1 { + debug s1 => _2; + } + scope 2 { + debug s2 => _6; + } + scope 3 { + debug c1 => _10; + } + scope 4 { + debug c2 => _13; + } + + bb0: { +- StorageLive(_1); +- StorageLive(_2); + _2 = S(const 1_usize, const 2_usize); + StorageLive(_3); +- StorageLive(_4); +- _4 = move _2; +- _3 = std::mem::drop::(move _4) -> [return: bb1, unwind unreachable]; ++ _3 = std::mem::drop::(move _2) -> [return: bb1, unwind unreachable]; + } + + bb1: { +- StorageDead(_4); + StorageDead(_3); +- _1 = const (); +- StorageDead(_2); +- StorageDead(_1); +- StorageLive(_5); +- StorageLive(_6); + _6 = S(const 3_usize, const 4_usize); + StorageLive(_7); +- StorageLive(_8); +- _8 = move _6; +- _7 = std::mem::drop::(move _8) -> [return: bb2, unwind unreachable]; ++ _7 = std::mem::drop::(move _6) -> [return: bb2, unwind unreachable]; + } + + bb2: { +- StorageDead(_8); + StorageDead(_7); +- _5 = const (); +- StorageDead(_6); +- StorageDead(_5); +- StorageLive(_9); +- StorageLive(_10); + _10 = C(const 1_usize, const 2_usize); + StorageLive(_11); +- StorageLive(_12); +- _12 = copy _10; +- _11 = std::mem::drop::(move _12) -> [return: bb3, unwind unreachable]; ++ _11 = std::mem::drop::(copy _10) -> [return: bb3, unwind unreachable]; + } + + bb3: { +- StorageDead(_12); + StorageDead(_11); +- _9 = const (); +- StorageDead(_10); +- StorageDead(_9); +- StorageLive(_13); + _13 = C(const 3_usize, const 4_usize); + StorageLive(_14); +- StorageLive(_15); +- _15 = copy _13; +- _14 = std::mem::drop::(move _15) -> [return: bb4, unwind unreachable]; ++ _14 = std::mem::drop::(copy _13) -> [return: bb4, unwind unreachable]; + } + + bb4: { +- StorageDead(_15); + StorageDead(_14); + _0 = const (); +- StorageDead(_13); + return; + } + } + diff --git a/tests/mir-opt/copy-prop/issue_141649_debug.main.CopyProp.panic-unwind.diff b/tests/mir-opt/copy-prop/issue_141649_debug.main.CopyProp.panic-unwind.diff new file mode 100644 index 0000000000000..e02fe72a47a7b --- /dev/null +++ b/tests/mir-opt/copy-prop/issue_141649_debug.main.CopyProp.panic-unwind.diff @@ -0,0 +1,100 @@ +- // MIR for `main` before CopyProp ++ // MIR for `main` after CopyProp + + fn main() -> () { + let mut _0: (); + let _1: (); + let _2: main::S; + let _3: (); + let mut _4: main::S; + let _5: (); + let _6: main::S; + let _7: (); + let mut _8: main::S; + let _9: (); + let _10: main::C; + let _11: (); + let mut _12: main::C; + let _13: main::C; + let _14: (); + let mut _15: main::C; + scope 1 { + debug s1 => _2; + } + scope 2 { + debug s2 => _6; + } + scope 3 { + debug c1 => _10; + } + scope 4 { + debug c2 => _13; + } + + bb0: { +- StorageLive(_1); +- StorageLive(_2); + _2 = S(const 1_usize, const 2_usize); + StorageLive(_3); +- StorageLive(_4); +- _4 = move _2; +- _3 = std::mem::drop::(move _4) -> [return: bb1, unwind continue]; ++ _3 = std::mem::drop::(move _2) -> [return: bb1, unwind continue]; + } + + bb1: { +- StorageDead(_4); + StorageDead(_3); +- _1 = const (); +- StorageDead(_2); +- StorageDead(_1); +- StorageLive(_5); +- StorageLive(_6); + _6 = S(const 3_usize, const 4_usize); + StorageLive(_7); +- StorageLive(_8); +- _8 = move _6; +- _7 = std::mem::drop::(move _8) -> [return: bb2, unwind continue]; ++ _7 = std::mem::drop::(move _6) -> [return: bb2, unwind continue]; + } + + bb2: { +- StorageDead(_8); + StorageDead(_7); +- _5 = const (); +- StorageDead(_6); +- StorageDead(_5); +- StorageLive(_9); +- StorageLive(_10); + _10 = C(const 1_usize, const 2_usize); + StorageLive(_11); +- StorageLive(_12); +- _12 = copy _10; +- _11 = std::mem::drop::(move _12) -> [return: bb3, unwind continue]; ++ _11 = std::mem::drop::(copy _10) -> [return: bb3, unwind continue]; + } + + bb3: { +- StorageDead(_12); + StorageDead(_11); +- _9 = const (); +- StorageDead(_10); +- StorageDead(_9); +- StorageLive(_13); + _13 = C(const 3_usize, const 4_usize); + StorageLive(_14); +- StorageLive(_15); +- _15 = copy _13; +- _14 = std::mem::drop::(move _15) -> [return: bb4, unwind continue]; ++ _14 = std::mem::drop::(copy _13) -> [return: bb4, unwind continue]; + } + + bb4: { +- StorageDead(_15); + StorageDead(_14); + _0 = const (); +- StorageDead(_13); + return; + } + } + diff --git a/tests/mir-opt/copy-prop/issue_141649_debug.rs b/tests/mir-opt/copy-prop/issue_141649_debug.rs new file mode 100644 index 0000000000000..5769118700ca1 --- /dev/null +++ b/tests/mir-opt/copy-prop/issue_141649_debug.rs @@ -0,0 +1,29 @@ +// skip-filecheck +// EMIT_MIR_FOR_EACH_PANIC_STRATEGY +//! Tests that in lower opt levels we remove (more) storage statements using a simpler strategy. +//@ test-mir-pass: CopyProp +//@ compile-flags: -Copt-level=0 + +// EMIT_MIR issue_141649_debug.main.CopyProp.diff +fn main() { + struct S(usize, usize); + { + let s1 = S(1, 2); + drop(s1); + } + { + let s2 = S(3, 4); + drop(s2); + } + + #[derive(Clone, Copy)] + struct C(usize, usize); + { + let c1 = C(1, 2); + drop(c1); + } + { + let c2 = C(3, 4); + drop(c2); + } +} diff --git a/tests/mir-opt/copy-prop/reborrow.demiraw.CopyProp.panic-abort.diff b/tests/mir-opt/copy-prop/reborrow.demiraw.CopyProp.panic-abort.diff index 676c5cee34387..ccd1e1caf003a 100644 --- a/tests/mir-opt/copy-prop/reborrow.demiraw.CopyProp.panic-abort.diff +++ b/tests/mir-opt/copy-prop/reborrow.demiraw.CopyProp.panic-abort.diff @@ -22,7 +22,7 @@ } bb0: { -- StorageLive(_2); + StorageLive(_2); _2 = &raw mut _1; StorageLive(_3); StorageLive(_4); @@ -44,7 +44,7 @@ _0 = const (); - StorageDead(_5); StorageDead(_3); -- StorageDead(_2); + StorageDead(_2); return; } } diff --git a/tests/mir-opt/copy-prop/reborrow.demiraw.CopyProp.panic-unwind.diff b/tests/mir-opt/copy-prop/reborrow.demiraw.CopyProp.panic-unwind.diff index ca2232ce54a1f..6cfb4af1fcf2e 100644 --- a/tests/mir-opt/copy-prop/reborrow.demiraw.CopyProp.panic-unwind.diff +++ b/tests/mir-opt/copy-prop/reborrow.demiraw.CopyProp.panic-unwind.diff @@ -22,7 +22,7 @@ } bb0: { -- StorageLive(_2); + StorageLive(_2); _2 = &raw mut _1; StorageLive(_3); StorageLive(_4); @@ -44,7 +44,7 @@ _0 = const (); - StorageDead(_5); StorageDead(_3); -- StorageDead(_2); + StorageDead(_2); return; } } diff --git a/tests/mir-opt/copy-prop/reborrow.miraw.CopyProp.panic-abort.diff b/tests/mir-opt/copy-prop/reborrow.miraw.CopyProp.panic-abort.diff index 1968696905fc7..b5f6a6e22f29f 100644 --- a/tests/mir-opt/copy-prop/reborrow.miraw.CopyProp.panic-abort.diff +++ b/tests/mir-opt/copy-prop/reborrow.miraw.CopyProp.panic-abort.diff @@ -21,7 +21,7 @@ } bb0: { -- StorageLive(_2); + StorageLive(_2); _2 = &raw mut _1; StorageLive(_3); _3 = &raw mut (*_2); @@ -40,7 +40,7 @@ _0 = const (); - StorageDead(_4); StorageDead(_3); -- StorageDead(_2); + StorageDead(_2); return; } } diff --git a/tests/mir-opt/copy-prop/reborrow.miraw.CopyProp.panic-unwind.diff b/tests/mir-opt/copy-prop/reborrow.miraw.CopyProp.panic-unwind.diff index 9a3c9665bc8f3..c28f7d037fd1d 100644 --- a/tests/mir-opt/copy-prop/reborrow.miraw.CopyProp.panic-unwind.diff +++ b/tests/mir-opt/copy-prop/reborrow.miraw.CopyProp.panic-unwind.diff @@ -21,7 +21,7 @@ } bb0: { -- StorageLive(_2); + StorageLive(_2); _2 = &raw mut _1; StorageLive(_3); _3 = &raw mut (*_2); @@ -40,7 +40,7 @@ _0 = const (); - StorageDead(_4); StorageDead(_3); -- StorageDead(_2); + StorageDead(_2); return; } } diff --git a/tests/mir-opt/copy-prop/reborrow.remut.CopyProp.panic-abort.diff b/tests/mir-opt/copy-prop/reborrow.remut.CopyProp.panic-abort.diff index 2026c1982f299..aebd98d85b54c 100644 --- a/tests/mir-opt/copy-prop/reborrow.remut.CopyProp.panic-abort.diff +++ b/tests/mir-opt/copy-prop/reborrow.remut.CopyProp.panic-abort.diff @@ -21,7 +21,7 @@ } bb0: { -- StorageLive(_2); + StorageLive(_2); _2 = &mut _1; StorageLive(_3); _3 = &mut (*_2); @@ -40,7 +40,7 @@ _0 = const (); - StorageDead(_4); StorageDead(_3); -- StorageDead(_2); + StorageDead(_2); return; } } diff --git a/tests/mir-opt/copy-prop/reborrow.remut.CopyProp.panic-unwind.diff b/tests/mir-opt/copy-prop/reborrow.remut.CopyProp.panic-unwind.diff index 67763fdce6676..a836d439c3eac 100644 --- a/tests/mir-opt/copy-prop/reborrow.remut.CopyProp.panic-unwind.diff +++ b/tests/mir-opt/copy-prop/reborrow.remut.CopyProp.panic-unwind.diff @@ -21,7 +21,7 @@ } bb0: { -- StorageLive(_2); + StorageLive(_2); _2 = &mut _1; StorageLive(_3); _3 = &mut (*_2); @@ -40,7 +40,7 @@ _0 = const (); - StorageDead(_4); StorageDead(_3); -- StorageDead(_2); + StorageDead(_2); return; } } diff --git a/tests/mir-opt/copy-prop/reborrow.reraw.CopyProp.panic-abort.diff b/tests/mir-opt/copy-prop/reborrow.reraw.CopyProp.panic-abort.diff index dfc8dd0975638..38801bc7811a8 100644 --- a/tests/mir-opt/copy-prop/reborrow.reraw.CopyProp.panic-abort.diff +++ b/tests/mir-opt/copy-prop/reborrow.reraw.CopyProp.panic-abort.diff @@ -21,7 +21,7 @@ } bb0: { -- StorageLive(_2); + StorageLive(_2); _2 = &mut _1; StorageLive(_3); _3 = &raw mut (*_2); @@ -40,7 +40,7 @@ _0 = const (); - StorageDead(_4); StorageDead(_3); -- StorageDead(_2); + StorageDead(_2); return; } } diff --git a/tests/mir-opt/copy-prop/reborrow.reraw.CopyProp.panic-unwind.diff b/tests/mir-opt/copy-prop/reborrow.reraw.CopyProp.panic-unwind.diff index becc425632104..f7af4681014b3 100644 --- a/tests/mir-opt/copy-prop/reborrow.reraw.CopyProp.panic-unwind.diff +++ b/tests/mir-opt/copy-prop/reborrow.reraw.CopyProp.panic-unwind.diff @@ -21,7 +21,7 @@ } bb0: { -- StorageLive(_2); + StorageLive(_2); _2 = &mut _1; StorageLive(_3); _3 = &raw mut (*_2); @@ -40,7 +40,7 @@ _0 = const (); - StorageDead(_4); StorageDead(_3); -- StorageDead(_2); + StorageDead(_2); return; } } diff --git a/tests/mir-opt/simplify_locals_fixedpoint.foo.SimplifyLocals-final.panic-abort.diff b/tests/mir-opt/simplify_locals_fixedpoint.foo.SimplifyLocals-final.panic-abort.diff index ff1bc58524bc2..c590c1aad4477 100644 --- a/tests/mir-opt/simplify_locals_fixedpoint.foo.SimplifyLocals-final.panic-abort.diff +++ b/tests/mir-opt/simplify_locals_fixedpoint.foo.SimplifyLocals-final.panic-abort.diff @@ -35,7 +35,9 @@ } bb2: { + StorageLive(_6); _6 = copy (((_1.0: std::option::Option) as Some).0: u8); + StorageDead(_6); goto -> bb3; } diff --git a/tests/mir-opt/simplify_locals_fixedpoint.foo.SimplifyLocals-final.panic-unwind.diff b/tests/mir-opt/simplify_locals_fixedpoint.foo.SimplifyLocals-final.panic-unwind.diff index 2c289c664754a..9dd0195c86c97 100644 --- a/tests/mir-opt/simplify_locals_fixedpoint.foo.SimplifyLocals-final.panic-unwind.diff +++ b/tests/mir-opt/simplify_locals_fixedpoint.foo.SimplifyLocals-final.panic-unwind.diff @@ -35,7 +35,9 @@ } bb2: { + StorageLive(_6); _6 = copy (((_1.0: std::option::Option) as Some).0: u8); + StorageDead(_6); goto -> bb3; } From ec52a2d3a0234961295c0c8dd37ca102149cad92 Mon Sep 17 00:00:00 2001 From: Ohad Ravid Date: Tue, 3 Jun 2025 08:28:17 +0300 Subject: [PATCH 03/14] Added gvn test for removed local storage annotations --- ...n_storage_remove.main.GVN.panic-abort.diff | 132 ++++++++++++++++++ ..._storage_remove.main.GVN.panic-unwind.diff | 132 ++++++++++++++++++ .../issue_141649_gvn_storage_remove.rs | 27 ++++ 3 files changed, 291 insertions(+) create mode 100644 tests/mir-opt/issue_141649_gvn_storage_remove.main.GVN.panic-abort.diff create mode 100644 tests/mir-opt/issue_141649_gvn_storage_remove.main.GVN.panic-unwind.diff create mode 100644 tests/mir-opt/issue_141649_gvn_storage_remove.rs diff --git a/tests/mir-opt/issue_141649_gvn_storage_remove.main.GVN.panic-abort.diff b/tests/mir-opt/issue_141649_gvn_storage_remove.main.GVN.panic-abort.diff new file mode 100644 index 0000000000000..5e19645ed5b7d --- /dev/null +++ b/tests/mir-opt/issue_141649_gvn_storage_remove.main.GVN.panic-abort.diff @@ -0,0 +1,132 @@ +- // MIR for `main` before GVN ++ // MIR for `main` after GVN + + fn main() -> () { + let mut _0: (); + let _1: (); + let _2: main::S; + let _3: (); + let mut _4: main::S; + let _5: (); + let _6: main::S; + let _7: (); + let mut _8: main::S; + let _9: (); + let _10: main::C; + let _11: (); + let mut _12: main::C; + let _13: main::C; + let _14: (); + let mut _15: main::C; + scope 1 { + debug s1 => _2; + } + scope 2 { + debug s2 => _6; + } + scope 3 { + debug c1 => _10; + } + scope 4 { + debug c2 => _13; + } + + bb0: { + StorageLive(_1); +- StorageLive(_2); +- _2 = S(const 1_u32, const 2_u32); ++ nop; ++ _2 = const S(1_u32, 2_u32); + StorageLive(_3); + StorageLive(_4); +- _4 = move _2; +- _3 = std::mem::drop::(move _4) -> [return: bb1, unwind unreachable]; ++ _4 = const S(1_u32, 2_u32); ++ _3 = std::mem::drop::(const S(1_u32, 2_u32)) -> [return: bb1, unwind unreachable]; + } + + bb1: { + StorageDead(_4); + StorageDead(_3); + _1 = const (); +- StorageDead(_2); ++ nop; + StorageDead(_1); + StorageLive(_5); +- StorageLive(_6); +- _6 = S(const 3_u32, const 4_u32); ++ nop; ++ _6 = const S(3_u32, 4_u32); + StorageLive(_7); + StorageLive(_8); +- _8 = move _6; +- _7 = std::mem::drop::(move _8) -> [return: bb2, unwind unreachable]; ++ _8 = const S(3_u32, 4_u32); ++ _7 = std::mem::drop::(const S(3_u32, 4_u32)) -> [return: bb2, unwind unreachable]; + } + + bb2: { + StorageDead(_8); + StorageDead(_7); + _5 = const (); +- StorageDead(_6); ++ nop; + StorageDead(_5); + StorageLive(_9); +- StorageLive(_10); +- _10 = C(const 1_u32, const 2_u32); ++ nop; ++ _10 = const C(1_u32, 2_u32); + StorageLive(_11); + StorageLive(_12); +- _12 = copy _10; +- _11 = std::mem::drop::(move _12) -> [return: bb3, unwind unreachable]; ++ _12 = const C(1_u32, 2_u32); ++ _11 = std::mem::drop::(const C(1_u32, 2_u32)) -> [return: bb3, unwind unreachable]; + } + + bb3: { + StorageDead(_12); + StorageDead(_11); + _9 = const (); +- StorageDead(_10); ++ nop; + StorageDead(_9); +- StorageLive(_13); +- _13 = C(const 3_u32, const 4_u32); ++ nop; ++ _13 = const C(3_u32, 4_u32); + StorageLive(_14); + StorageLive(_15); +- _15 = copy _13; +- _14 = std::mem::drop::(move _15) -> [return: bb4, unwind unreachable]; ++ _15 = const C(3_u32, 4_u32); ++ _14 = std::mem::drop::(const C(3_u32, 4_u32)) -> [return: bb4, unwind unreachable]; + } + + bb4: { + StorageDead(_15); + StorageDead(_14); + _0 = const (); +- StorageDead(_13); ++ nop; + return; + } ++ } ++ ++ ALLOC0 (size: 8, align: 4) { ++ 03 00 00 00 04 00 00 00 │ ........ ++ } ++ ++ ALLOC1 (size: 8, align: 4) { ++ 01 00 00 00 02 00 00 00 │ ........ ++ } ++ ++ ALLOC2 (size: 8, align: 4) { ++ 03 00 00 00 04 00 00 00 │ ........ ++ } ++ ++ ALLOC3 (size: 8, align: 4) { ++ 01 00 00 00 02 00 00 00 │ ........ + } + diff --git a/tests/mir-opt/issue_141649_gvn_storage_remove.main.GVN.panic-unwind.diff b/tests/mir-opt/issue_141649_gvn_storage_remove.main.GVN.panic-unwind.diff new file mode 100644 index 0000000000000..8f60f2f63e0f6 --- /dev/null +++ b/tests/mir-opt/issue_141649_gvn_storage_remove.main.GVN.panic-unwind.diff @@ -0,0 +1,132 @@ +- // MIR for `main` before GVN ++ // MIR for `main` after GVN + + fn main() -> () { + let mut _0: (); + let _1: (); + let _2: main::S; + let _3: (); + let mut _4: main::S; + let _5: (); + let _6: main::S; + let _7: (); + let mut _8: main::S; + let _9: (); + let _10: main::C; + let _11: (); + let mut _12: main::C; + let _13: main::C; + let _14: (); + let mut _15: main::C; + scope 1 { + debug s1 => _2; + } + scope 2 { + debug s2 => _6; + } + scope 3 { + debug c1 => _10; + } + scope 4 { + debug c2 => _13; + } + + bb0: { + StorageLive(_1); +- StorageLive(_2); +- _2 = S(const 1_u32, const 2_u32); ++ nop; ++ _2 = const S(1_u32, 2_u32); + StorageLive(_3); + StorageLive(_4); +- _4 = move _2; +- _3 = std::mem::drop::(move _4) -> [return: bb1, unwind continue]; ++ _4 = const S(1_u32, 2_u32); ++ _3 = std::mem::drop::(const S(1_u32, 2_u32)) -> [return: bb1, unwind continue]; + } + + bb1: { + StorageDead(_4); + StorageDead(_3); + _1 = const (); +- StorageDead(_2); ++ nop; + StorageDead(_1); + StorageLive(_5); +- StorageLive(_6); +- _6 = S(const 3_u32, const 4_u32); ++ nop; ++ _6 = const S(3_u32, 4_u32); + StorageLive(_7); + StorageLive(_8); +- _8 = move _6; +- _7 = std::mem::drop::(move _8) -> [return: bb2, unwind continue]; ++ _8 = const S(3_u32, 4_u32); ++ _7 = std::mem::drop::(const S(3_u32, 4_u32)) -> [return: bb2, unwind continue]; + } + + bb2: { + StorageDead(_8); + StorageDead(_7); + _5 = const (); +- StorageDead(_6); ++ nop; + StorageDead(_5); + StorageLive(_9); +- StorageLive(_10); +- _10 = C(const 1_u32, const 2_u32); ++ nop; ++ _10 = const C(1_u32, 2_u32); + StorageLive(_11); + StorageLive(_12); +- _12 = copy _10; +- _11 = std::mem::drop::(move _12) -> [return: bb3, unwind continue]; ++ _12 = const C(1_u32, 2_u32); ++ _11 = std::mem::drop::(const C(1_u32, 2_u32)) -> [return: bb3, unwind continue]; + } + + bb3: { + StorageDead(_12); + StorageDead(_11); + _9 = const (); +- StorageDead(_10); ++ nop; + StorageDead(_9); +- StorageLive(_13); +- _13 = C(const 3_u32, const 4_u32); ++ nop; ++ _13 = const C(3_u32, 4_u32); + StorageLive(_14); + StorageLive(_15); +- _15 = copy _13; +- _14 = std::mem::drop::(move _15) -> [return: bb4, unwind continue]; ++ _15 = const C(3_u32, 4_u32); ++ _14 = std::mem::drop::(const C(3_u32, 4_u32)) -> [return: bb4, unwind continue]; + } + + bb4: { + StorageDead(_15); + StorageDead(_14); + _0 = const (); +- StorageDead(_13); ++ nop; + return; + } ++ } ++ ++ ALLOC0 (size: 8, align: 4) { ++ 03 00 00 00 04 00 00 00 │ ........ ++ } ++ ++ ALLOC1 (size: 8, align: 4) { ++ 01 00 00 00 02 00 00 00 │ ........ ++ } ++ ++ ALLOC2 (size: 8, align: 4) { ++ 03 00 00 00 04 00 00 00 │ ........ ++ } ++ ++ ALLOC3 (size: 8, align: 4) { ++ 01 00 00 00 02 00 00 00 │ ........ + } + diff --git a/tests/mir-opt/issue_141649_gvn_storage_remove.rs b/tests/mir-opt/issue_141649_gvn_storage_remove.rs new file mode 100644 index 0000000000000..eb2b5337d0c41 --- /dev/null +++ b/tests/mir-opt/issue_141649_gvn_storage_remove.rs @@ -0,0 +1,27 @@ +// skip-filecheck +// EMIT_MIR_FOR_EACH_PANIC_STRATEGY +//@ test-mir-pass: GVN + +// EMIT_MIR issue_141649_gvn_storage_remove.main.GVN.diff +fn main() { + struct S(u32, u32); + { + let s1 = S(1, 2); + drop(s1); + } + { + let s2 = S(3, 4); + drop(s2); + } + + #[derive(Clone, Copy)] + struct C(u32, u32); + { + let c1 = C(1, 2); + drop(c1); + } + { + let c2 = C(3, 4); + drop(c2); + } +} From 02434a2b6c98a2398c510c43c6a229feec88d9ee Mon Sep 17 00:00:00 2001 From: Ohad Ravid Date: Sat, 14 Jun 2025 22:38:21 +0300 Subject: [PATCH 04/14] Use `MaybeUninitializedLocals` analysis in GVN mir-opt to remove fewer storage statements --- compiler/rustc_mir_transform/src/gvn.rs | 71 +++++++++++++++++-- .../const_debuginfo.main.SingleUseConsts.diff | 20 +++--- .../aggregate.main.GVN.panic-abort.diff | 6 +- .../aggregate.main.GVN.panic-unwind.diff | 6 +- ...d_op_div_by_zero.main.GVN.panic-abort.diff | 6 +- ..._op_div_by_zero.main.GVN.panic-unwind.diff | 6 +- ...d_op_mod_by_zero.main.GVN.panic-abort.diff | 6 +- ..._op_mod_by_zero.main.GVN.panic-unwind.diff | 6 +- .../boolean_identities.test.GVN.diff | 12 ++-- .../boxes.main.GVN.panic-abort.diff | 6 +- .../boxes.main.GVN.panic-unwind.diff | 6 +- ...le_unprop_assign.main.GVN.panic-abort.diff | 6 +- ...e_unprop_assign.main.GVN.panic-unwind.diff | 6 +- ...xpose_provenance.main.GVN.panic-abort.diff | 6 +- ...pose_provenance.main.GVN.panic-unwind.diff | 6 +- .../read_immutable_static.main.GVN.diff | 12 ++-- ...eral_propagation.main.GVN.panic-abort.diff | 6 +- ...ral_propagation.main.GVN.panic-unwind.diff | 6 +- ...eral_propagation.main.GVN.panic-abort.diff | 6 +- ...ral_propagation.main.GVN.panic-unwind.diff | 6 +- ...ng_operand.test.GVN.32bit.panic-abort.diff | 6 +- ...g_operand.test.GVN.32bit.panic-unwind.diff | 6 +- ...ng_operand.test.GVN.64bit.panic-abort.diff | 6 +- ...g_operand.test.GVN.64bit.panic-unwind.diff | 6 +- ...onential_common.GVN.32bit.panic-abort.diff | 6 +- ...nential_common.GVN.32bit.panic-unwind.diff | 6 +- ...onential_common.GVN.64bit.panic-abort.diff | 6 +- ...nential_common.GVN.64bit.panic-unwind.diff | 6 +- ...struct_then_transmute.GVN.panic-abort.diff | 48 +++++-------- ...truct_then_transmute.GVN.panic-unwind.diff | 48 +++++-------- .../gvn.arithmetic.GVN.panic-abort.diff | 6 +- .../gvn.arithmetic.GVN.panic-unwind.diff | 6 +- ...vn.arithmetic_checked.GVN.panic-abort.diff | 6 +- ...n.arithmetic_checked.GVN.panic-unwind.diff | 6 +- .../gvn.array_len.GVN.panic-abort.diff | 6 +- .../gvn.array_len.GVN.panic-unwind.diff | 6 +- tests/mir-opt/gvn.cast.GVN.panic-abort.diff | 18 ++--- tests/mir-opt/gvn.cast.GVN.panic-unwind.diff | 18 ++--- .../gvn.cast_pointer_eq.GVN.panic-abort.diff | 12 ++-- .../gvn.cast_pointer_eq.GVN.panic-unwind.diff | 12 ++-- ...ore_aggregate_raw_ptr.GVN.panic-abort.diff | 18 ++--- ...re_aggregate_raw_ptr.GVN.panic-unwind.diff | 18 ++--- ...nstant_index_overflow.GVN.panic-abort.diff | 6 +- ...stant_index_overflow.GVN.panic-unwind.diff | 6 +- .../gvn.fn_pointers.GVN.panic-abort.diff | 30 +++----- .../gvn.fn_pointers.GVN.panic-unwind.diff | 30 +++----- ....manual_slice_mut_len.GVN.panic-abort.diff | 12 ++-- ...manual_slice_mut_len.GVN.panic-unwind.diff | 12 ++-- ....meta_of_ref_to_slice.GVN.panic-abort.diff | 6 +- ...meta_of_ref_to_slice.GVN.panic-unwind.diff | 6 +- .../gvn.references.GVN.panic-abort.diff | 6 +- .../gvn.references.GVN.panic-unwind.diff | 6 +- tests/mir-opt/gvn.repeat.GVN.panic-abort.diff | 6 +- .../mir-opt/gvn.repeat.GVN.panic-unwind.diff | 6 +- ...vn.slice_const_length.GVN.panic-abort.diff | 12 ++-- ...n.slice_const_length.GVN.panic-unwind.diff | 12 ++-- ...from_raw_parts_as_ptr.GVN.panic-abort.diff | 6 +- ...rom_raw_parts_as_ptr.GVN.panic-unwind.diff | 6 +- tests/mir-opt/gvn.slices.GVN.panic-abort.diff | 42 ++++------- .../mir-opt/gvn.slices.GVN.panic-unwind.diff | 42 ++++------- ...ute_then_cast_pointer.GVN.panic-abort.diff | 18 ++--- ...te_then_cast_pointer.GVN.panic-unwind.diff | 18 ++--- ..._then_transmute_again.GVN.panic-abort.diff | 12 ++-- ...then_transmute_again.GVN.panic-unwind.diff | 12 ++-- tests/mir-opt/gvn.unary.GVN.panic-abort.diff | 6 +- tests/mir-opt/gvn.unary.GVN.panic-unwind.diff | 6 +- .../gvn.wide_ptr_integer.GVN.panic-abort.diff | 12 ++-- ...gvn.wide_ptr_integer.GVN.panic-unwind.diff | 12 ++-- .../mir-opt/gvn_clone.{impl#0}-clone.GVN.diff | 18 ++--- .../gvn_copy_aggregate.all_copy.GVN.diff | 18 ++--- .../gvn_copy_aggregate.all_copy_2.GVN.diff | 22 +++--- ...aggregate.all_copy_different_type.GVN.diff | 18 ++--- ...py_aggregate.all_copy_has_changed.GVN.diff | 18 ++--- .../gvn_copy_aggregate.all_copy_move.GVN.diff | 18 ++--- ...gvn_copy_aggregate.all_copy_ret_2.GVN.diff | 24 +++---- ...py_aggregate.all_copy_use_changed.GVN.diff | 12 ++-- ..._aggregate.all_copy_use_changed_2.GVN.diff | 12 ++-- ..._aggregate.enum_different_variant.GVN.diff | 56 ++++++--------- ..._aggregate.enum_identical_variant.GVN.diff | 56 ++++++--------- .../gvn_copy_aggregate.nest_copy.GVN.diff | 30 +++----- ...gregate.same_type_different_index.GVN.diff | 12 ++-- ...ompare_constant_index.GVN.panic-abort.diff | 6 +- ...mpare_constant_index.GVN.panic-unwind.diff | 6 +- .../gvn_on_unsafe_binder.propagate.GVN.diff | 6 +- .../gvn_storage_twice.repeat_local.GVN.diff | 17 +++++ ...n_storage_twice.repeat_local_dead.GVN.diff | 19 +++++ ...rage_twice.repeat_local_dead_live.GVN.diff | 21 ++++++ tests/mir-opt/gvn_storage_twice.rs | 65 +++++++++++++++++ ...inline_diverging.h.Inline.panic-abort.diff | 1 - ...nline_diverging.h.Inline.panic-unwind.diff | 1 - ...n_storage_remove.main.GVN.panic-abort.diff | 24 +++---- ..._storage_remove.main.GVN.panic-unwind.diff | 24 +++---- ...implifyComparisonIntegral.panic-abort.diff | 2 + ...mplifyComparisonIntegral.panic-unwind.diff | 2 + ...e_75439.foo.MatchBranchSimplification.diff | 2 + ...array_len.array_bound.GVN.panic-abort.diff | 6 +- ...rray_len.array_bound.GVN.panic-unwind.diff | 6 +- ...y_len.array_bound_mut.GVN.panic-abort.diff | 6 +- ..._len.array_bound_mut.GVN.panic-unwind.diff | 6 +- ...ray_len.array_len_raw.GVN.panic-abort.diff | 6 +- ...ay_len.array_len_raw.GVN.panic-unwind.diff | 6 +- ...en.array_len_reborrow.GVN.panic-abort.diff | 6 +- ...n.array_len_reborrow.GVN.panic-unwind.diff | 6 +- ...ecked_sub.PreCodegen.after.panic-abort.mir | 14 ++-- ...cked_sub.PreCodegen.after.panic-unwind.mir | 14 ++-- ...ef_nested_borrows.src.GVN.panic-abort.diff | 6 +- ...f_nested_borrows.src.GVN.panic-unwind.diff | 6 +- ...rrows.src.PreCodegen.after.panic-abort.mir | 2 + ...rows.src.PreCodegen.after.panic-unwind.mir | 2 + .../derived_ord.demo_le.PreCodegen.after.mir | 6 +- ....{impl#0}-partial_cmp.PreCodegen.after.mir | 2 + ...d_constant.main.GVN.32bit.panic-abort.diff | 6 +- ..._constant.main.GVN.32bit.panic-unwind.diff | 6 +- ...d_constant.main.GVN.64bit.panic-abort.diff | 6 +- ..._constant.main.GVN.64bit.panic-unwind.diff | 6 +- .../loops.filter_mapped.PreCodegen.after.mir | 2 + .../loops.int_range.PreCodegen.after.mir | 5 ++ .../loops.mapped.PreCodegen.after.mir | 2 + .../loops.vec_move.PreCodegen.after.mir | 5 ++ ...ward_loop.PreCodegen.after.panic-abort.mir | 4 ++ ...ard_loop.PreCodegen.after.panic-unwind.mir | 4 ++ ...sive_loop.PreCodegen.after.panic-abort.mir | 5 ++ ...ive_loop.PreCodegen.after.panic-unwind.mir | 5 ++ ...iter_next.PreCodegen.after.panic-abort.mir | 2 + ...ter_next.PreCodegen.after.panic-unwind.mir | 2 + ...mple_option_map.ezmap.PreCodegen.after.mir | 2 + ...variant_a-{closure#0}.PreCodegen.after.mir | 8 +++ ...variant_b-{closure#0}.PreCodegen.after.mir | 8 +++ ...mut_range.PreCodegen.after.panic-abort.mir | 4 ++ ...ut_range.PreCodegen.after.panic-unwind.mir | 4 ++ ...ked_range.PreCodegen.after.panic-abort.mir | 4 ++ ...ed_range.PreCodegen.after.panic-unwind.mir | 4 ++ .../try_identity.new.PreCodegen.after.mir | 6 ++ .../try_identity.old.PreCodegen.after.mir | 4 ++ ...e_const_switch.identity.JumpThreading.diff | 4 ++ ...onst_switch.too_complex.JumpThreading.diff | 6 ++ ..._aggregate_to_copy_miscompile.foo.GVN.diff | 6 +- .../simplify_match.main.GVN.panic-abort.diff | 8 +-- .../simplify_match.main.GVN.panic-unwind.diff | 8 +-- 139 files changed, 737 insertions(+), 844 deletions(-) create mode 100644 tests/mir-opt/gvn_storage_twice.repeat_local.GVN.diff create mode 100644 tests/mir-opt/gvn_storage_twice.repeat_local_dead.GVN.diff create mode 100644 tests/mir-opt/gvn_storage_twice.repeat_local_dead_live.GVN.diff create mode 100644 tests/mir-opt/gvn_storage_twice.rs diff --git a/compiler/rustc_mir_transform/src/gvn.rs b/compiler/rustc_mir_transform/src/gvn.rs index b17b7f450009c..496a1a0acd9b7 100644 --- a/compiler/rustc_mir_transform/src/gvn.rs +++ b/compiler/rustc_mir_transform/src/gvn.rs @@ -104,6 +104,8 @@ use rustc_middle::mir::visit::*; use rustc_middle::mir::*; use rustc_middle::ty::layout::HasTypingEnv; use rustc_middle::ty::{self, Ty, TyCtxt}; +use rustc_mir_dataflow::impls::MaybeUninitializedLocals; +use rustc_mir_dataflow::{Analysis, ResultsCursor}; use rustc_span::DUMMY_SP; use rustc_span::def_id::DefId; use smallvec::SmallVec; @@ -140,10 +142,31 @@ impl<'tcx> crate::MirPass<'tcx> for GVN { state.visit_basic_block_data(bb, data); } - // For each local that is reused (`y` above), we remove its storage statements do avoid any - // difficulty. Those locals are SSA, so should be easy to optimize by LLVM without storage - // statements. - StorageRemover { tcx, reused_locals: state.reused_locals }.visit_body_preserves_cfg(body); + // If we emit storage annotations, use `MaybeStorageDead` to check which reused locals + // require storage removal (making them alive for the duration of the function). + let storage_to_remove = if tcx.sess.emit_lifetime_markers() { + let maybe_uninit = MaybeUninitializedLocals::new() + .iterate_to_fixpoint(tcx, body, Some("mir_opt::gvn")) + .into_results_cursor(body); + + let mut storage_checker = StorageChecker { + storage_to_check: state.reused_locals.clone(), + storage_to_remove: DenseBitSet::new_empty(body.local_decls.len()), + maybe_uninit, + }; + + storage_checker.visit_body(body); + + storage_checker.storage_to_remove + } else { + // Conservatively remove all storage statements for reused locals. + state.reused_locals.clone() + }; + + debug!(?storage_to_remove); + + StorageRemover { tcx, reused_locals: state.reused_locals, storage_to_remove } + .visit_body_preserves_cfg(body); } fn is_required(&self) -> bool { @@ -1824,6 +1847,7 @@ impl<'tcx> MutVisitor<'tcx> for VnState<'_, 'tcx> { struct StorageRemover<'tcx> { tcx: TyCtxt<'tcx>, reused_locals: DenseBitSet, + storage_to_remove: DenseBitSet, } impl<'tcx> MutVisitor<'tcx> for StorageRemover<'tcx> { @@ -1844,7 +1868,7 @@ impl<'tcx> MutVisitor<'tcx> for StorageRemover<'tcx> { match stmt.kind { // When removing storage statements, we need to remove both (#107511). StatementKind::StorageLive(l) | StatementKind::StorageDead(l) - if self.reused_locals.contains(l) => + if self.storage_to_remove.contains(l) => { stmt.make_nop() } @@ -1852,3 +1876,40 @@ impl<'tcx> MutVisitor<'tcx> for StorageRemover<'tcx> { } } } + +struct StorageChecker<'a, 'tcx> { + storage_to_check: DenseBitSet, + storage_to_remove: DenseBitSet, + maybe_uninit: ResultsCursor<'a, 'tcx, MaybeUninitializedLocals>, +} + +impl<'a, 'tcx> Visitor<'tcx> for StorageChecker<'a, 'tcx> { + fn visit_local(&mut self, local: Local, context: PlaceContext, location: Location) { + match context { + // These mutating uses do not require the local to be initialized. + PlaceContext::MutatingUse(MutatingUseContext::AsmOutput) + | PlaceContext::MutatingUse(MutatingUseContext::Call) + | PlaceContext::MutatingUse(MutatingUseContext::Store) + | PlaceContext::MutatingUse(MutatingUseContext::Yield) + | PlaceContext::NonUse(_) => { + return; + } + // Must check validity for other mutating usages and all non-mutating uses. + PlaceContext::MutatingUse(_) | PlaceContext::NonMutatingUse(_) => {} + } + + if self.storage_to_check.contains(local) { + self.maybe_uninit.seek_before_primary_effect(location); + + if self.maybe_uninit.get().contains(local) { + debug!( + ?location, + ?local, + "local is maybe uninit in this location, removing storage" + ); + self.storage_to_remove.insert(local); + self.storage_to_check.remove(local); + } + } + } +} diff --git a/tests/mir-opt/const_debuginfo.main.SingleUseConsts.diff b/tests/mir-opt/const_debuginfo.main.SingleUseConsts.diff index 8088984bc77ab..b3a908a154734 100644 --- a/tests/mir-opt/const_debuginfo.main.SingleUseConsts.diff +++ b/tests/mir-opt/const_debuginfo.main.SingleUseConsts.diff @@ -55,14 +55,14 @@ } bb0: { - nop; + StorageLive(_1); - _1 = const 1_u8; - nop; -- _2 = const 2_u8; - nop; -- _3 = const 3_u8; + nop; + StorageLive(_2); +- _2 = const 2_u8; + nop; + StorageLive(_3); +- _3 = const 3_u8; + nop; StorageLive(_4); StorageLive(_5); @@ -95,7 +95,7 @@ - _12 = const Point {{ x: 32_u32, y: 32_u32 }}; + nop; StorageLive(_13); - nop; + StorageLive(_14); - _14 = const 32_u32; + nop; StorageLive(_15); @@ -104,7 +104,7 @@ + nop; + nop; StorageDead(_15); - nop; + StorageDead(_14); _0 = const (); StorageDead(_13); StorageDead(_12); @@ -112,9 +112,9 @@ StorageDead(_10); StorageDead(_9); StorageDead(_4); - nop; - nop; - nop; + StorageDead(_3); + StorageDead(_2); + StorageDead(_1); return; } } diff --git a/tests/mir-opt/const_prop/aggregate.main.GVN.panic-abort.diff b/tests/mir-opt/const_prop/aggregate.main.GVN.panic-abort.diff index 0a59c59c2ed2c..3371c19360f92 100644 --- a/tests/mir-opt/const_prop/aggregate.main.GVN.panic-abort.diff +++ b/tests/mir-opt/const_prop/aggregate.main.GVN.panic-abort.diff @@ -13,8 +13,7 @@ } bb0: { -- StorageLive(_1); -+ nop; + StorageLive(_1); StorageLive(_2); StorageLive(_3); _3 = (const 0_i32, const 1_u8, const 2_i32); @@ -36,8 +35,7 @@ StorageDead(_5); StorageDead(_4); _0 = const (); -- StorageDead(_1); -+ nop; + StorageDead(_1); return; } } diff --git a/tests/mir-opt/const_prop/aggregate.main.GVN.panic-unwind.diff b/tests/mir-opt/const_prop/aggregate.main.GVN.panic-unwind.diff index 100369a2eee31..a0f9e7a117996 100644 --- a/tests/mir-opt/const_prop/aggregate.main.GVN.panic-unwind.diff +++ b/tests/mir-opt/const_prop/aggregate.main.GVN.panic-unwind.diff @@ -13,8 +13,7 @@ } bb0: { -- StorageLive(_1); -+ nop; + StorageLive(_1); StorageLive(_2); StorageLive(_3); _3 = (const 0_i32, const 1_u8, const 2_i32); @@ -36,8 +35,7 @@ StorageDead(_5); StorageDead(_4); _0 = const (); -- StorageDead(_1); -+ nop; + StorageDead(_1); return; } } diff --git a/tests/mir-opt/const_prop/bad_op_div_by_zero.main.GVN.panic-abort.diff b/tests/mir-opt/const_prop/bad_op_div_by_zero.main.GVN.panic-abort.diff index 8c535b567c328..d6551b8e3e741 100644 --- a/tests/mir-opt/const_prop/bad_op_div_by_zero.main.GVN.panic-abort.diff +++ b/tests/mir-opt/const_prop/bad_op_div_by_zero.main.GVN.panic-abort.diff @@ -18,8 +18,7 @@ } bb0: { -- StorageLive(_1); -+ nop; + StorageLive(_1); _1 = const 0_i32; StorageLive(_2); StorageLive(_3); @@ -48,8 +47,7 @@ StorageDead(_3); _0 = const (); StorageDead(_2); -- StorageDead(_1); -+ nop; + StorageDead(_1); return; } } diff --git a/tests/mir-opt/const_prop/bad_op_div_by_zero.main.GVN.panic-unwind.diff b/tests/mir-opt/const_prop/bad_op_div_by_zero.main.GVN.panic-unwind.diff index 045f4d81db62e..3dbd6ca6769cb 100644 --- a/tests/mir-opt/const_prop/bad_op_div_by_zero.main.GVN.panic-unwind.diff +++ b/tests/mir-opt/const_prop/bad_op_div_by_zero.main.GVN.panic-unwind.diff @@ -18,8 +18,7 @@ } bb0: { -- StorageLive(_1); -+ nop; + StorageLive(_1); _1 = const 0_i32; StorageLive(_2); StorageLive(_3); @@ -48,8 +47,7 @@ StorageDead(_3); _0 = const (); StorageDead(_2); -- StorageDead(_1); -+ nop; + StorageDead(_1); return; } } diff --git a/tests/mir-opt/const_prop/bad_op_mod_by_zero.main.GVN.panic-abort.diff b/tests/mir-opt/const_prop/bad_op_mod_by_zero.main.GVN.panic-abort.diff index e5a8726b855c4..eac751a231bd3 100644 --- a/tests/mir-opt/const_prop/bad_op_mod_by_zero.main.GVN.panic-abort.diff +++ b/tests/mir-opt/const_prop/bad_op_mod_by_zero.main.GVN.panic-abort.diff @@ -18,8 +18,7 @@ } bb0: { -- StorageLive(_1); -+ nop; + StorageLive(_1); _1 = const 0_i32; StorageLive(_2); StorageLive(_3); @@ -48,8 +47,7 @@ StorageDead(_3); _0 = const (); StorageDead(_2); -- StorageDead(_1); -+ nop; + StorageDead(_1); return; } } diff --git a/tests/mir-opt/const_prop/bad_op_mod_by_zero.main.GVN.panic-unwind.diff b/tests/mir-opt/const_prop/bad_op_mod_by_zero.main.GVN.panic-unwind.diff index 1110ff186dc6e..72b13008f5c50 100644 --- a/tests/mir-opt/const_prop/bad_op_mod_by_zero.main.GVN.panic-unwind.diff +++ b/tests/mir-opt/const_prop/bad_op_mod_by_zero.main.GVN.panic-unwind.diff @@ -18,8 +18,7 @@ } bb0: { -- StorageLive(_1); -+ nop; + StorageLive(_1); _1 = const 0_i32; StorageLive(_2); StorageLive(_3); @@ -48,8 +47,7 @@ StorageDead(_3); _0 = const (); StorageDead(_2); -- StorageDead(_1); -+ nop; + StorageDead(_1); return; } } diff --git a/tests/mir-opt/const_prop/boolean_identities.test.GVN.diff b/tests/mir-opt/const_prop/boolean_identities.test.GVN.diff index 3fe70302b21cf..2b389e815ce4e 100644 --- a/tests/mir-opt/const_prop/boolean_identities.test.GVN.diff +++ b/tests/mir-opt/const_prop/boolean_identities.test.GVN.diff @@ -19,15 +19,13 @@ } bb0: { -- StorageLive(_3); -+ nop; + StorageLive(_3); StorageLive(_4); _4 = copy _2; - _3 = BitOr(move _4, const true); + _3 = const true; StorageDead(_4); -- StorageLive(_5); -+ nop; + StorageLive(_5); StorageLive(_6); _6 = copy _1; - _5 = BitAnd(move _6, const false); @@ -43,10 +41,8 @@ + _0 = const false; StorageDead(_8); StorageDead(_7); -- StorageDead(_5); -- StorageDead(_3); -+ nop; -+ nop; + StorageDead(_5); + StorageDead(_3); return; } } diff --git a/tests/mir-opt/const_prop/boxes.main.GVN.panic-abort.diff b/tests/mir-opt/const_prop/boxes.main.GVN.panic-abort.diff index f43c0cca9ad28..fc22060f96ed1 100644 --- a/tests/mir-opt/const_prop/boxes.main.GVN.panic-abort.diff +++ b/tests/mir-opt/const_prop/boxes.main.GVN.panic-abort.diff @@ -18,8 +18,7 @@ bb0: { StorageLive(_1); -- StorageLive(_2); -+ nop; + StorageLive(_2); StorageLive(_3); - _4 = SizeOf(i32); - _5 = AlignOf(i32); @@ -39,9 +38,8 @@ _9 = copy ((_3.0: std::ptr::Unique).0: std::ptr::NonNull) as *const i32 (Transmute); _2 = copy (*_9); - _1 = Add(move _2, const 0_i32); -- StorageDead(_2); + _1 = copy _2; -+ nop; + StorageDead(_2); drop(_3) -> [return: bb2, unwind unreachable]; } diff --git a/tests/mir-opt/const_prop/boxes.main.GVN.panic-unwind.diff b/tests/mir-opt/const_prop/boxes.main.GVN.panic-unwind.diff index 2c903b6d85349..857f6163ca5c6 100644 --- a/tests/mir-opt/const_prop/boxes.main.GVN.panic-unwind.diff +++ b/tests/mir-opt/const_prop/boxes.main.GVN.panic-unwind.diff @@ -18,8 +18,7 @@ bb0: { StorageLive(_1); -- StorageLive(_2); -+ nop; + StorageLive(_2); StorageLive(_3); - _4 = SizeOf(i32); - _5 = AlignOf(i32); @@ -39,9 +38,8 @@ _9 = copy ((_3.0: std::ptr::Unique).0: std::ptr::NonNull) as *const i32 (Transmute); _2 = copy (*_9); - _1 = Add(move _2, const 0_i32); -- StorageDead(_2); + _1 = copy _2; -+ nop; + StorageDead(_2); drop(_3) -> [return: bb2, unwind: bb3]; } diff --git a/tests/mir-opt/const_prop/mutable_variable_unprop_assign.main.GVN.panic-abort.diff b/tests/mir-opt/const_prop/mutable_variable_unprop_assign.main.GVN.panic-abort.diff index 7ca1b39d77110..405ef7f54d654 100644 --- a/tests/mir-opt/const_prop/mutable_variable_unprop_assign.main.GVN.panic-abort.diff +++ b/tests/mir-opt/const_prop/mutable_variable_unprop_assign.main.GVN.panic-abort.diff @@ -22,8 +22,7 @@ } bb0: { -- StorageLive(_1); -+ nop; + StorageLive(_1); _1 = foo() -> [return: bb1, unwind unreachable]; } @@ -44,8 +43,7 @@ StorageDead(_5); StorageDead(_4); StorageDead(_2); -- StorageDead(_1); -+ nop; + StorageDead(_1); return; } } diff --git a/tests/mir-opt/const_prop/mutable_variable_unprop_assign.main.GVN.panic-unwind.diff b/tests/mir-opt/const_prop/mutable_variable_unprop_assign.main.GVN.panic-unwind.diff index f637951380664..49782bb44c2a0 100644 --- a/tests/mir-opt/const_prop/mutable_variable_unprop_assign.main.GVN.panic-unwind.diff +++ b/tests/mir-opt/const_prop/mutable_variable_unprop_assign.main.GVN.panic-unwind.diff @@ -22,8 +22,7 @@ } bb0: { -- StorageLive(_1); -+ nop; + StorageLive(_1); _1 = foo() -> [return: bb1, unwind continue]; } @@ -44,8 +43,7 @@ StorageDead(_5); StorageDead(_4); StorageDead(_2); -- StorageDead(_1); -+ nop; + StorageDead(_1); return; } } diff --git a/tests/mir-opt/const_prop/pointer_expose_provenance.main.GVN.panic-abort.diff b/tests/mir-opt/const_prop/pointer_expose_provenance.main.GVN.panic-abort.diff index 657fa7a5fea19..c6991c0a3bb4d 100644 --- a/tests/mir-opt/const_prop/pointer_expose_provenance.main.GVN.panic-abort.diff +++ b/tests/mir-opt/const_prop/pointer_expose_provenance.main.GVN.panic-abort.diff @@ -13,8 +13,7 @@ } bb0: { -- StorageLive(_1); -+ nop; + StorageLive(_1); StorageLive(_2); StorageLive(_3); _3 = const main::FOO; @@ -33,8 +32,7 @@ StorageDead(_5); StorageDead(_4); _0 = const (); -- StorageDead(_1); -+ nop; + StorageDead(_1); return; } } diff --git a/tests/mir-opt/const_prop/pointer_expose_provenance.main.GVN.panic-unwind.diff b/tests/mir-opt/const_prop/pointer_expose_provenance.main.GVN.panic-unwind.diff index 8fef6591d41d9..04a43e5973a88 100644 --- a/tests/mir-opt/const_prop/pointer_expose_provenance.main.GVN.panic-unwind.diff +++ b/tests/mir-opt/const_prop/pointer_expose_provenance.main.GVN.panic-unwind.diff @@ -13,8 +13,7 @@ } bb0: { -- StorageLive(_1); -+ nop; + StorageLive(_1); StorageLive(_2); StorageLive(_3); _3 = const main::FOO; @@ -33,8 +32,7 @@ StorageDead(_5); StorageDead(_4); _0 = const (); -- StorageDead(_1); -+ nop; + StorageDead(_1); return; } } diff --git a/tests/mir-opt/const_prop/read_immutable_static.main.GVN.diff b/tests/mir-opt/const_prop/read_immutable_static.main.GVN.diff index 8df262b351f12..1d8c05a4d6a9c 100644 --- a/tests/mir-opt/const_prop/read_immutable_static.main.GVN.diff +++ b/tests/mir-opt/const_prop/read_immutable_static.main.GVN.diff @@ -14,10 +14,8 @@ bb0: { StorageLive(_1); -- StorageLive(_2); -- StorageLive(_3); -+ nop; -+ nop; + StorageLive(_2); + StorageLive(_3); _3 = const {ALLOC0: &u8}; - _2 = copy (*_3); + _2 = const 2_u8; @@ -29,11 +27,9 @@ + _4 = const 2_u8; + _1 = const 4_u8; StorageDead(_4); -- StorageDead(_2); -+ nop; + StorageDead(_2); StorageDead(_5); -- StorageDead(_3); -+ nop; + StorageDead(_3); _0 = const (); StorageDead(_1); return; diff --git a/tests/mir-opt/const_prop/scalar_literal_propagation.main.GVN.panic-abort.diff b/tests/mir-opt/const_prop/scalar_literal_propagation.main.GVN.panic-abort.diff index 3c73d34474c13..83093cc337cb3 100644 --- a/tests/mir-opt/const_prop/scalar_literal_propagation.main.GVN.panic-abort.diff +++ b/tests/mir-opt/const_prop/scalar_literal_propagation.main.GVN.panic-abort.diff @@ -11,8 +11,7 @@ } bb0: { -- StorageLive(_1); -+ nop; + StorageLive(_1); _1 = const 1_u32; StorageLive(_2); StorageLive(_3); @@ -26,8 +25,7 @@ StorageDead(_3); StorageDead(_2); _0 = const (); -- StorageDead(_1); -+ nop; + StorageDead(_1); return; } } diff --git a/tests/mir-opt/const_prop/scalar_literal_propagation.main.GVN.panic-unwind.diff b/tests/mir-opt/const_prop/scalar_literal_propagation.main.GVN.panic-unwind.diff index 0a7fddee39b62..804763b4f399b 100644 --- a/tests/mir-opt/const_prop/scalar_literal_propagation.main.GVN.panic-unwind.diff +++ b/tests/mir-opt/const_prop/scalar_literal_propagation.main.GVN.panic-unwind.diff @@ -11,8 +11,7 @@ } bb0: { -- StorageLive(_1); -+ nop; + StorageLive(_1); _1 = const 1_u32; StorageLive(_2); StorageLive(_3); @@ -26,8 +25,7 @@ StorageDead(_3); StorageDead(_2); _0 = const (); -- StorageDead(_1); -+ nop; + StorageDead(_1); return; } } diff --git a/tests/mir-opt/const_prop/tuple_literal_propagation.main.GVN.panic-abort.diff b/tests/mir-opt/const_prop/tuple_literal_propagation.main.GVN.panic-abort.diff index 01d86ce8717d1..402482eb4e006 100644 --- a/tests/mir-opt/const_prop/tuple_literal_propagation.main.GVN.panic-abort.diff +++ b/tests/mir-opt/const_prop/tuple_literal_propagation.main.GVN.panic-abort.diff @@ -11,9 +11,8 @@ } bb0: { -- StorageLive(_1); + StorageLive(_1); - _1 = (const 1_u32, const 2_u32); -+ nop; + _1 = const (1_u32, 2_u32); StorageLive(_2); StorageLive(_3); @@ -27,8 +26,7 @@ StorageDead(_3); StorageDead(_2); _0 = const (); -- StorageDead(_1); -+ nop; + StorageDead(_1); return; } } diff --git a/tests/mir-opt/const_prop/tuple_literal_propagation.main.GVN.panic-unwind.diff b/tests/mir-opt/const_prop/tuple_literal_propagation.main.GVN.panic-unwind.diff index bd7d494212ce6..2f1c5f1c0b0de 100644 --- a/tests/mir-opt/const_prop/tuple_literal_propagation.main.GVN.panic-unwind.diff +++ b/tests/mir-opt/const_prop/tuple_literal_propagation.main.GVN.panic-unwind.diff @@ -11,9 +11,8 @@ } bb0: { -- StorageLive(_1); + StorageLive(_1); - _1 = (const 1_u32, const 2_u32); -+ nop; + _1 = const (1_u32, 2_u32); StorageLive(_2); StorageLive(_3); @@ -27,8 +26,7 @@ StorageDead(_3); StorageDead(_2); _0 = const (); -- StorageDead(_1); -+ nop; + StorageDead(_1); return; } } diff --git a/tests/mir-opt/dont_reset_cast_kind_without_updating_operand.test.GVN.32bit.panic-abort.diff b/tests/mir-opt/dont_reset_cast_kind_without_updating_operand.test.GVN.32bit.panic-abort.diff index 25ffff619e60b..deb1c67f86d47 100644 --- a/tests/mir-opt/dont_reset_cast_kind_without_updating_operand.test.GVN.32bit.panic-abort.diff +++ b/tests/mir-opt/dont_reset_cast_kind_without_updating_operand.test.GVN.32bit.panic-abort.diff @@ -124,8 +124,7 @@ + _9 = copy _3; _10 = copy ((_9.0: std::ptr::Unique<()>).0: std::ptr::NonNull<()>) as *const () (Transmute); _4 = copy _10; -- StorageLive(_5); -+ nop; + StorageLive(_5); StorageLive(_6); - _6 = copy _4; + _6 = copy _10; @@ -142,8 +141,7 @@ + _7 = copy ((_9.0: std::ptr::Unique<()>).0: std::ptr::NonNull<()>) as *mut () (Transmute); StorageDead(_8); StorageDead(_7); -- StorageDead(_5); -+ nop; + StorageDead(_5); StorageDead(_4); drop(_3) -> [return: bb1, unwind unreachable]; } diff --git a/tests/mir-opt/dont_reset_cast_kind_without_updating_operand.test.GVN.32bit.panic-unwind.diff b/tests/mir-opt/dont_reset_cast_kind_without_updating_operand.test.GVN.32bit.panic-unwind.diff index b2085afb71379..30d8d63850a21 100644 --- a/tests/mir-opt/dont_reset_cast_kind_without_updating_operand.test.GVN.32bit.panic-unwind.diff +++ b/tests/mir-opt/dont_reset_cast_kind_without_updating_operand.test.GVN.32bit.panic-unwind.diff @@ -49,8 +49,7 @@ + _9 = copy _3; _10 = copy ((_9.0: std::ptr::Unique<()>).0: std::ptr::NonNull<()>) as *const () (Transmute); _4 = copy _10; -- StorageLive(_5); -+ nop; + StorageLive(_5); StorageLive(_6); - _6 = copy _4; + _6 = copy _10; @@ -67,8 +66,7 @@ + _7 = copy ((_9.0: std::ptr::Unique<()>).0: std::ptr::NonNull<()>) as *mut () (Transmute); StorageDead(_8); StorageDead(_7); -- StorageDead(_5); -+ nop; + StorageDead(_5); StorageDead(_4); drop(_3) -> [return: bb2, unwind: bb3]; } diff --git a/tests/mir-opt/dont_reset_cast_kind_without_updating_operand.test.GVN.64bit.panic-abort.diff b/tests/mir-opt/dont_reset_cast_kind_without_updating_operand.test.GVN.64bit.panic-abort.diff index 839b53e3b0b3b..1fb578530d9a5 100644 --- a/tests/mir-opt/dont_reset_cast_kind_without_updating_operand.test.GVN.64bit.panic-abort.diff +++ b/tests/mir-opt/dont_reset_cast_kind_without_updating_operand.test.GVN.64bit.panic-abort.diff @@ -124,8 +124,7 @@ + _9 = copy _3; _10 = copy ((_9.0: std::ptr::Unique<()>).0: std::ptr::NonNull<()>) as *const () (Transmute); _4 = copy _10; -- StorageLive(_5); -+ nop; + StorageLive(_5); StorageLive(_6); - _6 = copy _4; + _6 = copy _10; @@ -142,8 +141,7 @@ + _7 = copy ((_9.0: std::ptr::Unique<()>).0: std::ptr::NonNull<()>) as *mut () (Transmute); StorageDead(_8); StorageDead(_7); -- StorageDead(_5); -+ nop; + StorageDead(_5); StorageDead(_4); drop(_3) -> [return: bb1, unwind unreachable]; } diff --git a/tests/mir-opt/dont_reset_cast_kind_without_updating_operand.test.GVN.64bit.panic-unwind.diff b/tests/mir-opt/dont_reset_cast_kind_without_updating_operand.test.GVN.64bit.panic-unwind.diff index b2085afb71379..30d8d63850a21 100644 --- a/tests/mir-opt/dont_reset_cast_kind_without_updating_operand.test.GVN.64bit.panic-unwind.diff +++ b/tests/mir-opt/dont_reset_cast_kind_without_updating_operand.test.GVN.64bit.panic-unwind.diff @@ -49,8 +49,7 @@ + _9 = copy _3; _10 = copy ((_9.0: std::ptr::Unique<()>).0: std::ptr::NonNull<()>) as *const () (Transmute); _4 = copy _10; -- StorageLive(_5); -+ nop; + StorageLive(_5); StorageLive(_6); - _6 = copy _4; + _6 = copy _10; @@ -67,8 +66,7 @@ + _7 = copy ((_9.0: std::ptr::Unique<()>).0: std::ptr::NonNull<()>) as *mut () (Transmute); StorageDead(_8); StorageDead(_7); -- StorageDead(_5); -+ nop; + StorageDead(_5); StorageDead(_4); drop(_3) -> [return: bb2, unwind: bb3]; } diff --git a/tests/mir-opt/funky_arms.float_to_exponential_common.GVN.32bit.panic-abort.diff b/tests/mir-opt/funky_arms.float_to_exponential_common.GVN.32bit.panic-abort.diff index 6baa902b6f4bd..14058c5944bb6 100644 --- a/tests/mir-opt/funky_arms.float_to_exponential_common.GVN.32bit.panic-abort.diff +++ b/tests/mir-opt/funky_arms.float_to_exponential_common.GVN.32bit.panic-abort.diff @@ -78,8 +78,7 @@ } bb4: { -- StorageLive(_8); -+ nop; + StorageLive(_8); _8 = copy ((_6 as Some).0: usize); StorageLive(_9); _9 = copy _1; @@ -108,8 +107,7 @@ StorageDead(_11); StorageDead(_10); StorageDead(_9); -- StorageDead(_8); -+ nop; + StorageDead(_8); goto -> bb8; } diff --git a/tests/mir-opt/funky_arms.float_to_exponential_common.GVN.32bit.panic-unwind.diff b/tests/mir-opt/funky_arms.float_to_exponential_common.GVN.32bit.panic-unwind.diff index 36540e038654f..24c3ae1b1b2d4 100644 --- a/tests/mir-opt/funky_arms.float_to_exponential_common.GVN.32bit.panic-unwind.diff +++ b/tests/mir-opt/funky_arms.float_to_exponential_common.GVN.32bit.panic-unwind.diff @@ -78,8 +78,7 @@ } bb4: { -- StorageLive(_8); -+ nop; + StorageLive(_8); _8 = copy ((_6 as Some).0: usize); StorageLive(_9); _9 = copy _1; @@ -108,8 +107,7 @@ StorageDead(_11); StorageDead(_10); StorageDead(_9); -- StorageDead(_8); -+ nop; + StorageDead(_8); goto -> bb8; } diff --git a/tests/mir-opt/funky_arms.float_to_exponential_common.GVN.64bit.panic-abort.diff b/tests/mir-opt/funky_arms.float_to_exponential_common.GVN.64bit.panic-abort.diff index 41c350f3eaeb5..ffbb51be657d9 100644 --- a/tests/mir-opt/funky_arms.float_to_exponential_common.GVN.64bit.panic-abort.diff +++ b/tests/mir-opt/funky_arms.float_to_exponential_common.GVN.64bit.panic-abort.diff @@ -78,8 +78,7 @@ } bb4: { -- StorageLive(_8); -+ nop; + StorageLive(_8); _8 = copy ((_6 as Some).0: usize); StorageLive(_9); _9 = copy _1; @@ -108,8 +107,7 @@ StorageDead(_11); StorageDead(_10); StorageDead(_9); -- StorageDead(_8); -+ nop; + StorageDead(_8); goto -> bb8; } diff --git a/tests/mir-opt/funky_arms.float_to_exponential_common.GVN.64bit.panic-unwind.diff b/tests/mir-opt/funky_arms.float_to_exponential_common.GVN.64bit.panic-unwind.diff index b839bf81eaf45..1fbac464c9d34 100644 --- a/tests/mir-opt/funky_arms.float_to_exponential_common.GVN.64bit.panic-unwind.diff +++ b/tests/mir-opt/funky_arms.float_to_exponential_common.GVN.64bit.panic-unwind.diff @@ -78,8 +78,7 @@ } bb4: { -- StorageLive(_8); -+ nop; + StorageLive(_8); _8 = copy ((_6 as Some).0: usize); StorageLive(_9); _9 = copy _1; @@ -108,8 +107,7 @@ StorageDead(_11); StorageDead(_10); StorageDead(_9); -- StorageDead(_8); -+ nop; + StorageDead(_8); goto -> bb8; } diff --git a/tests/mir-opt/gvn.aggregate_struct_then_transmute.GVN.panic-abort.diff b/tests/mir-opt/gvn.aggregate_struct_then_transmute.GVN.panic-abort.diff index 5ae575f300afb..9f8a839eee9a0 100644 --- a/tests/mir-opt/gvn.aggregate_struct_then_transmute.GVN.panic-abort.diff +++ b/tests/mir-opt/gvn.aggregate_struct_then_transmute.GVN.panic-abort.diff @@ -91,8 +91,7 @@ } bb0: { -- StorageLive(_3); -+ nop; + StorageLive(_3); StorageLive(_4); _4 = copy _1; - _3 = MyId(move _4); @@ -113,8 +112,7 @@ bb1: { StorageDead(_6); StorageDead(_5); -- StorageLive(_8); -+ nop; + StorageLive(_8); StorageLive(_9); _9 = copy _1; StorageLive(_10); @@ -139,8 +137,7 @@ bb2: { StorageDead(_12); StorageDead(_11); -- StorageLive(_14); -+ nop; + StorageLive(_14); StorageLive(_15); _15 = copy _1; - _14 = Result::::Err(move _15); @@ -161,8 +158,7 @@ bb3: { StorageDead(_17); StorageDead(_16); -- StorageLive(_19); -+ nop; + StorageLive(_19); StorageLive(_20); _20 = copy _1; - _19 = Option::::Some(move _20); @@ -201,8 +197,7 @@ bb5: { StorageDead(_27); StorageDead(_26); -- StorageLive(_29); -+ nop; + StorageLive(_29); StorageLive(_30); _30 = copy _1; StorageLive(_31); @@ -248,8 +243,7 @@ bb7: { StorageDead(_39); StorageDead(_38); -- StorageLive(_41); -+ nop; + StorageLive(_41); StorageLive(_42); _42 = copy _1; - _41 = (move _42,); @@ -269,8 +263,7 @@ bb8: { StorageDead(_44); StorageDead(_43); -- StorageLive(_46); -+ nop; + StorageLive(_46); StorageLive(_47); _47 = copy _1; - _46 = [move _47]; @@ -290,8 +283,7 @@ bb9: { StorageDead(_49); StorageDead(_48); -- StorageLive(_51); -+ nop; + StorageLive(_51); StorageLive(_52); _52 = copy _2; StorageLive(_53); @@ -316,24 +308,16 @@ StorageDead(_55); StorageDead(_54); _0 = const (); -- StorageDead(_51); -- StorageDead(_46); -- StorageDead(_41); -+ nop; -+ nop; -+ nop; + StorageDead(_51); + StorageDead(_46); + StorageDead(_41); StorageDead(_35); -- StorageDead(_29); -+ nop; + StorageDead(_29); StorageDead(_24); -- StorageDead(_19); -- StorageDead(_14); -- StorageDead(_8); -- StorageDead(_3); -+ nop; -+ nop; -+ nop; -+ nop; + StorageDead(_19); + StorageDead(_14); + StorageDead(_8); + StorageDead(_3); return; } } diff --git a/tests/mir-opt/gvn.aggregate_struct_then_transmute.GVN.panic-unwind.diff b/tests/mir-opt/gvn.aggregate_struct_then_transmute.GVN.panic-unwind.diff index 3119a93fb8912..f04f778349dba 100644 --- a/tests/mir-opt/gvn.aggregate_struct_then_transmute.GVN.panic-unwind.diff +++ b/tests/mir-opt/gvn.aggregate_struct_then_transmute.GVN.panic-unwind.diff @@ -91,8 +91,7 @@ } bb0: { -- StorageLive(_3); -+ nop; + StorageLive(_3); StorageLive(_4); _4 = copy _1; - _3 = MyId(move _4); @@ -113,8 +112,7 @@ bb1: { StorageDead(_6); StorageDead(_5); -- StorageLive(_8); -+ nop; + StorageLive(_8); StorageLive(_9); _9 = copy _1; StorageLive(_10); @@ -139,8 +137,7 @@ bb2: { StorageDead(_12); StorageDead(_11); -- StorageLive(_14); -+ nop; + StorageLive(_14); StorageLive(_15); _15 = copy _1; - _14 = Result::::Err(move _15); @@ -161,8 +158,7 @@ bb3: { StorageDead(_17); StorageDead(_16); -- StorageLive(_19); -+ nop; + StorageLive(_19); StorageLive(_20); _20 = copy _1; - _19 = Option::::Some(move _20); @@ -201,8 +197,7 @@ bb5: { StorageDead(_27); StorageDead(_26); -- StorageLive(_29); -+ nop; + StorageLive(_29); StorageLive(_30); _30 = copy _1; StorageLive(_31); @@ -248,8 +243,7 @@ bb7: { StorageDead(_39); StorageDead(_38); -- StorageLive(_41); -+ nop; + StorageLive(_41); StorageLive(_42); _42 = copy _1; - _41 = (move _42,); @@ -269,8 +263,7 @@ bb8: { StorageDead(_44); StorageDead(_43); -- StorageLive(_46); -+ nop; + StorageLive(_46); StorageLive(_47); _47 = copy _1; - _46 = [move _47]; @@ -290,8 +283,7 @@ bb9: { StorageDead(_49); StorageDead(_48); -- StorageLive(_51); -+ nop; + StorageLive(_51); StorageLive(_52); _52 = copy _2; StorageLive(_53); @@ -316,24 +308,16 @@ StorageDead(_55); StorageDead(_54); _0 = const (); -- StorageDead(_51); -- StorageDead(_46); -- StorageDead(_41); -+ nop; -+ nop; -+ nop; + StorageDead(_51); + StorageDead(_46); + StorageDead(_41); StorageDead(_35); -- StorageDead(_29); -+ nop; + StorageDead(_29); StorageDead(_24); -- StorageDead(_19); -- StorageDead(_14); -- StorageDead(_8); -- StorageDead(_3); -+ nop; -+ nop; -+ nop; -+ nop; + StorageDead(_19); + StorageDead(_14); + StorageDead(_8); + StorageDead(_3); return; } } diff --git a/tests/mir-opt/gvn.arithmetic.GVN.panic-abort.diff b/tests/mir-opt/gvn.arithmetic.GVN.panic-abort.diff index f980645b1d092..363c2f6ad37cf 100644 --- a/tests/mir-opt/gvn.arithmetic.GVN.panic-abort.diff +++ b/tests/mir-opt/gvn.arithmetic.GVN.panic-abort.diff @@ -108,8 +108,7 @@ StorageDead(_6); StorageDead(_5); StorageLive(_8); -- StorageLive(_9); -+ nop; + StorageLive(_9); StorageLive(_10); _10 = copy _1; StorageLive(_11); @@ -123,8 +122,7 @@ } bb3: { -- StorageDead(_9); -+ nop; + StorageDead(_9); StorageDead(_8); StorageLive(_12); StorageLive(_13); diff --git a/tests/mir-opt/gvn.arithmetic.GVN.panic-unwind.diff b/tests/mir-opt/gvn.arithmetic.GVN.panic-unwind.diff index b8e4967fe8b18..f135532a3f202 100644 --- a/tests/mir-opt/gvn.arithmetic.GVN.panic-unwind.diff +++ b/tests/mir-opt/gvn.arithmetic.GVN.panic-unwind.diff @@ -108,8 +108,7 @@ StorageDead(_6); StorageDead(_5); StorageLive(_8); -- StorageLive(_9); -+ nop; + StorageLive(_9); StorageLive(_10); _10 = copy _1; StorageLive(_11); @@ -123,8 +122,7 @@ } bb3: { -- StorageDead(_9); -+ nop; + StorageDead(_9); StorageDead(_8); StorageLive(_12); StorageLive(_13); diff --git a/tests/mir-opt/gvn.arithmetic_checked.GVN.panic-abort.diff b/tests/mir-opt/gvn.arithmetic_checked.GVN.panic-abort.diff index acf8bfc71beda..03db197c6a6cc 100644 --- a/tests/mir-opt/gvn.arithmetic_checked.GVN.panic-abort.diff +++ b/tests/mir-opt/gvn.arithmetic_checked.GVN.panic-abort.diff @@ -70,8 +70,7 @@ StorageDead(_7); StorageDead(_6); StorageLive(_10); -- StorageLive(_11); -+ nop; + StorageLive(_11); StorageLive(_12); _12 = copy _1; StorageLive(_13); @@ -92,8 +91,7 @@ } bb6: { -- StorageDead(_11); -+ nop; + StorageDead(_11); StorageDead(_10); StorageLive(_15); StorageLive(_16); diff --git a/tests/mir-opt/gvn.arithmetic_checked.GVN.panic-unwind.diff b/tests/mir-opt/gvn.arithmetic_checked.GVN.panic-unwind.diff index f3f6b381a81ca..61d4ec54a14d7 100644 --- a/tests/mir-opt/gvn.arithmetic_checked.GVN.panic-unwind.diff +++ b/tests/mir-opt/gvn.arithmetic_checked.GVN.panic-unwind.diff @@ -70,8 +70,7 @@ StorageDead(_7); StorageDead(_6); StorageLive(_10); -- StorageLive(_11); -+ nop; + StorageLive(_11); StorageLive(_12); _12 = copy _1; StorageLive(_13); @@ -92,8 +91,7 @@ } bb6: { -- StorageDead(_11); -+ nop; + StorageDead(_11); StorageDead(_10); StorageLive(_15); StorageLive(_16); diff --git a/tests/mir-opt/gvn.array_len.GVN.panic-abort.diff b/tests/mir-opt/gvn.array_len.GVN.panic-abort.diff index 0d0477fe7729f..59b65a52f4ee6 100644 --- a/tests/mir-opt/gvn.array_len.GVN.panic-abort.diff +++ b/tests/mir-opt/gvn.array_len.GVN.panic-abort.diff @@ -12,8 +12,7 @@ } bb0: { -- StorageLive(_2); -+ nop; + StorageLive(_2); StorageLive(_3); _3 = &(*_1); _2 = move _3 as &[i32] (PointerCoercion(Unsize, Implicit)); @@ -23,8 +22,7 @@ - _0 = PtrMetadata(move _4); + _0 = const 42_usize; StorageDead(_4); -- StorageDead(_2); -+ nop; + StorageDead(_2); return; } } diff --git a/tests/mir-opt/gvn.array_len.GVN.panic-unwind.diff b/tests/mir-opt/gvn.array_len.GVN.panic-unwind.diff index 0d0477fe7729f..59b65a52f4ee6 100644 --- a/tests/mir-opt/gvn.array_len.GVN.panic-unwind.diff +++ b/tests/mir-opt/gvn.array_len.GVN.panic-unwind.diff @@ -12,8 +12,7 @@ } bb0: { -- StorageLive(_2); -+ nop; + StorageLive(_2); StorageLive(_3); _3 = &(*_1); _2 = move _3 as &[i32] (PointerCoercion(Unsize, Implicit)); @@ -23,8 +22,7 @@ - _0 = PtrMetadata(move _4); + _0 = const 42_usize; StorageDead(_4); -- StorageDead(_2); -+ nop; + StorageDead(_2); return; } } diff --git a/tests/mir-opt/gvn.cast.GVN.panic-abort.diff b/tests/mir-opt/gvn.cast.GVN.panic-abort.diff index 1d523d22ca646..71566213f4123 100644 --- a/tests/mir-opt/gvn.cast.GVN.panic-abort.diff +++ b/tests/mir-opt/gvn.cast.GVN.panic-abort.diff @@ -104,14 +104,11 @@ } bb0: { -- StorageLive(_1); -+ nop; + StorageLive(_1); _1 = const 1_i64; -- StorageLive(_2); -+ nop; + StorageLive(_2); _2 = const 1_u64; -- StorageLive(_3); -+ nop; + StorageLive(_3); _3 = const 1f64; StorageLive(_4); StorageLive(_5); @@ -552,12 +549,9 @@ StorageDead(_90); StorageDead(_89); _0 = const (); -- StorageDead(_3); -- StorageDead(_2); -- StorageDead(_1); -+ nop; -+ nop; -+ nop; + StorageDead(_3); + StorageDead(_2); + StorageDead(_1); return; } } diff --git a/tests/mir-opt/gvn.cast.GVN.panic-unwind.diff b/tests/mir-opt/gvn.cast.GVN.panic-unwind.diff index 3541c10da6437..c0cd4882cd67a 100644 --- a/tests/mir-opt/gvn.cast.GVN.panic-unwind.diff +++ b/tests/mir-opt/gvn.cast.GVN.panic-unwind.diff @@ -104,14 +104,11 @@ } bb0: { -- StorageLive(_1); -+ nop; + StorageLive(_1); _1 = const 1_i64; -- StorageLive(_2); -+ nop; + StorageLive(_2); _2 = const 1_u64; -- StorageLive(_3); -+ nop; + StorageLive(_3); _3 = const 1f64; StorageLive(_4); StorageLive(_5); @@ -552,12 +549,9 @@ StorageDead(_90); StorageDead(_89); _0 = const (); -- StorageDead(_3); -- StorageDead(_2); -- StorageDead(_1); -+ nop; -+ nop; -+ nop; + StorageDead(_3); + StorageDead(_2); + StorageDead(_1); return; } } diff --git a/tests/mir-opt/gvn.cast_pointer_eq.GVN.panic-abort.diff b/tests/mir-opt/gvn.cast_pointer_eq.GVN.panic-abort.diff index f66aed0f44150..7dc5180a0a5cc 100644 --- a/tests/mir-opt/gvn.cast_pointer_eq.GVN.panic-abort.diff +++ b/tests/mir-opt/gvn.cast_pointer_eq.GVN.panic-abort.diff @@ -49,8 +49,7 @@ } bb0: { -- StorageLive(_5); -+ nop; + StorageLive(_5); StorageLive(_6); _6 = copy _1; - _5 = move _6 as *const u32 (PtrToPtr); @@ -78,10 +77,9 @@ StorageDead(_12); - _10 = move _11 as *const u32 (PtrToPtr); - StorageDead(_11); -- StorageLive(_13); + _10 = copy _11; + nop; -+ nop; + StorageLive(_13); StorageLive(_14); _14 = copy _4; - _13 = move _14 as *const u32 (PtrToPtr); @@ -122,12 +120,10 @@ StorageDead(_21); StorageDead(_18); StorageDead(_15); -- StorageDead(_13); -+ nop; + StorageDead(_13); StorageDead(_10); StorageDead(_7); -- StorageDead(_5); -+ nop; + StorageDead(_5); return; } } diff --git a/tests/mir-opt/gvn.cast_pointer_eq.GVN.panic-unwind.diff b/tests/mir-opt/gvn.cast_pointer_eq.GVN.panic-unwind.diff index f66aed0f44150..7dc5180a0a5cc 100644 --- a/tests/mir-opt/gvn.cast_pointer_eq.GVN.panic-unwind.diff +++ b/tests/mir-opt/gvn.cast_pointer_eq.GVN.panic-unwind.diff @@ -49,8 +49,7 @@ } bb0: { -- StorageLive(_5); -+ nop; + StorageLive(_5); StorageLive(_6); _6 = copy _1; - _5 = move _6 as *const u32 (PtrToPtr); @@ -78,10 +77,9 @@ StorageDead(_12); - _10 = move _11 as *const u32 (PtrToPtr); - StorageDead(_11); -- StorageLive(_13); + _10 = copy _11; + nop; -+ nop; + StorageLive(_13); StorageLive(_14); _14 = copy _4; - _13 = move _14 as *const u32 (PtrToPtr); @@ -122,12 +120,10 @@ StorageDead(_21); StorageDead(_18); StorageDead(_15); -- StorageDead(_13); -+ nop; + StorageDead(_13); StorageDead(_10); StorageDead(_7); -- StorageDead(_5); -+ nop; + StorageDead(_5); return; } } diff --git a/tests/mir-opt/gvn.casts_before_aggregate_raw_ptr.GVN.panic-abort.diff b/tests/mir-opt/gvn.casts_before_aggregate_raw_ptr.GVN.panic-abort.diff index fd09310fabdeb..bb35b7ef57b2c 100644 --- a/tests/mir-opt/gvn.casts_before_aggregate_raw_ptr.GVN.panic-abort.diff +++ b/tests/mir-opt/gvn.casts_before_aggregate_raw_ptr.GVN.panic-abort.diff @@ -22,22 +22,19 @@ } bb0: { -- StorageLive(_2); -+ nop; + StorageLive(_2); StorageLive(_3); _3 = copy _1; - _2 = move _3 as *const [u8; 4] (PtrToPtr); + _2 = copy _1 as *const [u8; 4] (PtrToPtr); StorageDead(_3); -- StorageLive(_4); -+ nop; + StorageLive(_4); StorageLive(_5); _5 = copy _2; - _4 = move _5 as *const u8 (PtrToPtr); + _4 = copy _1 as *const u8 (PtrToPtr); StorageDead(_5); -- StorageLive(_6); -+ nop; + StorageLive(_6); StorageLive(_7); _7 = copy _4; - _6 = move _7 as *const () (PtrToPtr); @@ -48,12 +45,9 @@ - _0 = *const [u8] from (move _8, const 4_usize); + _0 = *const [u8] from (copy _1, const 4_usize); StorageDead(_8); -- StorageDead(_6); -- StorageDead(_4); -- StorageDead(_2); -+ nop; -+ nop; -+ nop; + StorageDead(_6); + StorageDead(_4); + StorageDead(_2); return; } } diff --git a/tests/mir-opt/gvn.casts_before_aggregate_raw_ptr.GVN.panic-unwind.diff b/tests/mir-opt/gvn.casts_before_aggregate_raw_ptr.GVN.panic-unwind.diff index fd09310fabdeb..bb35b7ef57b2c 100644 --- a/tests/mir-opt/gvn.casts_before_aggregate_raw_ptr.GVN.panic-unwind.diff +++ b/tests/mir-opt/gvn.casts_before_aggregate_raw_ptr.GVN.panic-unwind.diff @@ -22,22 +22,19 @@ } bb0: { -- StorageLive(_2); -+ nop; + StorageLive(_2); StorageLive(_3); _3 = copy _1; - _2 = move _3 as *const [u8; 4] (PtrToPtr); + _2 = copy _1 as *const [u8; 4] (PtrToPtr); StorageDead(_3); -- StorageLive(_4); -+ nop; + StorageLive(_4); StorageLive(_5); _5 = copy _2; - _4 = move _5 as *const u8 (PtrToPtr); + _4 = copy _1 as *const u8 (PtrToPtr); StorageDead(_5); -- StorageLive(_6); -+ nop; + StorageLive(_6); StorageLive(_7); _7 = copy _4; - _6 = move _7 as *const () (PtrToPtr); @@ -48,12 +45,9 @@ - _0 = *const [u8] from (move _8, const 4_usize); + _0 = *const [u8] from (copy _1, const 4_usize); StorageDead(_8); -- StorageDead(_6); -- StorageDead(_4); -- StorageDead(_2); -+ nop; -+ nop; -+ nop; + StorageDead(_6); + StorageDead(_4); + StorageDead(_2); return; } } diff --git a/tests/mir-opt/gvn.constant_index_overflow.GVN.panic-abort.diff b/tests/mir-opt/gvn.constant_index_overflow.GVN.panic-abort.diff index 183b4d2599f53..5ce130fbace82 100644 --- a/tests/mir-opt/gvn.constant_index_overflow.GVN.panic-abort.diff +++ b/tests/mir-opt/gvn.constant_index_overflow.GVN.panic-abort.diff @@ -25,9 +25,8 @@ } bb0: { -- StorageLive(_2); + StorageLive(_2); - _2 = const core::num::::MAX as usize (IntToInt); -+ nop; + _2 = const usize::MAX; StorageLive(_3); StorageLive(_4); @@ -96,8 +95,7 @@ bb7: { StorageDead(_14); StorageDead(_3); -- StorageDead(_2); -+ nop; + StorageDead(_2); return; } } diff --git a/tests/mir-opt/gvn.constant_index_overflow.GVN.panic-unwind.diff b/tests/mir-opt/gvn.constant_index_overflow.GVN.panic-unwind.diff index 03e8aa3bd9b98..f81b8cbecb663 100644 --- a/tests/mir-opt/gvn.constant_index_overflow.GVN.panic-unwind.diff +++ b/tests/mir-opt/gvn.constant_index_overflow.GVN.panic-unwind.diff @@ -25,9 +25,8 @@ } bb0: { -- StorageLive(_2); + StorageLive(_2); - _2 = const core::num::::MAX as usize (IntToInt); -+ nop; + _2 = const usize::MAX; StorageLive(_3); StorageLive(_4); @@ -96,8 +95,7 @@ bb7: { StorageDead(_14); StorageDead(_3); -- StorageDead(_2); -+ nop; + StorageDead(_2); return; } } diff --git a/tests/mir-opt/gvn.fn_pointers.GVN.panic-abort.diff b/tests/mir-opt/gvn.fn_pointers.GVN.panic-abort.diff index 3cce35d34e90d..f8180886e97be 100644 --- a/tests/mir-opt/gvn.fn_pointers.GVN.panic-abort.diff +++ b/tests/mir-opt/gvn.fn_pointers.GVN.panic-abort.diff @@ -35,8 +35,7 @@ } bb0: { -- StorageLive(_1); -+ nop; + StorageLive(_1); _1 = identity:: as fn(u8) -> u8 (PointerCoercion(ReifyFnPointer, AsCast)); StorageLive(_2); StorageLive(_3); @@ -48,8 +47,7 @@ bb1: { StorageDead(_3); StorageDead(_2); -- StorageLive(_4); -+ nop; + StorageLive(_4); _4 = identity:: as fn(u8) -> u8 (PointerCoercion(ReifyFnPointer, AsCast)); StorageLive(_5); StorageLive(_6); @@ -61,12 +59,10 @@ bb2: { StorageDead(_6); StorageDead(_5); -- StorageLive(_7); + StorageLive(_7); - _7 = {closure@$DIR/gvn.rs:620:19: 620:21}; -- StorageLive(_8); -+ nop; + _7 = const ZeroSized: {closure@$DIR/gvn.rs:620:19: 620:21}; -+ nop; + StorageLive(_8); StorageLive(_9); - _9 = copy _7; - _8 = move _9 as fn() (PointerCoercion(ClosureFnPointer(Safe), AsCast)); @@ -83,8 +79,7 @@ bb3: { StorageDead(_11); StorageDead(_10); -- StorageLive(_12); -+ nop; + StorageLive(_12); StorageLive(_13); - _13 = copy _7; - _12 = move _13 as fn() (PointerCoercion(ClosureFnPointer(Safe), AsCast)); @@ -102,16 +97,11 @@ StorageDead(_15); StorageDead(_14); _0 = const (); -- StorageDead(_12); -- StorageDead(_8); -- StorageDead(_7); -- StorageDead(_4); -- StorageDead(_1); -+ nop; -+ nop; -+ nop; -+ nop; -+ nop; + StorageDead(_12); + StorageDead(_8); + StorageDead(_7); + StorageDead(_4); + StorageDead(_1); return; } } diff --git a/tests/mir-opt/gvn.fn_pointers.GVN.panic-unwind.diff b/tests/mir-opt/gvn.fn_pointers.GVN.panic-unwind.diff index d85aca040fe67..44e6e914cd92c 100644 --- a/tests/mir-opt/gvn.fn_pointers.GVN.panic-unwind.diff +++ b/tests/mir-opt/gvn.fn_pointers.GVN.panic-unwind.diff @@ -35,8 +35,7 @@ } bb0: { -- StorageLive(_1); -+ nop; + StorageLive(_1); _1 = identity:: as fn(u8) -> u8 (PointerCoercion(ReifyFnPointer, AsCast)); StorageLive(_2); StorageLive(_3); @@ -48,8 +47,7 @@ bb1: { StorageDead(_3); StorageDead(_2); -- StorageLive(_4); -+ nop; + StorageLive(_4); _4 = identity:: as fn(u8) -> u8 (PointerCoercion(ReifyFnPointer, AsCast)); StorageLive(_5); StorageLive(_6); @@ -61,12 +59,10 @@ bb2: { StorageDead(_6); StorageDead(_5); -- StorageLive(_7); + StorageLive(_7); - _7 = {closure@$DIR/gvn.rs:620:19: 620:21}; -- StorageLive(_8); -+ nop; + _7 = const ZeroSized: {closure@$DIR/gvn.rs:620:19: 620:21}; -+ nop; + StorageLive(_8); StorageLive(_9); - _9 = copy _7; - _8 = move _9 as fn() (PointerCoercion(ClosureFnPointer(Safe), AsCast)); @@ -83,8 +79,7 @@ bb3: { StorageDead(_11); StorageDead(_10); -- StorageLive(_12); -+ nop; + StorageLive(_12); StorageLive(_13); - _13 = copy _7; - _12 = move _13 as fn() (PointerCoercion(ClosureFnPointer(Safe), AsCast)); @@ -102,16 +97,11 @@ StorageDead(_15); StorageDead(_14); _0 = const (); -- StorageDead(_12); -- StorageDead(_8); -- StorageDead(_7); -- StorageDead(_4); -- StorageDead(_1); -+ nop; -+ nop; -+ nop; -+ nop; -+ nop; + StorageDead(_12); + StorageDead(_8); + StorageDead(_7); + StorageDead(_4); + StorageDead(_1); return; } } diff --git a/tests/mir-opt/gvn.manual_slice_mut_len.GVN.panic-abort.diff b/tests/mir-opt/gvn.manual_slice_mut_len.GVN.panic-abort.diff index 936fa3db82a73..7741d0907d2ba 100644 --- a/tests/mir-opt/gvn.manual_slice_mut_len.GVN.panic-abort.diff +++ b/tests/mir-opt/gvn.manual_slice_mut_len.GVN.panic-abort.diff @@ -16,11 +16,9 @@ } bb0: { -- StorageLive(_2); -+ nop; + StorageLive(_2); _2 = &raw mut (*_1); -- StorageLive(_3); -+ nop; + StorageLive(_3); StorageLive(_4); _4 = copy _2; - _3 = move _4 as *const [i32] (PtrToPtr); @@ -31,10 +29,8 @@ - _0 = PtrMetadata(move _5); + _0 = PtrMetadata(copy _1); StorageDead(_5); -- StorageDead(_3); -- StorageDead(_2); -+ nop; -+ nop; + StorageDead(_3); + StorageDead(_2); return; } } diff --git a/tests/mir-opt/gvn.manual_slice_mut_len.GVN.panic-unwind.diff b/tests/mir-opt/gvn.manual_slice_mut_len.GVN.panic-unwind.diff index 936fa3db82a73..7741d0907d2ba 100644 --- a/tests/mir-opt/gvn.manual_slice_mut_len.GVN.panic-unwind.diff +++ b/tests/mir-opt/gvn.manual_slice_mut_len.GVN.panic-unwind.diff @@ -16,11 +16,9 @@ } bb0: { -- StorageLive(_2); -+ nop; + StorageLive(_2); _2 = &raw mut (*_1); -- StorageLive(_3); -+ nop; + StorageLive(_3); StorageLive(_4); _4 = copy _2; - _3 = move _4 as *const [i32] (PtrToPtr); @@ -31,10 +29,8 @@ - _0 = PtrMetadata(move _5); + _0 = PtrMetadata(copy _1); StorageDead(_5); -- StorageDead(_3); -- StorageDead(_2); -+ nop; -+ nop; + StorageDead(_3); + StorageDead(_2); return; } } diff --git a/tests/mir-opt/gvn.meta_of_ref_to_slice.GVN.panic-abort.diff b/tests/mir-opt/gvn.meta_of_ref_to_slice.GVN.panic-abort.diff index 3ed6c2b5308fb..1825d68f1939c 100644 --- a/tests/mir-opt/gvn.meta_of_ref_to_slice.GVN.panic-abort.diff +++ b/tests/mir-opt/gvn.meta_of_ref_to_slice.GVN.panic-abort.diff @@ -12,8 +12,7 @@ } bb0: { -- StorageLive(_2); -+ nop; + StorageLive(_2); StorageLive(_3); _3 = copy _1; - _2 = *const [i32] from (move _3, const 1_usize); @@ -24,8 +23,7 @@ - _0 = PtrMetadata(move _4); + _0 = const 1_usize; StorageDead(_4); -- StorageDead(_2); -+ nop; + StorageDead(_2); return; } } diff --git a/tests/mir-opt/gvn.meta_of_ref_to_slice.GVN.panic-unwind.diff b/tests/mir-opt/gvn.meta_of_ref_to_slice.GVN.panic-unwind.diff index 3ed6c2b5308fb..1825d68f1939c 100644 --- a/tests/mir-opt/gvn.meta_of_ref_to_slice.GVN.panic-unwind.diff +++ b/tests/mir-opt/gvn.meta_of_ref_to_slice.GVN.panic-unwind.diff @@ -12,8 +12,7 @@ } bb0: { -- StorageLive(_2); -+ nop; + StorageLive(_2); StorageLive(_3); _3 = copy _1; - _2 = *const [i32] from (move _3, const 1_usize); @@ -24,8 +23,7 @@ - _0 = PtrMetadata(move _4); + _0 = const 1_usize; StorageDead(_4); -- StorageDead(_2); -+ nop; + StorageDead(_2); return; } } diff --git a/tests/mir-opt/gvn.references.GVN.panic-abort.diff b/tests/mir-opt/gvn.references.GVN.panic-abort.diff index 62a487dee8215..429c7df2f361e 100644 --- a/tests/mir-opt/gvn.references.GVN.panic-abort.diff +++ b/tests/mir-opt/gvn.references.GVN.panic-abort.diff @@ -112,8 +112,7 @@ bb8: { StorageDead(_17); StorageDead(_16); -- StorageLive(_18); -+ nop; + StorageLive(_18); _18 = &mut _1; StorageLive(_19); StorageLive(_20); @@ -168,8 +167,7 @@ StorageDead(_28); _0 = const (); StorageDead(_19); -- StorageDead(_18); -+ nop; + StorageDead(_18); drop(_1) -> [return: bb13, unwind unreachable]; } diff --git a/tests/mir-opt/gvn.references.GVN.panic-unwind.diff b/tests/mir-opt/gvn.references.GVN.panic-unwind.diff index 6dd986907fcc6..c2d67507c39d3 100644 --- a/tests/mir-opt/gvn.references.GVN.panic-unwind.diff +++ b/tests/mir-opt/gvn.references.GVN.panic-unwind.diff @@ -112,8 +112,7 @@ bb8: { StorageDead(_17); StorageDead(_16); -- StorageLive(_18); -+ nop; + StorageLive(_18); _18 = &mut _1; StorageLive(_19); StorageLive(_20); @@ -168,8 +167,7 @@ StorageDead(_28); _0 = const (); StorageDead(_19); -- StorageDead(_18); -+ nop; + StorageDead(_18); drop(_1) -> [return: bb13, unwind: bb15]; } diff --git a/tests/mir-opt/gvn.repeat.GVN.panic-abort.diff b/tests/mir-opt/gvn.repeat.GVN.panic-abort.diff index ef2eb1a66779d..0b8b682ba52ce 100644 --- a/tests/mir-opt/gvn.repeat.GVN.panic-abort.diff +++ b/tests/mir-opt/gvn.repeat.GVN.panic-abort.diff @@ -23,8 +23,7 @@ } bb0: { -- StorageLive(_1); -+ nop; + StorageLive(_1); _1 = const 5_i32; StorageLive(_2); StorageLive(_3); @@ -71,8 +70,7 @@ StorageDead(_3); _0 = const (); StorageDead(_2); -- StorageDead(_1); -+ nop; + StorageDead(_1); return; } } diff --git a/tests/mir-opt/gvn.repeat.GVN.panic-unwind.diff b/tests/mir-opt/gvn.repeat.GVN.panic-unwind.diff index ef2eb1a66779d..0b8b682ba52ce 100644 --- a/tests/mir-opt/gvn.repeat.GVN.panic-unwind.diff +++ b/tests/mir-opt/gvn.repeat.GVN.panic-unwind.diff @@ -23,8 +23,7 @@ } bb0: { -- StorageLive(_1); -+ nop; + StorageLive(_1); _1 = const 5_i32; StorageLive(_2); StorageLive(_3); @@ -71,8 +70,7 @@ StorageDead(_3); _0 = const (); StorageDead(_2); -- StorageDead(_1); -+ nop; + StorageDead(_1); return; } } diff --git a/tests/mir-opt/gvn.slice_const_length.GVN.panic-abort.diff b/tests/mir-opt/gvn.slice_const_length.GVN.panic-abort.diff index 1a6204e4ac8ae..412f908821ab6 100644 --- a/tests/mir-opt/gvn.slice_const_length.GVN.panic-abort.diff +++ b/tests/mir-opt/gvn.slice_const_length.GVN.panic-abort.diff @@ -17,8 +17,7 @@ } bb0: { -- StorageLive(_2); -+ nop; + StorageLive(_2); StorageLive(_3); _3 = &(*_1); _2 = core::slice::::as_ptr(move _3) -> [return: bb1, unwind unreachable]; @@ -26,8 +25,7 @@ bb1: { StorageDead(_3); -- StorageLive(_4); -+ nop; + StorageLive(_4); _4 = const 123_usize; StorageLive(_5); _5 = copy _2; @@ -38,10 +36,8 @@ + _0 = *const [i32] from (copy _2, const 123_usize); StorageDead(_6); StorageDead(_5); -- StorageDead(_4); -- StorageDead(_2); -+ nop; -+ nop; + StorageDead(_4); + StorageDead(_2); return; } } diff --git a/tests/mir-opt/gvn.slice_const_length.GVN.panic-unwind.diff b/tests/mir-opt/gvn.slice_const_length.GVN.panic-unwind.diff index 62d57b0fe2831..6f166971631c2 100644 --- a/tests/mir-opt/gvn.slice_const_length.GVN.panic-unwind.diff +++ b/tests/mir-opt/gvn.slice_const_length.GVN.panic-unwind.diff @@ -17,8 +17,7 @@ } bb0: { -- StorageLive(_2); -+ nop; + StorageLive(_2); StorageLive(_3); _3 = &(*_1); _2 = core::slice::::as_ptr(move _3) -> [return: bb1, unwind continue]; @@ -26,8 +25,7 @@ bb1: { StorageDead(_3); -- StorageLive(_4); -+ nop; + StorageLive(_4); _4 = const 123_usize; StorageLive(_5); _5 = copy _2; @@ -38,10 +36,8 @@ + _0 = *const [i32] from (copy _2, const 123_usize); StorageDead(_6); StorageDead(_5); -- StorageDead(_4); -- StorageDead(_2); -+ nop; -+ nop; + StorageDead(_4); + StorageDead(_2); return; } } diff --git a/tests/mir-opt/gvn.slice_from_raw_parts_as_ptr.GVN.panic-abort.diff b/tests/mir-opt/gvn.slice_from_raw_parts_as_ptr.GVN.panic-abort.diff index 4a2cc25189191..ab4971cc6c017 100644 --- a/tests/mir-opt/gvn.slice_from_raw_parts_as_ptr.GVN.panic-abort.diff +++ b/tests/mir-opt/gvn.slice_from_raw_parts_as_ptr.GVN.panic-abort.diff @@ -17,8 +17,7 @@ } bb0: { -- StorageLive(_3); -+ nop; + StorageLive(_3); StorageLive(_4); _4 = copy _1; StorageLive(_5); @@ -43,8 +42,7 @@ + _0 = (copy _1, move _8); StorageDead(_8); StorageDead(_6); -- StorageDead(_3); -+ nop; + StorageDead(_3); return; } } diff --git a/tests/mir-opt/gvn.slice_from_raw_parts_as_ptr.GVN.panic-unwind.diff b/tests/mir-opt/gvn.slice_from_raw_parts_as_ptr.GVN.panic-unwind.diff index 4a2cc25189191..ab4971cc6c017 100644 --- a/tests/mir-opt/gvn.slice_from_raw_parts_as_ptr.GVN.panic-unwind.diff +++ b/tests/mir-opt/gvn.slice_from_raw_parts_as_ptr.GVN.panic-unwind.diff @@ -17,8 +17,7 @@ } bb0: { -- StorageLive(_3); -+ nop; + StorageLive(_3); StorageLive(_4); _4 = copy _1; StorageLive(_5); @@ -43,8 +42,7 @@ + _0 = (copy _1, move _8); StorageDead(_8); StorageDead(_6); -- StorageDead(_3); -+ nop; + StorageDead(_3); return; } } diff --git a/tests/mir-opt/gvn.slices.GVN.panic-abort.diff b/tests/mir-opt/gvn.slices.GVN.panic-abort.diff index e8e99b44e721b..21a1292907c67 100644 --- a/tests/mir-opt/gvn.slices.GVN.panic-abort.diff +++ b/tests/mir-opt/gvn.slices.GVN.panic-abort.diff @@ -82,8 +82,7 @@ } bb0: { -- StorageLive(_1); -+ nop; + StorageLive(_1); _1 = const "my favourite slice"; StorageLive(_2); StorageLive(_3); @@ -111,9 +110,8 @@ StorageLive(_7); StorageLive(_8); - StorageLive(_9); -- StorageLive(_10); -+ nop; + nop; + StorageLive(_10); StorageLive(_11); _11 = &(*_1); _10 = core::str::::as_ptr(move _11) -> [return: bb3, unwind unreachable]; @@ -123,9 +121,8 @@ StorageDead(_11); _9 = &_10; - StorageLive(_12); -- StorageLive(_13); -+ nop; + nop; + StorageLive(_13); StorageLive(_14); - _14 = &(*_4); + _14 = &(*_1); @@ -166,14 +163,11 @@ StorageDead(_17); StorageDead(_16); StorageDead(_15); -- StorageDead(_13); -- StorageDead(_10); -+ nop; -+ nop; + StorageDead(_13); + StorageDead(_10); StorageDead(_8); StorageDead(_7); -- StorageLive(_29); -+ nop; + StorageLive(_29); StorageLive(_30); _30 = &(*_1); _29 = move _30 as &[u8] (Transmute); @@ -188,9 +182,8 @@ bb6: { StorageDead(_19); StorageDead(_18); -- StorageLive(_21); + StorageLive(_21); - _21 = core::panicking::AssertKind::Eq; -+ nop; + _21 = const core::panicking::AssertKind::Eq; StorageLive(_22); StorageLive(_23); @@ -218,9 +211,8 @@ StorageLive(_33); StorageLive(_34); - StorageLive(_35); -- StorageLive(_36); -+ nop; + nop; + StorageLive(_36); StorageLive(_37); _37 = &(*_1); _36 = core::str::::as_ptr(move _37) -> [return: bb8, unwind unreachable]; @@ -230,9 +222,8 @@ StorageDead(_37); _35 = &_36; - StorageLive(_38); -- StorageLive(_39); -+ nop; + nop; + StorageLive(_39); StorageLive(_40); _40 = &(*_29); _39 = core::slice::::as_ptr(move _40) -> [return: bb9, unwind unreachable]; @@ -272,27 +263,22 @@ StorageDead(_43); StorageDead(_42); StorageDead(_41); -- StorageDead(_39); -- StorageDead(_36); -+ nop; -+ nop; + StorageDead(_39); + StorageDead(_36); StorageDead(_34); StorageDead(_33); _0 = const (); -- StorageDead(_29); -+ nop; + StorageDead(_29); StorageDead(_4); -- StorageDead(_1); -+ nop; + StorageDead(_1); return; } bb11: { StorageDead(_45); StorageDead(_44); -- StorageLive(_47); + StorageLive(_47); - _47 = core::panicking::AssertKind::Eq; -+ nop; + _47 = const core::panicking::AssertKind::Eq; StorageLive(_48); StorageLive(_49); diff --git a/tests/mir-opt/gvn.slices.GVN.panic-unwind.diff b/tests/mir-opt/gvn.slices.GVN.panic-unwind.diff index 4296d4d4a5945..141d6346f4eb2 100644 --- a/tests/mir-opt/gvn.slices.GVN.panic-unwind.diff +++ b/tests/mir-opt/gvn.slices.GVN.panic-unwind.diff @@ -82,8 +82,7 @@ } bb0: { -- StorageLive(_1); -+ nop; + StorageLive(_1); _1 = const "my favourite slice"; StorageLive(_2); StorageLive(_3); @@ -111,9 +110,8 @@ StorageLive(_7); StorageLive(_8); - StorageLive(_9); -- StorageLive(_10); -+ nop; + nop; + StorageLive(_10); StorageLive(_11); _11 = &(*_1); _10 = core::str::::as_ptr(move _11) -> [return: bb3, unwind continue]; @@ -123,9 +121,8 @@ StorageDead(_11); _9 = &_10; - StorageLive(_12); -- StorageLive(_13); -+ nop; + nop; + StorageLive(_13); StorageLive(_14); - _14 = &(*_4); + _14 = &(*_1); @@ -166,14 +163,11 @@ StorageDead(_17); StorageDead(_16); StorageDead(_15); -- StorageDead(_13); -- StorageDead(_10); -+ nop; -+ nop; + StorageDead(_13); + StorageDead(_10); StorageDead(_8); StorageDead(_7); -- StorageLive(_29); -+ nop; + StorageLive(_29); StorageLive(_30); _30 = &(*_1); _29 = move _30 as &[u8] (Transmute); @@ -188,9 +182,8 @@ bb6: { StorageDead(_19); StorageDead(_18); -- StorageLive(_21); + StorageLive(_21); - _21 = core::panicking::AssertKind::Eq; -+ nop; + _21 = const core::panicking::AssertKind::Eq; StorageLive(_22); StorageLive(_23); @@ -218,9 +211,8 @@ StorageLive(_33); StorageLive(_34); - StorageLive(_35); -- StorageLive(_36); -+ nop; + nop; + StorageLive(_36); StorageLive(_37); _37 = &(*_1); _36 = core::str::::as_ptr(move _37) -> [return: bb8, unwind continue]; @@ -230,9 +222,8 @@ StorageDead(_37); _35 = &_36; - StorageLive(_38); -- StorageLive(_39); -+ nop; + nop; + StorageLive(_39); StorageLive(_40); _40 = &(*_29); _39 = core::slice::::as_ptr(move _40) -> [return: bb9, unwind continue]; @@ -272,27 +263,22 @@ StorageDead(_43); StorageDead(_42); StorageDead(_41); -- StorageDead(_39); -- StorageDead(_36); -+ nop; -+ nop; + StorageDead(_39); + StorageDead(_36); StorageDead(_34); StorageDead(_33); _0 = const (); -- StorageDead(_29); -+ nop; + StorageDead(_29); StorageDead(_4); -- StorageDead(_1); -+ nop; + StorageDead(_1); return; } bb11: { StorageDead(_45); StorageDead(_44); -- StorageLive(_47); + StorageLive(_47); - _47 = core::panicking::AssertKind::Eq; -+ nop; + _47 = const core::panicking::AssertKind::Eq; StorageLive(_48); StorageLive(_49); diff --git a/tests/mir-opt/gvn.transmute_then_cast_pointer.GVN.panic-abort.diff b/tests/mir-opt/gvn.transmute_then_cast_pointer.GVN.panic-abort.diff index 0bec425dd9957..230a420d0c3d6 100644 --- a/tests/mir-opt/gvn.transmute_then_cast_pointer.GVN.panic-abort.diff +++ b/tests/mir-opt/gvn.transmute_then_cast_pointer.GVN.panic-abort.diff @@ -34,8 +34,7 @@ } bb0: { -- StorageLive(_3); -+ nop; + StorageLive(_3); StorageLive(_4); _4 = copy _1; - _3 = move _4 as *mut u8 (Transmute); @@ -54,8 +53,7 @@ bb1: { StorageDead(_6); StorageDead(_5); -- StorageLive(_8); -+ nop; + StorageLive(_8); StorageLive(_9); StorageLive(_10); StorageLive(_11); @@ -82,8 +80,7 @@ bb2: { StorageDead(_14); StorageDead(_13); -- StorageLive(_16); -+ nop; + StorageLive(_16); StorageLive(_17); _17 = copy _2; - _16 = move _17 as *const [u8] (Transmute); @@ -103,12 +100,9 @@ StorageDead(_19); StorageDead(_18); _0 = const (); -- StorageDead(_16); -- StorageDead(_8); -- StorageDead(_3); -+ nop; -+ nop; -+ nop; + StorageDead(_16); + StorageDead(_8); + StorageDead(_3); return; } } diff --git a/tests/mir-opt/gvn.transmute_then_cast_pointer.GVN.panic-unwind.diff b/tests/mir-opt/gvn.transmute_then_cast_pointer.GVN.panic-unwind.diff index 14f2fe08a86a2..a20b9cef59ae3 100644 --- a/tests/mir-opt/gvn.transmute_then_cast_pointer.GVN.panic-unwind.diff +++ b/tests/mir-opt/gvn.transmute_then_cast_pointer.GVN.panic-unwind.diff @@ -34,8 +34,7 @@ } bb0: { -- StorageLive(_3); -+ nop; + StorageLive(_3); StorageLive(_4); _4 = copy _1; - _3 = move _4 as *mut u8 (Transmute); @@ -54,8 +53,7 @@ bb1: { StorageDead(_6); StorageDead(_5); -- StorageLive(_8); -+ nop; + StorageLive(_8); StorageLive(_9); StorageLive(_10); StorageLive(_11); @@ -82,8 +80,7 @@ bb2: { StorageDead(_14); StorageDead(_13); -- StorageLive(_16); -+ nop; + StorageLive(_16); StorageLive(_17); _17 = copy _2; - _16 = move _17 as *const [u8] (Transmute); @@ -103,12 +100,9 @@ StorageDead(_19); StorageDead(_18); _0 = const (); -- StorageDead(_16); -- StorageDead(_8); -- StorageDead(_3); -+ nop; -+ nop; -+ nop; + StorageDead(_16); + StorageDead(_8); + StorageDead(_3); return; } } diff --git a/tests/mir-opt/gvn.transmute_then_transmute_again.GVN.panic-abort.diff b/tests/mir-opt/gvn.transmute_then_transmute_again.GVN.panic-abort.diff index 962fecd2586eb..7eea36055f57a 100644 --- a/tests/mir-opt/gvn.transmute_then_transmute_again.GVN.panic-abort.diff +++ b/tests/mir-opt/gvn.transmute_then_transmute_again.GVN.panic-abort.diff @@ -23,8 +23,7 @@ } bb0: { -- StorageLive(_3); -+ nop; + StorageLive(_3); StorageLive(_4); _4 = copy _1; - _3 = move _4 as char (Transmute); @@ -43,8 +42,7 @@ bb1: { StorageDead(_6); StorageDead(_5); -- StorageLive(_8); -+ nop; + StorageLive(_8); StorageLive(_9); _9 = copy _2; - _8 = move _9 as u32 (Transmute); @@ -64,10 +62,8 @@ StorageDead(_11); StorageDead(_10); _0 = const (); -- StorageDead(_8); -- StorageDead(_3); -+ nop; -+ nop; + StorageDead(_8); + StorageDead(_3); return; } } diff --git a/tests/mir-opt/gvn.transmute_then_transmute_again.GVN.panic-unwind.diff b/tests/mir-opt/gvn.transmute_then_transmute_again.GVN.panic-unwind.diff index e32397c1aed07..b133b403729f4 100644 --- a/tests/mir-opt/gvn.transmute_then_transmute_again.GVN.panic-unwind.diff +++ b/tests/mir-opt/gvn.transmute_then_transmute_again.GVN.panic-unwind.diff @@ -23,8 +23,7 @@ } bb0: { -- StorageLive(_3); -+ nop; + StorageLive(_3); StorageLive(_4); _4 = copy _1; - _3 = move _4 as char (Transmute); @@ -43,8 +42,7 @@ bb1: { StorageDead(_6); StorageDead(_5); -- StorageLive(_8); -+ nop; + StorageLive(_8); StorageLive(_9); _9 = copy _2; - _8 = move _9 as u32 (Transmute); @@ -64,10 +62,8 @@ StorageDead(_11); StorageDead(_10); _0 = const (); -- StorageDead(_8); -- StorageDead(_3); -+ nop; -+ nop; + StorageDead(_8); + StorageDead(_3); return; } } diff --git a/tests/mir-opt/gvn.unary.GVN.panic-abort.diff b/tests/mir-opt/gvn.unary.GVN.panic-abort.diff index d14aec6df5fae..2b23b0a32d551 100644 --- a/tests/mir-opt/gvn.unary.GVN.panic-abort.diff +++ b/tests/mir-opt/gvn.unary.GVN.panic-abort.diff @@ -51,8 +51,7 @@ bb1: { StorageDead(_3); StorageDead(_2); -- StorageLive(_6); -+ nop; + StorageLive(_6); StorageLive(_7); _7 = copy _1; - _6 = Lt(move _7, const 13_i64); @@ -145,8 +144,7 @@ StorageDead(_23); StorageDead(_22); _0 = const (); -- StorageDead(_6); -+ nop; + StorageDead(_6); return; } } diff --git a/tests/mir-opt/gvn.unary.GVN.panic-unwind.diff b/tests/mir-opt/gvn.unary.GVN.panic-unwind.diff index 5978f1faa1f68..a2ca0dcb18dbd 100644 --- a/tests/mir-opt/gvn.unary.GVN.panic-unwind.diff +++ b/tests/mir-opt/gvn.unary.GVN.panic-unwind.diff @@ -51,8 +51,7 @@ bb1: { StorageDead(_3); StorageDead(_2); -- StorageLive(_6); -+ nop; + StorageLive(_6); StorageLive(_7); _7 = copy _1; - _6 = Lt(move _7, const 13_i64); @@ -145,8 +144,7 @@ StorageDead(_23); StorageDead(_22); _0 = const (); -- StorageDead(_6); -+ nop; + StorageDead(_6); return; } } diff --git a/tests/mir-opt/gvn.wide_ptr_integer.GVN.panic-abort.diff b/tests/mir-opt/gvn.wide_ptr_integer.GVN.panic-abort.diff index bb938f3ba6a9a..0d0c17c7c76a8 100644 --- a/tests/mir-opt/gvn.wide_ptr_integer.GVN.panic-abort.diff +++ b/tests/mir-opt/gvn.wide_ptr_integer.GVN.panic-abort.diff @@ -39,16 +39,14 @@ } bb0: { -- StorageLive(_1); -+ nop; + StorageLive(_1); StorageLive(_2); - _2 = (const 1_usize, const 1_usize); - _1 = move _2 as *const [u8] (Transmute); + _2 = const (1_usize, 1_usize); + _1 = const Indirect { alloc_id: ALLOC0, offset: Size(0 bytes) }: *const [u8]; StorageDead(_2); -- StorageLive(_3); -+ nop; + StorageLive(_3); StorageLive(_4); - _4 = (const 1_usize, const 2_usize); - _3 = move _4 as *const [u8] (Transmute); @@ -170,10 +168,8 @@ StorageDead(_26); StorageDead(_25); _0 = const (); -- StorageDead(_3); -- StorageDead(_1); -+ nop; -+ nop; + StorageDead(_3); + StorageDead(_1); return; } } diff --git a/tests/mir-opt/gvn.wide_ptr_integer.GVN.panic-unwind.diff b/tests/mir-opt/gvn.wide_ptr_integer.GVN.panic-unwind.diff index 81432d687eb32..885ca25c32990 100644 --- a/tests/mir-opt/gvn.wide_ptr_integer.GVN.panic-unwind.diff +++ b/tests/mir-opt/gvn.wide_ptr_integer.GVN.panic-unwind.diff @@ -39,16 +39,14 @@ } bb0: { -- StorageLive(_1); -+ nop; + StorageLive(_1); StorageLive(_2); - _2 = (const 1_usize, const 1_usize); - _1 = move _2 as *const [u8] (Transmute); + _2 = const (1_usize, 1_usize); + _1 = const Indirect { alloc_id: ALLOC0, offset: Size(0 bytes) }: *const [u8]; StorageDead(_2); -- StorageLive(_3); -+ nop; + StorageLive(_3); StorageLive(_4); - _4 = (const 1_usize, const 2_usize); - _3 = move _4 as *const [u8] (Transmute); @@ -170,10 +168,8 @@ StorageDead(_26); StorageDead(_25); _0 = const (); -- StorageDead(_3); -- StorageDead(_1); -+ nop; -+ nop; + StorageDead(_3); + StorageDead(_1); return; } } diff --git a/tests/mir-opt/gvn_clone.{impl#0}-clone.GVN.diff b/tests/mir-opt/gvn_clone.{impl#0}-clone.GVN.diff index 0f23415ec53bb..9381c7c0af537 100644 --- a/tests/mir-opt/gvn_clone.{impl#0}-clone.GVN.diff +++ b/tests/mir-opt/gvn_clone.{impl#0}-clone.GVN.diff @@ -17,8 +17,7 @@ bb0: { StorageLive(_2); StorageLive(_3); -- StorageLive(_4); -+ nop; + StorageLive(_4); _4 = &((*_1).0: i32); _3 = copy _4; - _2 = copy (*_3); @@ -30,8 +29,7 @@ StorageDead(_3); StorageLive(_5); StorageLive(_6); -- StorageLive(_7); -+ nop; + StorageLive(_7); _7 = &((*_1).1: u64); _6 = copy _7; - _5 = copy (*_6); @@ -43,8 +41,7 @@ StorageDead(_6); StorageLive(_8); StorageLive(_9); -- StorageLive(_10); -+ nop; + StorageLive(_10); _10 = &((*_1).2: [i8; 3]); _9 = copy _10; - _8 = copy (*_9); @@ -55,15 +52,12 @@ bb3: { StorageDead(_9); - _0 = AllCopy { a: move _2, b: move _5, c: move _8 }; -- StorageDead(_10); + _0 = copy (*_1); -+ nop; + StorageDead(_10); StorageDead(_8); -- StorageDead(_7); -+ nop; + StorageDead(_7); StorageDead(_5); -- StorageDead(_4); -+ nop; + StorageDead(_4); StorageDead(_2); return; } diff --git a/tests/mir-opt/gvn_copy_aggregate.all_copy.GVN.diff b/tests/mir-opt/gvn_copy_aggregate.all_copy.GVN.diff index f6345d5809f29..e88fc3e8553c3 100644 --- a/tests/mir-opt/gvn_copy_aggregate.all_copy.GVN.diff +++ b/tests/mir-opt/gvn_copy_aggregate.all_copy.GVN.diff @@ -21,14 +21,11 @@ } bb0: { -- StorageLive(_2); -+ nop; + StorageLive(_2); _2 = copy ((*_1).0: i32); -- StorageLive(_3); -+ nop; + StorageLive(_3); _3 = copy ((*_1).1: u64); -- StorageLive(_4); -+ nop; + StorageLive(_4); _4 = copy ((*_1).2: [i8; 3]); StorageLive(_5); _5 = copy _2; @@ -41,12 +38,9 @@ StorageDead(_7); StorageDead(_6); StorageDead(_5); -- StorageDead(_4); -- StorageDead(_3); -- StorageDead(_2); -+ nop; -+ nop; -+ nop; + StorageDead(_4); + StorageDead(_3); + StorageDead(_2); return; } } diff --git a/tests/mir-opt/gvn_copy_aggregate.all_copy_2.GVN.diff b/tests/mir-opt/gvn_copy_aggregate.all_copy_2.GVN.diff index 452d8a9332036..a9fb55f1d8f9a 100644 --- a/tests/mir-opt/gvn_copy_aggregate.all_copy_2.GVN.diff +++ b/tests/mir-opt/gvn_copy_aggregate.all_copy_2.GVN.diff @@ -24,21 +24,18 @@ } bb0: { -- StorageLive(_2); + StorageLive(_2); - _8 = deref_copy (*_1); -+ nop; + _8 = copy (*_1); _2 = copy ((*_8).0: i32); -- StorageLive(_3); + StorageLive(_3); - _9 = deref_copy (*_1); - _3 = copy ((*_9).1: u64); -- StorageLive(_4); -- _10 = deref_copy (*_1); -- _4 = copy ((*_10).2: [i8; 3]); -+ nop; + _9 = copy _8; + _3 = copy ((*_8).1: u64); -+ nop; + StorageLive(_4); +- _10 = deref_copy (*_1); +- _4 = copy ((*_10).2: [i8; 3]); + _10 = copy _8; + _4 = copy ((*_8).2: [i8; 3]); StorageLive(_5); @@ -52,12 +49,9 @@ StorageDead(_7); StorageDead(_6); StorageDead(_5); -- StorageDead(_4); -- StorageDead(_3); -- StorageDead(_2); -+ nop; -+ nop; -+ nop; + StorageDead(_4); + StorageDead(_3); + StorageDead(_2); return; } } diff --git a/tests/mir-opt/gvn_copy_aggregate.all_copy_different_type.GVN.diff b/tests/mir-opt/gvn_copy_aggregate.all_copy_different_type.GVN.diff index 37652095fa440..5f22429b4a2a1 100644 --- a/tests/mir-opt/gvn_copy_aggregate.all_copy_different_type.GVN.diff +++ b/tests/mir-opt/gvn_copy_aggregate.all_copy_different_type.GVN.diff @@ -21,14 +21,11 @@ } bb0: { -- StorageLive(_2); -+ nop; + StorageLive(_2); _2 = copy ((*_1).0: i32); -- StorageLive(_3); -+ nop; + StorageLive(_3); _3 = copy ((*_1).1: u64); -- StorageLive(_4); -+ nop; + StorageLive(_4); _4 = copy ((*_1).2: [i8; 3]); StorageLive(_5); _5 = copy _2; @@ -41,12 +38,9 @@ StorageDead(_7); StorageDead(_6); StorageDead(_5); -- StorageDead(_4); -- StorageDead(_3); -- StorageDead(_2); -+ nop; -+ nop; -+ nop; + StorageDead(_4); + StorageDead(_3); + StorageDead(_2); return; } } diff --git a/tests/mir-opt/gvn_copy_aggregate.all_copy_has_changed.GVN.diff b/tests/mir-opt/gvn_copy_aggregate.all_copy_has_changed.GVN.diff index 8012c26499c98..7a90189c4c496 100644 --- a/tests/mir-opt/gvn_copy_aggregate.all_copy_has_changed.GVN.diff +++ b/tests/mir-opt/gvn_copy_aggregate.all_copy_has_changed.GVN.diff @@ -21,14 +21,11 @@ } bb0: { -- StorageLive(_2); -+ nop; + StorageLive(_2); _2 = copy ((*_1).0: i32); -- StorageLive(_3); -+ nop; + StorageLive(_3); _3 = copy ((*_1).1: u64); -- StorageLive(_4); -+ nop; + StorageLive(_4); _4 = copy ((*_1).2: [i8; 3]); ((*_1).0: i32) = const 1_i32; StorageLive(_5); @@ -42,12 +39,9 @@ StorageDead(_7); StorageDead(_6); StorageDead(_5); -- StorageDead(_4); -- StorageDead(_3); -- StorageDead(_2); -+ nop; -+ nop; -+ nop; + StorageDead(_4); + StorageDead(_3); + StorageDead(_2); return; } } diff --git a/tests/mir-opt/gvn_copy_aggregate.all_copy_move.GVN.diff b/tests/mir-opt/gvn_copy_aggregate.all_copy_move.GVN.diff index 911b787a64bdb..416ee4ce7eea1 100644 --- a/tests/mir-opt/gvn_copy_aggregate.all_copy_move.GVN.diff +++ b/tests/mir-opt/gvn_copy_aggregate.all_copy_move.GVN.diff @@ -21,14 +21,11 @@ } bb0: { -- StorageLive(_2); -+ nop; + StorageLive(_2); _2 = copy (_1.0: i32); -- StorageLive(_3); -+ nop; + StorageLive(_3); _3 = copy (_1.1: u64); -- StorageLive(_4); -+ nop; + StorageLive(_4); _4 = copy (_1.2: [i8; 3]); StorageLive(_5); _5 = copy _2; @@ -41,12 +38,9 @@ StorageDead(_7); StorageDead(_6); StorageDead(_5); -- StorageDead(_4); -- StorageDead(_3); -- StorageDead(_2); -+ nop; -+ nop; -+ nop; + StorageDead(_4); + StorageDead(_3); + StorageDead(_2); return; } } diff --git a/tests/mir-opt/gvn_copy_aggregate.all_copy_ret_2.GVN.diff b/tests/mir-opt/gvn_copy_aggregate.all_copy_ret_2.GVN.diff index 5c6e2a6bc67db..fccbe492b4795 100644 --- a/tests/mir-opt/gvn_copy_aggregate.all_copy_ret_2.GVN.diff +++ b/tests/mir-opt/gvn_copy_aggregate.all_copy_ret_2.GVN.diff @@ -26,17 +26,13 @@ } bb0: { -- StorageLive(_2); -+ nop; + StorageLive(_2); _2 = copy ((*_1).0: i32); -- StorageLive(_3); -+ nop; + StorageLive(_3); _3 = copy ((*_1).1: u64); -- StorageLive(_4); -+ nop; + StorageLive(_4); _4 = copy ((*_1).2: [i8; 3]); -- StorageLive(_5); -+ nop; + StorageLive(_5); StorageLive(_6); _6 = copy _2; StorageLive(_7); @@ -63,14 +59,10 @@ - _0 = (move _5, move _9); + _0 = (copy _5, copy _5); StorageDead(_9); -- StorageDead(_5); -- StorageDead(_4); -- StorageDead(_3); -- StorageDead(_2); -+ nop; -+ nop; -+ nop; -+ nop; + StorageDead(_5); + StorageDead(_4); + StorageDead(_3); + StorageDead(_2); return; } } diff --git a/tests/mir-opt/gvn_copy_aggregate.all_copy_use_changed.GVN.diff b/tests/mir-opt/gvn_copy_aggregate.all_copy_use_changed.GVN.diff index dc65cccb7bd6e..e3842c9064fe4 100644 --- a/tests/mir-opt/gvn_copy_aggregate.all_copy_use_changed.GVN.diff +++ b/tests/mir-opt/gvn_copy_aggregate.all_copy_use_changed.GVN.diff @@ -29,11 +29,9 @@ _3 = copy ((*_1).0: i32); _2 = move _3; StorageDead(_3); -- StorageLive(_4); -+ nop; + StorageLive(_4); _4 = copy ((*_1).1: u64); -- StorageLive(_5); -+ nop; + StorageLive(_5); _5 = copy ((*_1).2: [i8; 3]); StorageLive(_6); _6 = copy _2; @@ -46,10 +44,8 @@ StorageDead(_8); StorageDead(_7); StorageDead(_6); -- StorageDead(_5); -- StorageDead(_4); -+ nop; -+ nop; + StorageDead(_5); + StorageDead(_4); StorageDead(_2); return; } diff --git a/tests/mir-opt/gvn_copy_aggregate.all_copy_use_changed_2.GVN.diff b/tests/mir-opt/gvn_copy_aggregate.all_copy_use_changed_2.GVN.diff index 08a4a078adcb4..3769c3cfa2ee4 100644 --- a/tests/mir-opt/gvn_copy_aggregate.all_copy_use_changed_2.GVN.diff +++ b/tests/mir-opt/gvn_copy_aggregate.all_copy_use_changed_2.GVN.diff @@ -24,11 +24,9 @@ bb0: { StorageLive(_2); _2 = copy ((*_1).0: i32); -- StorageLive(_3); -+ nop; + StorageLive(_3); _3 = copy ((*_1).1: u64); -- StorageLive(_4); -+ nop; + StorageLive(_4); _4 = copy ((*_1).2: [i8; 3]); ((*_1).0: i32) = const 1_i32; StorageLive(_5); @@ -46,10 +44,8 @@ StorageDead(_8); StorageDead(_7); StorageDead(_6); -- StorageDead(_4); -- StorageDead(_3); -+ nop; -+ nop; + StorageDead(_4); + StorageDead(_3); StorageDead(_2); return; } diff --git a/tests/mir-opt/gvn_copy_aggregate.enum_different_variant.GVN.diff b/tests/mir-opt/gvn_copy_aggregate.enum_different_variant.GVN.diff index 99318d395e218..a7063289e8ae6 100644 --- a/tests/mir-opt/gvn_copy_aggregate.enum_different_variant.GVN.diff +++ b/tests/mir-opt/gvn_copy_aggregate.enum_different_variant.GVN.diff @@ -66,20 +66,16 @@ bb2: { StorageLive(_12); _12 = &(((*_1) as B).0: AllCopy); -- StorageLive(_13); + StorageLive(_13); - _13 = copy ((*_12).0: i32); -- StorageLive(_14); -- _14 = copy ((*_12).1: u64); -- StorageLive(_15); -- _15 = copy ((*_12).2: [i8; 3]); -- StorageLive(_16); -+ nop; + _13 = copy ((((*_1) as B).0: AllCopy).0: i32); -+ nop; + StorageLive(_14); +- _14 = copy ((*_12).1: u64); + _14 = copy ((((*_1) as B).0: AllCopy).1: u64); -+ nop; + StorageLive(_15); +- _15 = copy ((*_12).2: [i8; 3]); + _15 = copy ((((*_1) as B).0: AllCopy).2: [i8; 3]); -+ nop; + StorageLive(_16); StorageLive(_17); _17 = copy _13; StorageLive(_18); @@ -97,14 +93,10 @@ + _20 = copy _16; + _0 = Enum1::A(copy _16); StorageDead(_20); -- StorageDead(_16); -- StorageDead(_15); -- StorageDead(_14); -- StorageDead(_13); -+ nop; -+ nop; -+ nop; -+ nop; + StorageDead(_16); + StorageDead(_15); + StorageDead(_14); + StorageDead(_13); StorageDead(_12); goto -> bb4; } @@ -112,20 +104,16 @@ bb3: { StorageLive(_3); _3 = &(((*_1) as A).0: AllCopy); -- StorageLive(_4); + StorageLive(_4); - _4 = copy ((*_3).0: i32); -- StorageLive(_5); -- _5 = copy ((*_3).1: u64); -- StorageLive(_6); -- _6 = copy ((*_3).2: [i8; 3]); -- StorageLive(_7); -+ nop; + _4 = copy ((((*_1) as A).0: AllCopy).0: i32); -+ nop; + StorageLive(_5); +- _5 = copy ((*_3).1: u64); + _5 = copy ((((*_1) as A).0: AllCopy).1: u64); -+ nop; + StorageLive(_6); +- _6 = copy ((*_3).2: [i8; 3]); + _6 = copy ((((*_1) as A).0: AllCopy).2: [i8; 3]); -+ nop; + StorageLive(_7); StorageLive(_8); _8 = copy _4; StorageLive(_9); @@ -143,14 +131,10 @@ + _11 = copy _7; + _0 = Enum1::B(copy _7); StorageDead(_11); -- StorageDead(_7); -- StorageDead(_6); -- StorageDead(_5); -- StorageDead(_4); -+ nop; -+ nop; -+ nop; -+ nop; + StorageDead(_7); + StorageDead(_6); + StorageDead(_5); + StorageDead(_4); StorageDead(_3); goto -> bb4; } diff --git a/tests/mir-opt/gvn_copy_aggregate.enum_identical_variant.GVN.diff b/tests/mir-opt/gvn_copy_aggregate.enum_identical_variant.GVN.diff index b740ba6411bd2..22ebaa5ca1932 100644 --- a/tests/mir-opt/gvn_copy_aggregate.enum_identical_variant.GVN.diff +++ b/tests/mir-opt/gvn_copy_aggregate.enum_identical_variant.GVN.diff @@ -66,20 +66,16 @@ bb2: { StorageLive(_12); _12 = &(((*_1) as B).0: AllCopy); -- StorageLive(_13); + StorageLive(_13); - _13 = copy ((*_12).0: i32); -- StorageLive(_14); -- _14 = copy ((*_12).1: u64); -- StorageLive(_15); -- _15 = copy ((*_12).2: [i8; 3]); -- StorageLive(_16); -+ nop; + _13 = copy ((((*_1) as B).0: AllCopy).0: i32); -+ nop; + StorageLive(_14); +- _14 = copy ((*_12).1: u64); + _14 = copy ((((*_1) as B).0: AllCopy).1: u64); -+ nop; + StorageLive(_15); +- _15 = copy ((*_12).2: [i8; 3]); + _15 = copy ((((*_1) as B).0: AllCopy).2: [i8; 3]); -+ nop; + StorageLive(_16); StorageLive(_17); _17 = copy _13; StorageLive(_18); @@ -97,14 +93,10 @@ + _20 = copy _16; + _0 = copy (*_1); StorageDead(_20); -- StorageDead(_16); -- StorageDead(_15); -- StorageDead(_14); -- StorageDead(_13); -+ nop; -+ nop; -+ nop; -+ nop; + StorageDead(_16); + StorageDead(_15); + StorageDead(_14); + StorageDead(_13); StorageDead(_12); goto -> bb4; } @@ -112,20 +104,16 @@ bb3: { StorageLive(_3); _3 = &(((*_1) as A).0: AllCopy); -- StorageLive(_4); + StorageLive(_4); - _4 = copy ((*_3).0: i32); -- StorageLive(_5); -- _5 = copy ((*_3).1: u64); -- StorageLive(_6); -- _6 = copy ((*_3).2: [i8; 3]); -- StorageLive(_7); -+ nop; + _4 = copy ((((*_1) as A).0: AllCopy).0: i32); -+ nop; + StorageLive(_5); +- _5 = copy ((*_3).1: u64); + _5 = copy ((((*_1) as A).0: AllCopy).1: u64); -+ nop; + StorageLive(_6); +- _6 = copy ((*_3).2: [i8; 3]); + _6 = copy ((((*_1) as A).0: AllCopy).2: [i8; 3]); -+ nop; + StorageLive(_7); StorageLive(_8); _8 = copy _4; StorageLive(_9); @@ -143,14 +131,10 @@ + _11 = copy _7; + _0 = copy (*_1); StorageDead(_11); -- StorageDead(_7); -- StorageDead(_6); -- StorageDead(_5); -- StorageDead(_4); -+ nop; -+ nop; -+ nop; -+ nop; + StorageDead(_7); + StorageDead(_6); + StorageDead(_5); + StorageDead(_4); StorageDead(_3); goto -> bb4; } diff --git a/tests/mir-opt/gvn_copy_aggregate.nest_copy.GVN.diff b/tests/mir-opt/gvn_copy_aggregate.nest_copy.GVN.diff index ee5906bab1161..f8515be75b8de 100644 --- a/tests/mir-opt/gvn_copy_aggregate.nest_copy.GVN.diff +++ b/tests/mir-opt/gvn_copy_aggregate.nest_copy.GVN.diff @@ -31,17 +31,13 @@ } bb0: { -- StorageLive(_2); -+ nop; + StorageLive(_2); _2 = copy (((*_1).1: AllCopy).0: i32); -- StorageLive(_3); -+ nop; + StorageLive(_3); _3 = copy (((*_1).1: AllCopy).1: u64); -- StorageLive(_4); -+ nop; + StorageLive(_4); _4 = copy (((*_1).1: AllCopy).2: [i8; 3]); -- StorageLive(_5); -+ nop; + StorageLive(_5); StorageLive(_6); _6 = copy _2; StorageLive(_7); @@ -53,8 +49,7 @@ StorageDead(_8); StorageDead(_7); StorageDead(_6); -- StorageLive(_9); -+ nop; + StorageLive(_9); _9 = copy ((*_1).0: i32); StorageLive(_10); _10 = copy _9; @@ -65,16 +60,11 @@ + _0 = copy (*_1); StorageDead(_11); StorageDead(_10); -- StorageDead(_9); -- StorageDead(_5); -- StorageDead(_4); -- StorageDead(_3); -- StorageDead(_2); -+ nop; -+ nop; -+ nop; -+ nop; -+ nop; + StorageDead(_9); + StorageDead(_5); + StorageDead(_4); + StorageDead(_3); + StorageDead(_2); return; } } diff --git a/tests/mir-opt/gvn_copy_aggregate.same_type_different_index.GVN.diff b/tests/mir-opt/gvn_copy_aggregate.same_type_different_index.GVN.diff index e3126b09a58e2..9c214330e352e 100644 --- a/tests/mir-opt/gvn_copy_aggregate.same_type_different_index.GVN.diff +++ b/tests/mir-opt/gvn_copy_aggregate.same_type_different_index.GVN.diff @@ -16,11 +16,9 @@ } bb0: { -- StorageLive(_2); -+ nop; + StorageLive(_2); _2 = copy ((*_1).1: i32); -- StorageLive(_3); -+ nop; + StorageLive(_3); _3 = copy ((*_1).0: i32); StorageLive(_4); _4 = copy _2; @@ -30,10 +28,8 @@ + _0 = SameType { a: copy _2, b: copy _3 }; StorageDead(_5); StorageDead(_4); -- StorageDead(_3); -- StorageDead(_2); -+ nop; -+ nop; + StorageDead(_3); + StorageDead(_2); return; } } diff --git a/tests/mir-opt/gvn_copy_constant_projection.compare_constant_index.GVN.panic-abort.diff b/tests/mir-opt/gvn_copy_constant_projection.compare_constant_index.GVN.panic-abort.diff index e2e55304921b2..c107eec9ee65b 100644 --- a/tests/mir-opt/gvn_copy_constant_projection.compare_constant_index.GVN.panic-abort.diff +++ b/tests/mir-opt/gvn_copy_constant_projection.compare_constant_index.GVN.panic-abort.diff @@ -17,8 +17,7 @@ } bb0: { -- StorageLive(_4); -+ nop; + StorageLive(_4); _4 = const 0_usize; - _5 = Lt(copy _4, const 1_usize); - assert(move _5, "index out of bounds: the length is {} but the index is {}", const 1_usize, copy _4) -> [success: bb1, unwind unreachable]; @@ -50,8 +49,7 @@ StorageDead(_10); StorageDead(_9); StorageDead(_7); -- StorageDead(_4); -+ nop; + StorageDead(_4); return; } } diff --git a/tests/mir-opt/gvn_copy_constant_projection.compare_constant_index.GVN.panic-unwind.diff b/tests/mir-opt/gvn_copy_constant_projection.compare_constant_index.GVN.panic-unwind.diff index 60611146a0eec..498df5adc1ef7 100644 --- a/tests/mir-opt/gvn_copy_constant_projection.compare_constant_index.GVN.panic-unwind.diff +++ b/tests/mir-opt/gvn_copy_constant_projection.compare_constant_index.GVN.panic-unwind.diff @@ -17,8 +17,7 @@ } bb0: { -- StorageLive(_4); -+ nop; + StorageLive(_4); _4 = const 0_usize; - _5 = Lt(copy _4, const 1_usize); - assert(move _5, "index out of bounds: the length is {} but the index is {}", const 1_usize, copy _4) -> [success: bb1, unwind continue]; @@ -50,8 +49,7 @@ StorageDead(_10); StorageDead(_9); StorageDead(_7); -- StorageDead(_4); -+ nop; + StorageDead(_4); return; } } diff --git a/tests/mir-opt/gvn_on_unsafe_binder.propagate.GVN.diff b/tests/mir-opt/gvn_on_unsafe_binder.propagate.GVN.diff index e28d04f1d5885..cef44cb99d66c 100644 --- a/tests/mir-opt/gvn_on_unsafe_binder.propagate.GVN.diff +++ b/tests/mir-opt/gvn_on_unsafe_binder.propagate.GVN.diff @@ -14,8 +14,7 @@ } bb0: { -- StorageLive(_1); -+ nop; + StorageLive(_1); _1 = const 1_i32; StorageLive(_2); StorageLive(_3); @@ -27,8 +26,7 @@ - _0 = move _2; + _0 = const {transmute(0x00000001): unsafe<> i32}; StorageDead(_2); -- StorageDead(_1); -+ nop; + StorageDead(_1); return; } } diff --git a/tests/mir-opt/gvn_storage_twice.repeat_local.GVN.diff b/tests/mir-opt/gvn_storage_twice.repeat_local.GVN.diff new file mode 100644 index 0000000000000..1c399d42d6fc9 --- /dev/null +++ b/tests/mir-opt/gvn_storage_twice.repeat_local.GVN.diff @@ -0,0 +1,17 @@ +- // MIR for `repeat_local` before GVN ++ // MIR for `repeat_local` after GVN + + fn repeat_local(_1: usize, _2: usize, _3: i32) -> i32 { + let mut _0: i32; + let mut _4: [i32; 5]; + let mut _5: &i32; + + bb0: { + _4 = [copy _3; 5]; + _5 = &_4[_1]; +- _0 = copy (*_5); ++ _0 = copy _3; + return; + } + } + diff --git a/tests/mir-opt/gvn_storage_twice.repeat_local_dead.GVN.diff b/tests/mir-opt/gvn_storage_twice.repeat_local_dead.GVN.diff new file mode 100644 index 0000000000000..ee044aa5a0b18 --- /dev/null +++ b/tests/mir-opt/gvn_storage_twice.repeat_local_dead.GVN.diff @@ -0,0 +1,19 @@ +- // MIR for `repeat_local_dead` before GVN ++ // MIR for `repeat_local_dead` after GVN + + fn repeat_local_dead(_1: usize, _2: usize, _3: i32) -> i32 { + let mut _0: i32; + let mut _4: [i32; 5]; + let mut _5: &i32; + + bb0: { + _4 = [copy _3; 5]; + _5 = &_4[_1]; +- StorageDead(_3); +- _0 = copy (*_5); ++ nop; ++ _0 = copy _3; + return; + } + } + diff --git a/tests/mir-opt/gvn_storage_twice.repeat_local_dead_live.GVN.diff b/tests/mir-opt/gvn_storage_twice.repeat_local_dead_live.GVN.diff new file mode 100644 index 0000000000000..9448e91d33a3e --- /dev/null +++ b/tests/mir-opt/gvn_storage_twice.repeat_local_dead_live.GVN.diff @@ -0,0 +1,21 @@ +- // MIR for `repeat_local_dead_live` before GVN ++ // MIR for `repeat_local_dead_live` after GVN + + fn repeat_local_dead_live(_1: usize, _2: usize, _3: i32) -> i32 { + let mut _0: i32; + let mut _4: [i32; 5]; + let mut _5: &i32; + + bb0: { + _4 = [copy _3; 5]; + _5 = &_4[_1]; +- StorageDead(_3); +- StorageLive(_3); +- _0 = copy (*_5); ++ nop; ++ nop; ++ _0 = copy _3; + return; + } + } + diff --git a/tests/mir-opt/gvn_storage_twice.rs b/tests/mir-opt/gvn_storage_twice.rs new file mode 100644 index 0000000000000..d6aa0ed87befe --- /dev/null +++ b/tests/mir-opt/gvn_storage_twice.rs @@ -0,0 +1,65 @@ +// skip-filecheck +//@ test-mir-pass: GVN +//@ compile-flags: -Zlint-mir=false + +#![feature(custom_mir, core_intrinsics)] + +use std::intrinsics::mir::*; + +// EMIT_MIR gvn_storage_twice.repeat_local.GVN.diff +// EMIT_MIR gvn_storage_twice.repeat_local_dead.GVN.diff +// EMIT_MIR gvn_storage_twice.repeat_local_dead_live.GVN.diff + +// Check that we remove the storage statements if the local +// doesn't have valid storage when it is used. +// +// Based on `gvn_repeat.rs::repeat_local`, were GVN should replace +// `let RET = *_5;` with `let RET = _3;`. + +#[custom_mir(dialect = "runtime")] +pub fn repeat_local(_1: usize, _2: usize, _3: i32) -> i32 { + mir! { + { + let _4 = [_3; 5]; + let _5 = &_4[_1]; + RET = *_5; + Return() + } + } +} + +// Since _3 is dead when we access _5, GVN should remove the storage statements. + +#[custom_mir(dialect = "runtime")] +pub fn repeat_local_dead(_1: usize, _2: usize, _3: i32) -> i32 { + mir! { + { + let _4 = [_3; 5]; + let _5 = &_4[_1]; + StorageDead(_3); + RET = *_5; + Return() + } + } +} + +// Since _3 is uninit due to storage when we access _5, GVN should remove the storage statements. + +#[custom_mir(dialect = "runtime")] +pub fn repeat_local_dead_live(_1: usize, _2: usize, _3: i32) -> i32 { + mir! { + { + let _4 = [_3; 5]; + let _5 = &_4[_1]; + StorageDead(_3); + StorageLive(_3); + RET = *_5; + Return() + } + } +} + +#[inline(never)] +fn opaque(a: T) -> T { + a +} diff --git a/tests/mir-opt/inline/inline_diverging.h.Inline.panic-abort.diff b/tests/mir-opt/inline/inline_diverging.h.Inline.panic-abort.diff index f099d763c3d8d..a116086a0ce14 100644 --- a/tests/mir-opt/inline/inline_diverging.h.Inline.panic-abort.diff +++ b/tests/mir-opt/inline/inline_diverging.h.Inline.panic-abort.diff @@ -35,7 +35,6 @@ + StorageLive(_2); + _2 = sleep; + StorageLive(_4); -+ StorageLive(_6); + StorageLive(_3); + _3 = &_2; + StorageLive(_7); diff --git a/tests/mir-opt/inline/inline_diverging.h.Inline.panic-unwind.diff b/tests/mir-opt/inline/inline_diverging.h.Inline.panic-unwind.diff index c33e0810739f2..978de2884c081 100644 --- a/tests/mir-opt/inline/inline_diverging.h.Inline.panic-unwind.diff +++ b/tests/mir-opt/inline/inline_diverging.h.Inline.panic-unwind.diff @@ -35,7 +35,6 @@ - _1 = call_twice:: ! {sleep}>(sleep) -> unwind continue; + StorageLive(_2); + _2 = sleep; -+ StorageLive(_6); + StorageLive(_4); + StorageLive(_3); + _3 = &_2; diff --git a/tests/mir-opt/issue_141649_gvn_storage_remove.main.GVN.panic-abort.diff b/tests/mir-opt/issue_141649_gvn_storage_remove.main.GVN.panic-abort.diff index 5e19645ed5b7d..79230f8e354a5 100644 --- a/tests/mir-opt/issue_141649_gvn_storage_remove.main.GVN.panic-abort.diff +++ b/tests/mir-opt/issue_141649_gvn_storage_remove.main.GVN.panic-abort.diff @@ -33,9 +33,8 @@ bb0: { StorageLive(_1); -- StorageLive(_2); + StorageLive(_2); - _2 = S(const 1_u32, const 2_u32); -+ nop; + _2 = const S(1_u32, 2_u32); StorageLive(_3); StorageLive(_4); @@ -49,13 +48,11 @@ StorageDead(_4); StorageDead(_3); _1 = const (); -- StorageDead(_2); -+ nop; + StorageDead(_2); StorageDead(_1); StorageLive(_5); -- StorageLive(_6); + StorageLive(_6); - _6 = S(const 3_u32, const 4_u32); -+ nop; + _6 = const S(3_u32, 4_u32); StorageLive(_7); StorageLive(_8); @@ -69,13 +66,11 @@ StorageDead(_8); StorageDead(_7); _5 = const (); -- StorageDead(_6); -+ nop; + StorageDead(_6); StorageDead(_5); StorageLive(_9); -- StorageLive(_10); + StorageLive(_10); - _10 = C(const 1_u32, const 2_u32); -+ nop; + _10 = const C(1_u32, 2_u32); StorageLive(_11); StorageLive(_12); @@ -89,12 +84,10 @@ StorageDead(_12); StorageDead(_11); _9 = const (); -- StorageDead(_10); -+ nop; + StorageDead(_10); StorageDead(_9); -- StorageLive(_13); + StorageLive(_13); - _13 = C(const 3_u32, const 4_u32); -+ nop; + _13 = const C(3_u32, 4_u32); StorageLive(_14); StorageLive(_15); @@ -108,8 +101,7 @@ StorageDead(_15); StorageDead(_14); _0 = const (); -- StorageDead(_13); -+ nop; + StorageDead(_13); return; } + } diff --git a/tests/mir-opt/issue_141649_gvn_storage_remove.main.GVN.panic-unwind.diff b/tests/mir-opt/issue_141649_gvn_storage_remove.main.GVN.panic-unwind.diff index 8f60f2f63e0f6..a9c68d742f504 100644 --- a/tests/mir-opt/issue_141649_gvn_storage_remove.main.GVN.panic-unwind.diff +++ b/tests/mir-opt/issue_141649_gvn_storage_remove.main.GVN.panic-unwind.diff @@ -33,9 +33,8 @@ bb0: { StorageLive(_1); -- StorageLive(_2); + StorageLive(_2); - _2 = S(const 1_u32, const 2_u32); -+ nop; + _2 = const S(1_u32, 2_u32); StorageLive(_3); StorageLive(_4); @@ -49,13 +48,11 @@ StorageDead(_4); StorageDead(_3); _1 = const (); -- StorageDead(_2); -+ nop; + StorageDead(_2); StorageDead(_1); StorageLive(_5); -- StorageLive(_6); + StorageLive(_6); - _6 = S(const 3_u32, const 4_u32); -+ nop; + _6 = const S(3_u32, 4_u32); StorageLive(_7); StorageLive(_8); @@ -69,13 +66,11 @@ StorageDead(_8); StorageDead(_7); _5 = const (); -- StorageDead(_6); -+ nop; + StorageDead(_6); StorageDead(_5); StorageLive(_9); -- StorageLive(_10); + StorageLive(_10); - _10 = C(const 1_u32, const 2_u32); -+ nop; + _10 = const C(1_u32, 2_u32); StorageLive(_11); StorageLive(_12); @@ -89,12 +84,10 @@ StorageDead(_12); StorageDead(_11); _9 = const (); -- StorageDead(_10); -+ nop; + StorageDead(_10); StorageDead(_9); -- StorageLive(_13); + StorageLive(_13); - _13 = C(const 3_u32, const 4_u32); -+ nop; + _13 = const C(3_u32, 4_u32); StorageLive(_14); StorageLive(_15); @@ -108,8 +101,7 @@ StorageDead(_15); StorageDead(_14); _0 = const (); -- StorageDead(_13); -+ nop; + StorageDead(_13); return; } + } diff --git a/tests/mir-opt/issue_76432.test.SimplifyComparisonIntegral.panic-abort.diff b/tests/mir-opt/issue_76432.test.SimplifyComparisonIntegral.panic-abort.diff index c02bab3524bca..a01b10364a01d 100644 --- a/tests/mir-opt/issue_76432.test.SimplifyComparisonIntegral.panic-abort.diff +++ b/tests/mir-opt/issue_76432.test.SimplifyComparisonIntegral.panic-abort.diff @@ -23,10 +23,12 @@ } bb0: { + StorageLive(_3); StorageLive(_4); _4 = [copy _1, copy _1, copy _1]; _3 = &_4; _2 = copy _3 as &[T] (PointerCoercion(Unsize, Implicit)); + StorageDead(_3); nop; nop; goto -> bb2; diff --git a/tests/mir-opt/issue_76432.test.SimplifyComparisonIntegral.panic-unwind.diff b/tests/mir-opt/issue_76432.test.SimplifyComparisonIntegral.panic-unwind.diff index 49be042588cb3..dd5d700863646 100644 --- a/tests/mir-opt/issue_76432.test.SimplifyComparisonIntegral.panic-unwind.diff +++ b/tests/mir-opt/issue_76432.test.SimplifyComparisonIntegral.panic-unwind.diff @@ -23,10 +23,12 @@ } bb0: { + StorageLive(_3); StorageLive(_4); _4 = [copy _1, copy _1, copy _1]; _3 = &_4; _2 = copy _3 as &[T] (PointerCoercion(Unsize, Implicit)); + StorageDead(_3); nop; nop; goto -> bb2; diff --git a/tests/mir-opt/issues/issue_75439.foo.MatchBranchSimplification.diff b/tests/mir-opt/issues/issue_75439.foo.MatchBranchSimplification.diff index d8eace98d556e..febcb0944c710 100644 --- a/tests/mir-opt/issues/issue_75439.foo.MatchBranchSimplification.diff +++ b/tests/mir-opt/issues/issue_75439.foo.MatchBranchSimplification.diff @@ -29,11 +29,13 @@ } bb3: { + StorageLive(_3); _3 = copy _2[3 of 4]; StorageLive(_4); _4 = copy _3 as [u8; 4] (Transmute); _0 = Option::<[u8; 4]>::Some(move _4); StorageDead(_4); + StorageDead(_3); goto -> bb5; } diff --git a/tests/mir-opt/lower_array_len.array_bound.GVN.panic-abort.diff b/tests/mir-opt/lower_array_len.array_bound.GVN.panic-abort.diff index 98c5e868046b5..c0500ca3bb835 100644 --- a/tests/mir-opt/lower_array_len.array_bound.GVN.panic-abort.diff +++ b/tests/mir-opt/lower_array_len.array_bound.GVN.panic-abort.diff @@ -14,8 +14,7 @@ let mut _9: bool; bb0: { -- StorageLive(_3); -+ nop; + StorageLive(_3); StorageLive(_4); _4 = copy _1; StorageLive(_5); @@ -63,8 +62,7 @@ } bb5: { -- StorageDead(_3); -+ nop; + StorageDead(_3); return; } } diff --git a/tests/mir-opt/lower_array_len.array_bound.GVN.panic-unwind.diff b/tests/mir-opt/lower_array_len.array_bound.GVN.panic-unwind.diff index 72c7313786996..9e6d01764ccd5 100644 --- a/tests/mir-opt/lower_array_len.array_bound.GVN.panic-unwind.diff +++ b/tests/mir-opt/lower_array_len.array_bound.GVN.panic-unwind.diff @@ -14,8 +14,7 @@ let mut _9: bool; bb0: { -- StorageLive(_3); -+ nop; + StorageLive(_3); StorageLive(_4); _4 = copy _1; StorageLive(_5); @@ -63,8 +62,7 @@ } bb5: { -- StorageDead(_3); -+ nop; + StorageDead(_3); return; } } diff --git a/tests/mir-opt/lower_array_len.array_bound_mut.GVN.panic-abort.diff b/tests/mir-opt/lower_array_len.array_bound_mut.GVN.panic-abort.diff index 9ffaf44c02bd2..b2d0efff8f30a 100644 --- a/tests/mir-opt/lower_array_len.array_bound_mut.GVN.panic-abort.diff +++ b/tests/mir-opt/lower_array_len.array_bound_mut.GVN.panic-abort.diff @@ -16,8 +16,7 @@ let mut _11: bool; bb0: { -- StorageLive(_3); -+ nop; + StorageLive(_3); StorageLive(_4); _4 = copy _1; StorageLive(_5); @@ -77,8 +76,7 @@ } bb6: { -- StorageDead(_3); -+ nop; + StorageDead(_3); return; } } diff --git a/tests/mir-opt/lower_array_len.array_bound_mut.GVN.panic-unwind.diff b/tests/mir-opt/lower_array_len.array_bound_mut.GVN.panic-unwind.diff index 08008e463357f..ab5209eca7592 100644 --- a/tests/mir-opt/lower_array_len.array_bound_mut.GVN.panic-unwind.diff +++ b/tests/mir-opt/lower_array_len.array_bound_mut.GVN.panic-unwind.diff @@ -16,8 +16,7 @@ let mut _11: bool; bb0: { -- StorageLive(_3); -+ nop; + StorageLive(_3); StorageLive(_4); _4 = copy _1; StorageLive(_5); @@ -77,8 +76,7 @@ } bb6: { -- StorageDead(_3); -+ nop; + StorageDead(_3); return; } } diff --git a/tests/mir-opt/lower_array_len.array_len_raw.GVN.panic-abort.diff b/tests/mir-opt/lower_array_len.array_len_raw.GVN.panic-abort.diff index 180a7db029794..714a12804e692 100644 --- a/tests/mir-opt/lower_array_len.array_len_raw.GVN.panic-abort.diff +++ b/tests/mir-opt/lower_array_len.array_len_raw.GVN.panic-abort.diff @@ -18,8 +18,7 @@ } bb0: { -- StorageLive(_2); -+ nop; + StorageLive(_2); StorageLive(_3); StorageLive(_4); _4 = &_1; @@ -41,8 +40,7 @@ bb1: { StorageDead(_6); StorageDead(_5); -- StorageDead(_2); -+ nop; + StorageDead(_2); StorageDead(_7); return; } diff --git a/tests/mir-opt/lower_array_len.array_len_raw.GVN.panic-unwind.diff b/tests/mir-opt/lower_array_len.array_len_raw.GVN.panic-unwind.diff index 180a7db029794..714a12804e692 100644 --- a/tests/mir-opt/lower_array_len.array_len_raw.GVN.panic-unwind.diff +++ b/tests/mir-opt/lower_array_len.array_len_raw.GVN.panic-unwind.diff @@ -18,8 +18,7 @@ } bb0: { -- StorageLive(_2); -+ nop; + StorageLive(_2); StorageLive(_3); StorageLive(_4); _4 = &_1; @@ -41,8 +40,7 @@ bb1: { StorageDead(_6); StorageDead(_5); -- StorageDead(_2); -+ nop; + StorageDead(_2); StorageDead(_7); return; } diff --git a/tests/mir-opt/lower_array_len.array_len_reborrow.GVN.panic-abort.diff b/tests/mir-opt/lower_array_len.array_len_reborrow.GVN.panic-abort.diff index 49964f8b49e26..b236b22f067d8 100644 --- a/tests/mir-opt/lower_array_len.array_len_reborrow.GVN.panic-abort.diff +++ b/tests/mir-opt/lower_array_len.array_len_reborrow.GVN.panic-abort.diff @@ -17,8 +17,7 @@ } bb0: { -- StorageLive(_2); -+ nop; + StorageLive(_2); StorageLive(_3); StorageLive(_4); _4 = &mut _1; @@ -38,8 +37,7 @@ bb1: { StorageDead(_6); StorageDead(_5); -- StorageDead(_2); -+ nop; + StorageDead(_2); return; } } diff --git a/tests/mir-opt/lower_array_len.array_len_reborrow.GVN.panic-unwind.diff b/tests/mir-opt/lower_array_len.array_len_reborrow.GVN.panic-unwind.diff index 49964f8b49e26..b236b22f067d8 100644 --- a/tests/mir-opt/lower_array_len.array_len_reborrow.GVN.panic-unwind.diff +++ b/tests/mir-opt/lower_array_len.array_len_reborrow.GVN.panic-unwind.diff @@ -17,8 +17,7 @@ } bb0: { -- StorageLive(_2); -+ nop; + StorageLive(_2); StorageLive(_3); StorageLive(_4); _4 = &mut _1; @@ -38,8 +37,7 @@ bb1: { StorageDead(_6); StorageDead(_5); -- StorageDead(_2); -+ nop; + StorageDead(_2); return; } } diff --git a/tests/mir-opt/pre-codegen/checked_ops.use_checked_sub.PreCodegen.after.panic-abort.mir b/tests/mir-opt/pre-codegen/checked_ops.use_checked_sub.PreCodegen.after.panic-abort.mir index 3c475cd403091..426c114dfc2ab 100644 --- a/tests/mir-opt/pre-codegen/checked_ops.use_checked_sub.PreCodegen.after.panic-abort.mir +++ b/tests/mir-opt/pre-codegen/checked_ops.use_checked_sub.PreCodegen.after.panic-abort.mir @@ -19,7 +19,7 @@ fn use_checked_sub(_1: u32, _2: u32) -> () { StorageLive(_5); StorageLive(_3); _3 = Lt(copy _1, copy _2); - switchInt(move _3) -> [0: bb1, otherwise: bb2]; + switchInt(move _3) -> [0: bb1, otherwise: bb3]; } bb1: { @@ -28,16 +28,22 @@ fn use_checked_sub(_1: u32, _2: u32) -> () { _5 = Option::::Some(move _4); StorageDead(_4); StorageDead(_3); + StorageLive(_6); _6 = copy ((_5 as Some).0: u32); - _7 = do_something(move _6) -> [return: bb3, unwind unreachable]; + _7 = do_something(move _6) -> [return: bb2, unwind unreachable]; } bb2: { - StorageDead(_3); - goto -> bb3; + StorageDead(_6); + goto -> bb4; } bb3: { + StorageDead(_3); + goto -> bb4; + } + + bb4: { StorageDead(_5); return; } diff --git a/tests/mir-opt/pre-codegen/checked_ops.use_checked_sub.PreCodegen.after.panic-unwind.mir b/tests/mir-opt/pre-codegen/checked_ops.use_checked_sub.PreCodegen.after.panic-unwind.mir index 3ef09764b1c5b..f73c64a9b0929 100644 --- a/tests/mir-opt/pre-codegen/checked_ops.use_checked_sub.PreCodegen.after.panic-unwind.mir +++ b/tests/mir-opt/pre-codegen/checked_ops.use_checked_sub.PreCodegen.after.panic-unwind.mir @@ -19,7 +19,7 @@ fn use_checked_sub(_1: u32, _2: u32) -> () { StorageLive(_5); StorageLive(_3); _3 = Lt(copy _1, copy _2); - switchInt(move _3) -> [0: bb1, otherwise: bb2]; + switchInt(move _3) -> [0: bb1, otherwise: bb3]; } bb1: { @@ -28,16 +28,22 @@ fn use_checked_sub(_1: u32, _2: u32) -> () { _5 = Option::::Some(move _4); StorageDead(_4); StorageDead(_3); + StorageLive(_6); _6 = copy ((_5 as Some).0: u32); - _7 = do_something(move _6) -> [return: bb3, unwind continue]; + _7 = do_something(move _6) -> [return: bb2, unwind continue]; } bb2: { - StorageDead(_3); - goto -> bb3; + StorageDead(_6); + goto -> bb4; } bb3: { + StorageDead(_3); + goto -> bb4; + } + + bb4: { StorageDead(_5); return; } diff --git a/tests/mir-opt/pre-codegen/deref_nested_borrows.src.GVN.panic-abort.diff b/tests/mir-opt/pre-codegen/deref_nested_borrows.src.GVN.panic-abort.diff index 993857f225a81..f64efed6b3814 100644 --- a/tests/mir-opt/pre-codegen/deref_nested_borrows.src.GVN.panic-abort.diff +++ b/tests/mir-opt/pre-codegen/deref_nested_borrows.src.GVN.panic-abort.diff @@ -15,9 +15,8 @@ } bb0: { -- StorageLive(_2); + StorageLive(_2); - _6 = deref_copy (*_1); -+ nop; + _6 = copy (*_1); _2 = copy (*_6); _3 = unknown() -> [return: bb1, unwind unreachable]; @@ -34,8 +33,7 @@ + _0 = Eq(move _4, copy _2); StorageDead(_5); StorageDead(_4); -- StorageDead(_2); -+ nop; + StorageDead(_2); return; } } diff --git a/tests/mir-opt/pre-codegen/deref_nested_borrows.src.GVN.panic-unwind.diff b/tests/mir-opt/pre-codegen/deref_nested_borrows.src.GVN.panic-unwind.diff index d81bfa9310bc1..077bca2805d63 100644 --- a/tests/mir-opt/pre-codegen/deref_nested_borrows.src.GVN.panic-unwind.diff +++ b/tests/mir-opt/pre-codegen/deref_nested_borrows.src.GVN.panic-unwind.diff @@ -15,9 +15,8 @@ } bb0: { -- StorageLive(_2); + StorageLive(_2); - _6 = deref_copy (*_1); -+ nop; + _6 = copy (*_1); _2 = copy (*_6); _3 = unknown() -> [return: bb1, unwind continue]; @@ -34,8 +33,7 @@ + _0 = Eq(move _4, copy _2); StorageDead(_5); StorageDead(_4); -- StorageDead(_2); -+ nop; + StorageDead(_2); return; } } diff --git a/tests/mir-opt/pre-codegen/deref_nested_borrows.src.PreCodegen.after.panic-abort.mir b/tests/mir-opt/pre-codegen/deref_nested_borrows.src.PreCodegen.after.panic-abort.mir index 23b1c3f3f43ad..b3789dfab0cdc 100644 --- a/tests/mir-opt/pre-codegen/deref_nested_borrows.src.PreCodegen.after.panic-abort.mir +++ b/tests/mir-opt/pre-codegen/deref_nested_borrows.src.PreCodegen.after.panic-abort.mir @@ -13,6 +13,7 @@ fn src(_1: &&u8) -> bool { } bb0: { + StorageLive(_3); _2 = copy (*_1); _3 = copy (*_2); _4 = unknown() -> [return: bb1, unwind unreachable]; @@ -24,6 +25,7 @@ fn src(_1: &&u8) -> bool { _6 = copy (*_5); _0 = Eq(move _6, copy _3); StorageDead(_6); + StorageDead(_3); return; } } diff --git a/tests/mir-opt/pre-codegen/deref_nested_borrows.src.PreCodegen.after.panic-unwind.mir b/tests/mir-opt/pre-codegen/deref_nested_borrows.src.PreCodegen.after.panic-unwind.mir index 4c01e9464bf49..a3cf4806010a6 100644 --- a/tests/mir-opt/pre-codegen/deref_nested_borrows.src.PreCodegen.after.panic-unwind.mir +++ b/tests/mir-opt/pre-codegen/deref_nested_borrows.src.PreCodegen.after.panic-unwind.mir @@ -13,6 +13,7 @@ fn src(_1: &&u8) -> bool { } bb0: { + StorageLive(_3); _2 = copy (*_1); _3 = copy (*_2); _4 = unknown() -> [return: bb1, unwind continue]; @@ -24,6 +25,7 @@ fn src(_1: &&u8) -> bool { _6 = copy (*_5); _0 = Eq(move _6, copy _3); StorageDead(_6); + StorageDead(_3); return; } } diff --git a/tests/mir-opt/pre-codegen/derived_ord.demo_le.PreCodegen.after.mir b/tests/mir-opt/pre-codegen/derived_ord.demo_le.PreCodegen.after.mir index 8746cb0899166..f498f4326056d 100644 --- a/tests/mir-opt/pre-codegen/derived_ord.demo_le.PreCodegen.after.mir +++ b/tests/mir-opt/pre-codegen/derived_ord.demo_le.PreCodegen.after.mir @@ -40,8 +40,8 @@ fn demo_le(_1: &MultiField, _2: &MultiField) -> bool { StorageLive(_12); StorageLive(_11); StorageLive(_5); - StorageLive(_6); StorageLive(_7); + StorageLive(_6); StorageLive(_3); _3 = copy ((*_1).0: char); StorageLive(_4); @@ -65,16 +65,16 @@ fn demo_le(_1: &MultiField, _2: &MultiField) -> bool { StorageDead(_8); _11 = Option::::Some(move _10); StorageDead(_10); - StorageDead(_7); StorageDead(_6); + StorageDead(_7); StorageDead(_5); goto -> bb3; } bb2: { _11 = copy _6; - StorageDead(_7); StorageDead(_6); + StorageDead(_7); StorageDead(_5); goto -> bb3; } diff --git a/tests/mir-opt/pre-codegen/derived_ord.{impl#0}-partial_cmp.PreCodegen.after.mir b/tests/mir-opt/pre-codegen/derived_ord.{impl#0}-partial_cmp.PreCodegen.after.mir index de25eebee77ff..bdabedef4e166 100644 --- a/tests/mir-opt/pre-codegen/derived_ord.{impl#0}-partial_cmp.PreCodegen.after.mir +++ b/tests/mir-opt/pre-codegen/derived_ord.{impl#0}-partial_cmp.PreCodegen.after.mir @@ -21,6 +21,7 @@ fn ::partial_cmp(_1: &MultiField, _2: &M } bb0: { + StorageLive(_6); StorageLive(_3); _3 = copy ((*_1).0: char); StorageLive(_4); @@ -53,6 +54,7 @@ fn ::partial_cmp(_1: &MultiField, _2: &M } bb3: { + StorageDead(_6); return; } } diff --git a/tests/mir-opt/pre-codegen/issue_117368_print_invalid_constant.main.GVN.32bit.panic-abort.diff b/tests/mir-opt/pre-codegen/issue_117368_print_invalid_constant.main.GVN.32bit.panic-abort.diff index 027c71dfaae46..8534f02594216 100644 --- a/tests/mir-opt/pre-codegen/issue_117368_print_invalid_constant.main.GVN.32bit.panic-abort.diff +++ b/tests/mir-opt/pre-codegen/issue_117368_print_invalid_constant.main.GVN.32bit.panic-abort.diff @@ -41,8 +41,7 @@ } bb0: { -- StorageLive(_1); -+ nop; + StorageLive(_1); StorageLive(_2); - _2 = Option::::None; + _2 = const Option::::None; @@ -106,8 +105,7 @@ _3 = move _4 as *mut u8 (PtrToPtr); StorageDead(_4); StorageDead(_3); -- StorageDead(_1); -+ nop; + StorageDead(_1); return; } + } diff --git a/tests/mir-opt/pre-codegen/issue_117368_print_invalid_constant.main.GVN.32bit.panic-unwind.diff b/tests/mir-opt/pre-codegen/issue_117368_print_invalid_constant.main.GVN.32bit.panic-unwind.diff index 88bd4628c297a..0f752cac5596f 100644 --- a/tests/mir-opt/pre-codegen/issue_117368_print_invalid_constant.main.GVN.32bit.panic-unwind.diff +++ b/tests/mir-opt/pre-codegen/issue_117368_print_invalid_constant.main.GVN.32bit.panic-unwind.diff @@ -30,8 +30,7 @@ } bb0: { -- StorageLive(_1); -+ nop; + StorageLive(_1); StorageLive(_2); - _2 = Option::::None; + _2 = const Option::::None; @@ -49,8 +48,7 @@ _3 = move _4 as *mut u8 (PtrToPtr); StorageDead(_4); StorageDead(_3); -- StorageDead(_1); -+ nop; + StorageDead(_1); return; } diff --git a/tests/mir-opt/pre-codegen/issue_117368_print_invalid_constant.main.GVN.64bit.panic-abort.diff b/tests/mir-opt/pre-codegen/issue_117368_print_invalid_constant.main.GVN.64bit.panic-abort.diff index ebf305a6f1b12..f7e472c48df98 100644 --- a/tests/mir-opt/pre-codegen/issue_117368_print_invalid_constant.main.GVN.64bit.panic-abort.diff +++ b/tests/mir-opt/pre-codegen/issue_117368_print_invalid_constant.main.GVN.64bit.panic-abort.diff @@ -41,8 +41,7 @@ } bb0: { -- StorageLive(_1); -+ nop; + StorageLive(_1); StorageLive(_2); - _2 = Option::::None; + _2 = const Option::::None; @@ -106,8 +105,7 @@ _3 = move _4 as *mut u8 (PtrToPtr); StorageDead(_4); StorageDead(_3); -- StorageDead(_1); -+ nop; + StorageDead(_1); return; } + } diff --git a/tests/mir-opt/pre-codegen/issue_117368_print_invalid_constant.main.GVN.64bit.panic-unwind.diff b/tests/mir-opt/pre-codegen/issue_117368_print_invalid_constant.main.GVN.64bit.panic-unwind.diff index 0c52f1e058367..d0e4b9ad24e8d 100644 --- a/tests/mir-opt/pre-codegen/issue_117368_print_invalid_constant.main.GVN.64bit.panic-unwind.diff +++ b/tests/mir-opt/pre-codegen/issue_117368_print_invalid_constant.main.GVN.64bit.panic-unwind.diff @@ -30,8 +30,7 @@ } bb0: { -- StorageLive(_1); -+ nop; + StorageLive(_1); StorageLive(_2); - _2 = Option::::None; + _2 = const Option::::None; @@ -49,8 +48,7 @@ _3 = move _4 as *mut u8 (PtrToPtr); StorageDead(_4); StorageDead(_3); -- StorageDead(_1); -+ nop; + StorageDead(_1); 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 75e8cb1d8618c..48948acfad973 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 @@ -64,11 +64,13 @@ fn filter_mapped(_1: impl Iterator, _2: impl Fn(T) -> Option) -> () } bb6: { + StorageLive(_10); _10 = move ((_8 as Some).0: U); _11 = opaque::(move _10) -> [return: bb7, unwind: bb9]; } bb7: { + StorageDead(_10); StorageDead(_8); 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 154cbd3791cbd..a4050a261dcf6 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 @@ -62,6 +62,7 @@ fn int_range(_1: usize, _2: usize) -> () { bb1: { StorageLive(_13); _5 = &mut _4; + StorageLive(_11); StorageLive(_10); StorageLive(_6); _6 = &(_4.0: usize); @@ -81,6 +82,7 @@ fn int_range(_1: usize, _2: usize) -> () { StorageDead(_7); StorageDead(_6); StorageDead(_10); + StorageDead(_11); StorageDead(_13); StorageDead(_4); return; @@ -96,11 +98,14 @@ fn int_range(_1: usize, _2: usize) -> () { StorageDead(_12); _13 = Option::::Some(copy _11); StorageDead(_10); + StorageDead(_11); + StorageLive(_14); _14 = copy ((_13 as Some).0: usize); _15 = opaque::(move _14) -> [return: bb4, unwind continue]; } bb4: { + StorageDead(_14); StorageDead(_13); goto -> bb1; } diff --git a/tests/mir-opt/pre-codegen/loops.mapped.PreCodegen.after.mir b/tests/mir-opt/pre-codegen/loops.mapped.PreCodegen.after.mir index d22ea54004c91..e1bb56ef66eb5 100644 --- a/tests/mir-opt/pre-codegen/loops.mapped.PreCodegen.after.mir +++ b/tests/mir-opt/pre-codegen/loops.mapped.PreCodegen.after.mir @@ -100,11 +100,13 @@ fn mapped(_1: impl Iterator, _2: impl Fn(T) -> U) -> () { StorageDead(_9); StorageDead(_7); StorageDead(_8); + StorageLive(_14); _14 = move ((_13 as Some).0: U); _15 = opaque::(move _14) -> [return: bb8, unwind: bb10]; } bb8: { + StorageDead(_14); StorageDead(_13); goto -> bb2; } diff --git a/tests/mir-opt/pre-codegen/loops.vec_move.PreCodegen.after.mir b/tests/mir-opt/pre-codegen/loops.vec_move.PreCodegen.after.mir index e537dd6a28ef8..9e6043919b5da 100644 --- a/tests/mir-opt/pre-codegen/loops.vec_move.PreCodegen.after.mir +++ b/tests/mir-opt/pre-codegen/loops.vec_move.PreCodegen.after.mir @@ -30,6 +30,7 @@ fn vec_move(_1: Vec) -> () { bb2: { StorageLive(_5); + StorageLive(_4); _4 = &mut _3; _5 = as Iterator>::next(move _4) -> [return: bb3, unwind: bb9]; } @@ -40,6 +41,7 @@ fn vec_move(_1: Vec) -> () { } bb4: { + StorageDead(_4); StorageDead(_5); drop(_3) -> [return: bb5, unwind continue]; } @@ -51,11 +53,14 @@ fn vec_move(_1: Vec) -> () { } bb6: { + StorageLive(_7); _7 = move ((_5 as Some).0: impl Sized); _8 = opaque::(move _7) -> [return: bb7, unwind: bb9]; } bb7: { + StorageDead(_7); + StorageDead(_4); StorageDead(_5); goto -> bb2; } 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 dfe618612ab96..3d44fd6807f19 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 @@ -69,13 +69,16 @@ fn forward_loop(_1: u32, _2: u32, _3: impl Fn(u32)) -> () { } bb4: { + StorageLive(_7); _7 = copy _4; StorageLive(_8); _8 = AddUnchecked(copy _7, const 1_u32); _4 = move _8; StorageDead(_8); _9 = Option::::Some(copy _7); + StorageDead(_7); StorageDead(_6); + StorageLive(_10); _10 = copy ((_9 as Some).0: u32); StorageLive(_11); _11 = &_3; @@ -87,6 +90,7 @@ fn forward_loop(_1: u32, _2: u32, _3: impl Fn(u32)) -> () { bb5: { StorageDead(_12); StorageDead(_11); + StorageDead(_10); StorageDead(_9); 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 e0fcfcaffc59a..b955501316549 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 @@ -69,13 +69,16 @@ fn forward_loop(_1: u32, _2: u32, _3: impl Fn(u32)) -> () { } bb4: { + StorageLive(_7); _7 = copy _4; StorageLive(_8); _8 = AddUnchecked(copy _7, const 1_u32); _4 = move _8; StorageDead(_8); _9 = Option::::Some(copy _7); + StorageDead(_7); StorageDead(_6); + StorageLive(_10); _10 = copy ((_9 as Some).0: u32); StorageLive(_11); _11 = &_3; @@ -87,6 +90,7 @@ fn forward_loop(_1: u32, _2: u32, _3: impl Fn(u32)) -> () { bb5: { StorageDead(_12); StorageDead(_11); + StorageDead(_10); StorageDead(_9); goto -> bb1; } diff --git a/tests/mir-opt/pre-codegen/range_iter.inclusive_loop.PreCodegen.after.panic-abort.mir b/tests/mir-opt/pre-codegen/range_iter.inclusive_loop.PreCodegen.after.panic-abort.mir index 3f000dcafb035..63d9b1d1d0038 100644 --- a/tests/mir-opt/pre-codegen/range_iter.inclusive_loop.PreCodegen.after.panic-abort.mir +++ b/tests/mir-opt/pre-codegen/range_iter.inclusive_loop.PreCodegen.after.panic-abort.mir @@ -36,6 +36,7 @@ fn inclusive_loop(_1: u32, _2: u32, _3: impl Fn(u32)) -> () { bb1: { StorageLive(_7); + StorageLive(_6); _6 = &mut _5; _7 = as iter::range::RangeInclusiveIteratorImpl>::spec_next(move _6) -> [return: bb2, unwind unreachable]; } @@ -46,6 +47,7 @@ fn inclusive_loop(_1: u32, _2: u32, _3: impl Fn(u32)) -> () { } bb3: { + StorageDead(_6); StorageDead(_7); StorageDead(_5); drop(_3) -> [return: bb4, unwind unreachable]; @@ -56,6 +58,7 @@ fn inclusive_loop(_1: u32, _2: u32, _3: impl Fn(u32)) -> () { } bb5: { + StorageLive(_9); _9 = copy ((_7 as Some).0: u32); StorageLive(_10); _10 = &_3; @@ -67,6 +70,8 @@ fn inclusive_loop(_1: u32, _2: u32, _3: impl Fn(u32)) -> () { bb6: { StorageDead(_11); StorageDead(_10); + StorageDead(_9); + StorageDead(_6); StorageDead(_7); goto -> bb1; } diff --git a/tests/mir-opt/pre-codegen/range_iter.inclusive_loop.PreCodegen.after.panic-unwind.mir b/tests/mir-opt/pre-codegen/range_iter.inclusive_loop.PreCodegen.after.panic-unwind.mir index 2353717362711..33c9b492c5f1a 100644 --- a/tests/mir-opt/pre-codegen/range_iter.inclusive_loop.PreCodegen.after.panic-unwind.mir +++ b/tests/mir-opt/pre-codegen/range_iter.inclusive_loop.PreCodegen.after.panic-unwind.mir @@ -36,6 +36,7 @@ fn inclusive_loop(_1: u32, _2: u32, _3: impl Fn(u32)) -> () { bb1: { StorageLive(_7); + StorageLive(_6); _6 = &mut _5; _7 = as iter::range::RangeInclusiveIteratorImpl>::spec_next(move _6) -> [return: bb2, unwind: bb8]; } @@ -46,6 +47,7 @@ fn inclusive_loop(_1: u32, _2: u32, _3: impl Fn(u32)) -> () { } bb3: { + StorageDead(_6); StorageDead(_7); StorageDead(_5); drop(_3) -> [return: bb4, unwind continue]; @@ -56,6 +58,7 @@ fn inclusive_loop(_1: u32, _2: u32, _3: impl Fn(u32)) -> () { } bb5: { + StorageLive(_9); _9 = copy ((_7 as Some).0: u32); StorageLive(_10); _10 = &_3; @@ -67,6 +70,8 @@ fn inclusive_loop(_1: u32, _2: u32, _3: impl Fn(u32)) -> () { bb6: { StorageDead(_11); StorageDead(_10); + StorageDead(_9); + StorageDead(_6); StorageDead(_7); 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 1f82fc59ac2c1..55caea9d8f96d 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 @@ -43,12 +43,14 @@ fn range_iter_next(_1: &mut std::ops::Range) -> Option { } bb2: { + StorageLive(_5); _5 = copy ((*_1).0: u32); StorageLive(_6); _6 = AddUnchecked(copy _5, const 1_u32); ((*_1).0: u32) = move _6; StorageDead(_6); _0 = Option::::Some(copy _5); + StorageDead(_5); goto -> bb3; } 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 1f82fc59ac2c1..55caea9d8f96d 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 @@ -43,12 +43,14 @@ fn range_iter_next(_1: &mut std::ops::Range) -> Option { } bb2: { + StorageLive(_5); _5 = copy ((*_1).0: u32); StorageLive(_6); _6 = AddUnchecked(copy _5, const 1_u32); ((*_1).0: u32) = move _6; StorageDead(_6); _0 = Option::::Some(copy _5); + StorageDead(_5); goto -> bb3; } diff --git a/tests/mir-opt/pre-codegen/simple_option_map.ezmap.PreCodegen.after.mir b/tests/mir-opt/pre-codegen/simple_option_map.ezmap.PreCodegen.after.mir index 7595ad88d9df4..876fa96dfb6fe 100644 --- a/tests/mir-opt/pre-codegen/simple_option_map.ezmap.PreCodegen.after.mir +++ b/tests/mir-opt/pre-codegen/simple_option_map.ezmap.PreCodegen.after.mir @@ -25,11 +25,13 @@ fn ezmap(_1: Option) -> Option { } bb2: { + StorageLive(_3); _3 = copy ((_1 as Some).0: i32); StorageLive(_4); _4 = Add(copy _3, const 1_i32); _0 = Option::::Some(move _4); StorageDead(_4); + StorageDead(_3); goto -> bb3; } 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 cbdd194afd3ab..bb93139c31be5 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 @@ -68,10 +68,14 @@ fn variant_a::{closure#0}(_1: &mut {closure@$DIR/slice_filter.rs:7:25: 7:39}, _2 } bb0: { + StorageLive(_4); _3 = copy (*_2); _4 = &((*_3).0: usize); + StorageLive(_5); _5 = &((*_3).1: usize); + StorageLive(_6); _6 = &((*_3).2: usize); + StorageLive(_7); _7 = &((*_3).3: usize); StorageLive(_13); StorageLive(_8); @@ -180,6 +184,10 @@ fn variant_a::{closure#0}(_1: &mut {closure@$DIR/slice_filter.rs:7:25: 7:39}, _2 bb9: { StorageDead(_19); StorageDead(_13); + StorageDead(_7); + StorageDead(_6); + StorageDead(_5); + StorageDead(_4); return; } } diff --git a/tests/mir-opt/pre-codegen/slice_filter.variant_b-{closure#0}.PreCodegen.after.mir b/tests/mir-opt/pre-codegen/slice_filter.variant_b-{closure#0}.PreCodegen.after.mir index bc7a31d52199b..1d0ebfc3bcd70 100644 --- a/tests/mir-opt/pre-codegen/slice_filter.variant_b-{closure#0}.PreCodegen.after.mir +++ b/tests/mir-opt/pre-codegen/slice_filter.variant_b-{closure#0}.PreCodegen.after.mir @@ -18,10 +18,14 @@ fn variant_b::{closure#0}(_1: &mut {closure@$DIR/slice_filter.rs:11:25: 11:41}, } bb0: { + StorageLive(_4); _3 = copy (*_2); _4 = copy ((*_3).0: usize); + StorageLive(_5); _5 = copy ((*_3).1: usize); + StorageLive(_6); _6 = copy ((*_3).2: usize); + StorageLive(_7); _7 = copy ((*_3).3: usize); StorageLive(_8); _8 = Le(copy _4, copy _6); @@ -63,6 +67,10 @@ fn variant_b::{closure#0}(_1: &mut {closure@$DIR/slice_filter.rs:11:25: 11:41}, bb7: { StorageDead(_9); StorageDead(_8); + StorageDead(_7); + StorageDead(_6); + StorageDead(_5); + StorageDead(_4); return; } } 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 6fb1637a6e02f..b03344c848d80 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 @@ -31,6 +31,8 @@ fn slice_get_unchecked_mut_range(_1: &mut [u32], _2: std::ops::Range) -> } bb0: { + StorageLive(_3); + StorageLive(_4); _3 = move (_2.0: usize); _4 = move (_2.1: usize); StorageLive(_11); @@ -56,6 +58,8 @@ fn slice_get_unchecked_mut_range(_1: &mut [u32], _2: std::ops::Range) -> StorageDead(_5); _0 = &mut (*_11); StorageDead(_11); + StorageDead(_3); + StorageDead(_4); return; } } 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 6fb1637a6e02f..b03344c848d80 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 @@ -31,6 +31,8 @@ fn slice_get_unchecked_mut_range(_1: &mut [u32], _2: std::ops::Range) -> } bb0: { + StorageLive(_3); + StorageLive(_4); _3 = move (_2.0: usize); _4 = move (_2.1: usize); StorageLive(_11); @@ -56,6 +58,8 @@ fn slice_get_unchecked_mut_range(_1: &mut [u32], _2: std::ops::Range) -> StorageDead(_5); _0 = &mut (*_11); StorageDead(_11); + StorageDead(_3); + StorageDead(_4); return; } } diff --git a/tests/mir-opt/pre-codegen/slice_index.slice_ptr_get_unchecked_range.PreCodegen.after.panic-abort.mir b/tests/mir-opt/pre-codegen/slice_index.slice_ptr_get_unchecked_range.PreCodegen.after.panic-abort.mir index ad1ca5dff43a9..9e5c652c11d1a 100644 --- a/tests/mir-opt/pre-codegen/slice_index.slice_ptr_get_unchecked_range.PreCodegen.after.panic-abort.mir +++ b/tests/mir-opt/pre-codegen/slice_index.slice_ptr_get_unchecked_range.PreCodegen.after.panic-abort.mir @@ -29,6 +29,8 @@ fn slice_ptr_get_unchecked_range(_1: *const [u32], _2: std::ops::Range) - } bb0: { + StorageLive(_3); + StorageLive(_4); _3 = move (_2.0: usize); _4 = move (_2.1: usize); StorageLive(_7); @@ -48,6 +50,8 @@ fn slice_ptr_get_unchecked_range(_1: *const [u32], _2: std::ops::Range) - StorageDead(_9); StorageDead(_8); StorageDead(_7); + StorageDead(_3); + StorageDead(_4); return; } } diff --git a/tests/mir-opt/pre-codegen/slice_index.slice_ptr_get_unchecked_range.PreCodegen.after.panic-unwind.mir b/tests/mir-opt/pre-codegen/slice_index.slice_ptr_get_unchecked_range.PreCodegen.after.panic-unwind.mir index ad1ca5dff43a9..9e5c652c11d1a 100644 --- a/tests/mir-opt/pre-codegen/slice_index.slice_ptr_get_unchecked_range.PreCodegen.after.panic-unwind.mir +++ b/tests/mir-opt/pre-codegen/slice_index.slice_ptr_get_unchecked_range.PreCodegen.after.panic-unwind.mir @@ -29,6 +29,8 @@ fn slice_ptr_get_unchecked_range(_1: *const [u32], _2: std::ops::Range) - } bb0: { + StorageLive(_3); + StorageLive(_4); _3 = move (_2.0: usize); _4 = move (_2.1: usize); StorageLive(_7); @@ -48,6 +50,8 @@ fn slice_ptr_get_unchecked_range(_1: *const [u32], _2: std::ops::Range) - StorageDead(_9); StorageDead(_8); StorageDead(_7); + StorageDead(_3); + StorageDead(_4); return; } } diff --git a/tests/mir-opt/pre-codegen/try_identity.new.PreCodegen.after.mir b/tests/mir-opt/pre-codegen/try_identity.new.PreCodegen.after.mir index baa01e28a9410..6035f245c4977 100644 --- a/tests/mir-opt/pre-codegen/try_identity.new.PreCodegen.after.mir +++ b/tests/mir-opt/pre-codegen/try_identity.new.PreCodegen.after.mir @@ -29,8 +29,10 @@ fn new(_1: Result) -> Result { } bb1: { + StorageLive(_3); _3 = move ((_1 as Ok).0: T); _4 = ControlFlow::::Continue(copy _3); + StorageDead(_3); _5 = move ((_4 as Continue).0: T); _0 = Result::::Ok(copy _5); StorageDead(_4); @@ -38,10 +40,14 @@ fn new(_1: Result) -> Result { } bb2: { + StorageLive(_6); _6 = move ((_1 as Err).0: E); _4 = ControlFlow::::Break(copy _6); + StorageDead(_6); + StorageLive(_7); _7 = move ((_4 as Break).0: E); _0 = Result::::Err(copy _7); + StorageDead(_7); StorageDead(_4); goto -> bb3; } diff --git a/tests/mir-opt/pre-codegen/try_identity.old.PreCodegen.after.mir b/tests/mir-opt/pre-codegen/try_identity.old.PreCodegen.after.mir index 889e80d26e1cc..aec51bfd8d745 100644 --- a/tests/mir-opt/pre-codegen/try_identity.old.PreCodegen.after.mir +++ b/tests/mir-opt/pre-codegen/try_identity.old.PreCodegen.after.mir @@ -19,14 +19,18 @@ fn old(_1: Result) -> Result { } bb1: { + StorageLive(_3); _3 = copy ((_1 as Ok).0: T); + StorageDead(_3); _0 = copy _1; goto -> bb3; } bb2: { + StorageLive(_4); _4 = copy ((_1 as Err).0: E); _0 = copy _1; + StorageDead(_4); goto -> bb3; } diff --git a/tests/mir-opt/separate_const_switch.identity.JumpThreading.diff b/tests/mir-opt/separate_const_switch.identity.JumpThreading.diff index ce9d812701a8f..516edfbeb9c7e 100644 --- a/tests/mir-opt/separate_const_switch.identity.JumpThreading.diff +++ b/tests/mir-opt/separate_const_switch.identity.JumpThreading.diff @@ -57,9 +57,13 @@ } bb3: { + StorageLive(_4); _4 = copy ((_2 as Break).0: std::result::Result); + StorageLive(_10); _10 = copy ((_4 as Err).0: i32); _0 = Result::::Err(copy _10); + StorageDead(_10); + StorageDead(_4); StorageDead(_2); return; } diff --git a/tests/mir-opt/separate_const_switch.too_complex.JumpThreading.diff b/tests/mir-opt/separate_const_switch.too_complex.JumpThreading.diff index c88c63e0c1334..97be532254528 100644 --- a/tests/mir-opt/separate_const_switch.too_complex.JumpThreading.diff +++ b/tests/mir-opt/separate_const_switch.too_complex.JumpThreading.diff @@ -35,15 +35,19 @@ } bb2: { + StorageLive(_5); _5 = copy ((_1 as Err).0: usize); _2 = ControlFlow::::Break(copy _5); + StorageDead(_5); - goto -> bb4; + goto -> bb8; } bb3: { + StorageLive(_4); _4 = copy ((_1 as Ok).0: i32); _2 = ControlFlow::::Continue(copy _4); + StorageDead(_4); goto -> bb4; } @@ -62,8 +66,10 @@ } bb6: { + StorageLive(_7); _7 = copy ((_2 as Continue).0: i32); _0 = Option::::Some(copy _7); + StorageDead(_7); goto -> bb7; } diff --git a/tests/mir-opt/simplify_aggregate_to_copy_miscompile.foo.GVN.diff b/tests/mir-opt/simplify_aggregate_to_copy_miscompile.foo.GVN.diff index 54c11679f0c69..9d1c9079a2465 100644 --- a/tests/mir-opt/simplify_aggregate_to_copy_miscompile.foo.GVN.diff +++ b/tests/mir-opt/simplify_aggregate_to_copy_miscompile.foo.GVN.diff @@ -30,8 +30,7 @@ } bb2: { -- StorageLive(_5); -+ nop; + StorageLive(_5); _5 = copy (((*_2) as Some).0: i32); StorageLive(_7); - _7 = Option::::None; @@ -44,8 +43,7 @@ - _0 = Option::::Some(move _8); + _0 = Option::::Some(copy _5); StorageDead(_8); -- StorageDead(_5); -+ nop; + StorageDead(_5); StorageDead(_2); return; } diff --git a/tests/mir-opt/simplify_match.main.GVN.panic-abort.diff b/tests/mir-opt/simplify_match.main.GVN.panic-abort.diff index 9e798cbcac0c1..30c3b0bcfa1d7 100644 --- a/tests/mir-opt/simplify_match.main.GVN.panic-abort.diff +++ b/tests/mir-opt/simplify_match.main.GVN.panic-abort.diff @@ -11,14 +11,12 @@ bb0: { StorageLive(_1); -- StorageLive(_2); -+ nop; + StorageLive(_2); _2 = const false; - _1 = copy _2; -- StorageDead(_2); -- switchInt(copy _1) -> [0: bb2, otherwise: bb1]; + _1 = const false; -+ nop; + StorageDead(_2); +- switchInt(copy _1) -> [0: bb2, otherwise: bb1]; + switchInt(const false) -> [0: bb2, otherwise: bb1]; } diff --git a/tests/mir-opt/simplify_match.main.GVN.panic-unwind.diff b/tests/mir-opt/simplify_match.main.GVN.panic-unwind.diff index e243ff45ab0b2..7923d3210d83f 100644 --- a/tests/mir-opt/simplify_match.main.GVN.panic-unwind.diff +++ b/tests/mir-opt/simplify_match.main.GVN.panic-unwind.diff @@ -11,14 +11,12 @@ bb0: { StorageLive(_1); -- StorageLive(_2); -+ nop; + StorageLive(_2); _2 = const false; - _1 = copy _2; -- StorageDead(_2); -- switchInt(copy _1) -> [0: bb2, otherwise: bb1]; + _1 = const false; -+ nop; + StorageDead(_2); +- switchInt(copy _1) -> [0: bb2, otherwise: bb1]; + switchInt(const false) -> [0: bb2, otherwise: bb1]; } From ce5b7ecaed96d26b93fcedf0e52130a8188f59f4 Mon Sep 17 00:00:00 2001 From: Ohad Ravid Date: Sun, 29 Jun 2025 08:07:37 +0300 Subject: [PATCH 05/14] Use a single bitset to check the storage in copy_prop, only check reachable blocks --- compiler/rustc_mir_transform/src/copy_prop.rs | 71 ++++++++++--------- ...y_prop_storage_unreachable.f.CopyProp.diff | 27 +++++++ .../copy_prop_storage_unreachable.rs | 35 +++++++++ ...ward_loop.PreCodegen.after.panic-abort.mir | 5 +- ...ard_loop.PreCodegen.after.panic-unwind.mir | 5 +- ...iter_next.PreCodegen.after.panic-abort.mir | 4 +- ...ter_next.PreCodegen.after.panic-unwind.mir | 4 +- 7 files changed, 108 insertions(+), 43 deletions(-) create mode 100644 tests/mir-opt/copy-prop/copy_prop_storage_unreachable.f.CopyProp.diff create mode 100644 tests/mir-opt/copy-prop/copy_prop_storage_unreachable.rs diff --git a/compiler/rustc_mir_transform/src/copy_prop.rs b/compiler/rustc_mir_transform/src/copy_prop.rs index d6d1ebda033c6..e114f0d80ef62 100644 --- a/compiler/rustc_mir_transform/src/copy_prop.rs +++ b/compiler/rustc_mir_transform/src/copy_prop.rs @@ -32,30 +32,20 @@ impl<'tcx> crate::MirPass<'tcx> for CopyProp { let typing_env = body.typing_env(tcx); let ssa = SsaLocals::new(tcx, body, typing_env); - let borrowed_locals = ssa.borrowed_locals().clone(); - debug!(?borrowed_locals); + debug!(borrowed_locals = ?ssa.borrowed_locals()); debug!(copy_classes = ?ssa.copy_classes()); let mut any_replacement = false; let fully_moved = fully_moved_locals(&ssa, body); debug!(?fully_moved); - let mut head_storage_to_check = DenseBitSet::new_empty(fully_moved.domain_size()); let mut storage_to_remove = DenseBitSet::new_empty(fully_moved.domain_size()); for (local, &head) in ssa.copy_classes().iter_enumerated() { if local != head { any_replacement = true; - // We need to determine if we can keep the head's storage statements (which enables better optimizations). - // For every local's usage location, if the head is maybe-uninitialized, we'll need to remove it's storage statements. - head_storage_to_check.insert(head); - - if borrowed_locals.contains(local) { - // To keep the storage of a head, we require that none of the locals in it's copy class are borrowed, - // since otherwise we cannot easily identify when it is used. - storage_to_remove.insert(head); - } + storage_to_remove.insert(head); } } @@ -66,8 +56,12 @@ impl<'tcx> crate::MirPass<'tcx> for CopyProp { let fully_moved = fully_moved_locals(&ssa, body); debug!(?fully_moved); - // Debug builds have no use for the storage statements, so avoid extra work. - let storage_to_remove = if any_replacement && tcx.sess.emit_lifetime_markers() { + // We can determine if we can keep the head's storage statements (which enables better optimizations). + // For every local's usage location, we'll to remove it's storage statements only if the head is maybe-uninitialized, + // or if the local is borrowed (since we cannot easily identify when it is used). + let storage_to_remove = if tcx.sess.emit_lifetime_markers() { + storage_to_remove.clear(); + let maybe_uninit = MaybeUninitializedLocals::new() .iterate_to_fixpoint(tcx, body, Some("mir_opt::copy_prop")) .into_results_cursor(body); @@ -75,16 +69,18 @@ impl<'tcx> crate::MirPass<'tcx> for CopyProp { let mut storage_checker = StorageChecker { maybe_uninit, copy_classes: ssa.copy_classes(), - head_storage_to_check, + borrowed_locals: ssa.borrowed_locals(), storage_to_remove, }; - storage_checker.visit_body(body); + for (bb, data) in traversal::reachable(body) { + storage_checker.visit_basic_block_data(bb, data); + } storage_checker.storage_to_remove } else { // Conservatively remove all storage statements for the head locals. - head_storage_to_check + storage_to_remove }; debug!(?storage_to_remove); @@ -200,7 +196,7 @@ impl<'tcx> MutVisitor<'tcx> for Replacer<'_, 'tcx> { struct StorageChecker<'a, 'tcx> { maybe_uninit: ResultsCursor<'a, 'tcx, MaybeUninitializedLocals>, copy_classes: &'a IndexSlice, - head_storage_to_check: DenseBitSet, + borrowed_locals: &'a DenseBitSet, storage_to_remove: DenseBitSet, } @@ -222,23 +218,28 @@ impl<'a, 'tcx> Visitor<'tcx> for StorageChecker<'a, 'tcx> { let head = self.copy_classes[local]; - // The head must be initialized at the location of the local, otherwise we must remove it's storage statements. - if self.head_storage_to_check.contains(head) { - self.maybe_uninit.seek_before_primary_effect(loc); - - if self.maybe_uninit.get().contains(head) { - debug!( - ?loc, - ?context, - ?local, - ?head, - "found a head at a location in which it is maybe uninit, marking head for storage statement removal" - ); - self.storage_to_remove.insert(head); - - // Once we found a use of the head that is maybe uninit, we do not need to check it again. - self.head_storage_to_check.remove(head); - } + // If the local is the head, or if we already marked it for deletion, we do not need to check it. + if head == local || self.storage_to_remove.contains(head) { + return; + } + + // If the local is borrowed, we cannot easily determine if it is used, so we have to remove the storage statements. + if self.borrowed_locals.contains(local) { + self.storage_to_remove.insert(head); + return; + } + + self.maybe_uninit.seek_before_primary_effect(loc); + + if self.maybe_uninit.get().contains(head) { + debug!( + ?loc, + ?context, + ?local, + ?head, + "found a head at a location in which it is maybe uninit, marking head for storage statement removal" + ); + self.storage_to_remove.insert(head); } } } diff --git a/tests/mir-opt/copy-prop/copy_prop_storage_unreachable.f.CopyProp.diff b/tests/mir-opt/copy-prop/copy_prop_storage_unreachable.f.CopyProp.diff new file mode 100644 index 0000000000000..93c186846908e --- /dev/null +++ b/tests/mir-opt/copy-prop/copy_prop_storage_unreachable.f.CopyProp.diff @@ -0,0 +1,27 @@ +- // MIR for `f` before CopyProp ++ // MIR for `f` after CopyProp + + fn f(_1: &mut usize) -> () { + let mut _0: (); + let mut _2: usize; + let mut _3: usize; + + bb0: { + StorageLive(_2); + _2 = const 42_usize; +- _3 = copy _2; +- (*_1) = copy _3; ++ (*_1) = copy _2; + StorageDead(_2); + return; + } + + bb1: { + StorageLive(_2); +- (*_1) = copy _3; ++ (*_1) = copy _2; + StorageDead(_2); + return; + } + } + diff --git a/tests/mir-opt/copy-prop/copy_prop_storage_unreachable.rs b/tests/mir-opt/copy-prop/copy_prop_storage_unreachable.rs new file mode 100644 index 0000000000000..65295acc8a226 --- /dev/null +++ b/tests/mir-opt/copy-prop/copy_prop_storage_unreachable.rs @@ -0,0 +1,35 @@ +// skip-filecheck +//@ test-mir-pass: CopyProp + +#![feature(custom_mir, core_intrinsics)] + +// Check that we do not remove the storage statements if the head +// is uninitialized in an unreachable block. + +use std::intrinsics::mir::*; + +// EMIT_MIR copy_prop_storage_unreachable.f.CopyProp.diff + +#[custom_mir(dialect = "runtime", phase = "post-cleanup")] +pub fn f(_1: &mut usize) { + mir! { + let _2: usize; + let _3: usize; + { + StorageLive(_2); + _2 = 42; + _3 = _2; + (*_1) = _3; + StorageDead(_2); + Return() + } + bb1 = { + // Ensure that _2 is considered uninitialized by `MaybeUninitializedLocals`. + StorageLive(_2); + // Use of _3 (in an unreachable block) when definition of _2 is unavailable. + (*_1) = _3; + StorageDead(_2); + Return() + } + } +} 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 3d44fd6807f19..ef73dd8150f63 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 @@ -49,6 +49,7 @@ fn forward_loop(_1: u32, _2: u32, _3: impl Fn(u32)) -> () { bb1: { StorageLive(_9); + StorageLive(_7); StorageLive(_6); StorageLive(_5); _5 = copy _4; @@ -59,6 +60,7 @@ fn forward_loop(_1: u32, _2: u32, _3: impl Fn(u32)) -> () { bb2: { StorageDead(_6); + StorageDead(_7); StorageDead(_9); StorageDead(_4); drop(_3) -> [return: bb3, unwind unreachable]; @@ -69,15 +71,14 @@ fn forward_loop(_1: u32, _2: u32, _3: impl Fn(u32)) -> () { } bb4: { - StorageLive(_7); _7 = copy _4; StorageLive(_8); _8 = AddUnchecked(copy _7, const 1_u32); _4 = move _8; StorageDead(_8); _9 = Option::::Some(copy _7); - StorageDead(_7); StorageDead(_6); + StorageDead(_7); StorageLive(_10); _10 = copy ((_9 as Some).0: u32); StorageLive(_11); 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 b955501316549..a3b6cda831833 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 @@ -49,6 +49,7 @@ fn forward_loop(_1: u32, _2: u32, _3: impl Fn(u32)) -> () { bb1: { StorageLive(_9); + StorageLive(_7); StorageLive(_6); StorageLive(_5); _5 = copy _4; @@ -59,6 +60,7 @@ fn forward_loop(_1: u32, _2: u32, _3: impl Fn(u32)) -> () { bb2: { StorageDead(_6); + StorageDead(_7); StorageDead(_9); StorageDead(_4); drop(_3) -> [return: bb3, unwind continue]; @@ -69,15 +71,14 @@ fn forward_loop(_1: u32, _2: u32, _3: impl Fn(u32)) -> () { } bb4: { - StorageLive(_7); _7 = copy _4; StorageLive(_8); _8 = AddUnchecked(copy _7, const 1_u32); _4 = move _8; StorageDead(_8); _9 = Option::::Some(copy _7); - StorageDead(_7); StorageDead(_6); + StorageDead(_7); StorageLive(_10); _10 = copy ((_9 as Some).0: u32); StorageLive(_11); 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 55caea9d8f96d..335e0bcb6b1f2 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 @@ -26,6 +26,7 @@ fn range_iter_next(_1: &mut std::ops::Range) -> Option { } bb0: { + StorageLive(_5); StorageLive(_4); StorageLive(_2); _2 = copy ((*_1).0: u32); @@ -43,19 +44,18 @@ fn range_iter_next(_1: &mut std::ops::Range) -> Option { } bb2: { - StorageLive(_5); _5 = copy ((*_1).0: u32); StorageLive(_6); _6 = AddUnchecked(copy _5, const 1_u32); ((*_1).0: u32) = move _6; StorageDead(_6); _0 = Option::::Some(copy _5); - StorageDead(_5); goto -> bb3; } bb3: { StorageDead(_4); + StorageDead(_5); 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 55caea9d8f96d..335e0bcb6b1f2 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 @@ -26,6 +26,7 @@ fn range_iter_next(_1: &mut std::ops::Range) -> Option { } bb0: { + StorageLive(_5); StorageLive(_4); StorageLive(_2); _2 = copy ((*_1).0: u32); @@ -43,19 +44,18 @@ fn range_iter_next(_1: &mut std::ops::Range) -> Option { } bb2: { - StorageLive(_5); _5 = copy ((*_1).0: u32); StorageLive(_6); _6 = AddUnchecked(copy _5, const 1_u32); ((*_1).0: u32) = move _6; StorageDead(_6); _0 = Option::::Some(copy _5); - StorageDead(_5); goto -> bb3; } bb3: { StorageDead(_4); + StorageDead(_5); return; } } From e0def5164d55b6c0220d6cc83f583c69f136b86b Mon Sep 17 00:00:00 2001 From: Ohad Ravid Date: Sun, 29 Jun 2025 08:23:31 +0300 Subject: [PATCH 06/14] Added test for preserving head storage --- ...prop_storage_preserve_head.f.CopyProp.diff | 20 +++++++++++++++ .../copy_prop_storage_preserve_head.rs | 25 +++++++++++++++++++ 2 files changed, 45 insertions(+) create mode 100644 tests/mir-opt/copy-prop/copy_prop_storage_preserve_head.f.CopyProp.diff create mode 100644 tests/mir-opt/copy-prop/copy_prop_storage_preserve_head.rs diff --git a/tests/mir-opt/copy-prop/copy_prop_storage_preserve_head.f.CopyProp.diff b/tests/mir-opt/copy-prop/copy_prop_storage_preserve_head.f.CopyProp.diff new file mode 100644 index 0000000000000..3eebfdd6303a1 --- /dev/null +++ b/tests/mir-opt/copy-prop/copy_prop_storage_preserve_head.f.CopyProp.diff @@ -0,0 +1,20 @@ +- // MIR for `f` before CopyProp ++ // MIR for `f` after CopyProp + + fn f(_1: &mut usize) -> () { + let mut _0: (); + let mut _2: usize; + let mut _3: usize; + + bb0: { + StorageLive(_2); + _2 = const 0_usize; +- _3 = copy _2; +- (*_1) = copy _3; ++ (*_1) = copy _2; + StorageDead(_2); + (*_1) = copy _2; + return; + } + } + diff --git a/tests/mir-opt/copy-prop/copy_prop_storage_preserve_head.rs b/tests/mir-opt/copy-prop/copy_prop_storage_preserve_head.rs new file mode 100644 index 0000000000000..c66da3aecb022 --- /dev/null +++ b/tests/mir-opt/copy-prop/copy_prop_storage_preserve_head.rs @@ -0,0 +1,25 @@ +// skip-filecheck +//@ test-mir-pass: CopyProp +//@ compile-flags: -Zlint-mir=false + +#![feature(custom_mir, core_intrinsics)] +use std::intrinsics::mir::*; + +// EMIT_MIR copy_prop_storage_preserve_head.f.CopyProp.diff + +#[custom_mir(dialect = "runtime", phase = "post-cleanup")] +pub fn f(_1: &mut usize) { + mir! { + let _2: usize; + let _3: usize; + { + StorageLive(_2); + _2 = 0; + _3 = _2; + (*_1) = _3; + StorageDead(_2); + (*_1) = _2; + Return() + } + } +} From 13bbc3203043e45619e5957672a973f988b66aa4 Mon Sep 17 00:00:00 2001 From: Ohad Ravid Date: Sun, 29 Jun 2025 08:39:42 +0300 Subject: [PATCH 07/14] Move `MaybeUninitializedLocals` to the ssa module --- .../src/impls/initialized.rs | 74 ------------------ compiler/rustc_mir_dataflow/src/impls/mod.rs | 2 +- compiler/rustc_mir_transform/src/copy_prop.rs | 8 +- compiler/rustc_mir_transform/src/gvn.rs | 3 +- compiler/rustc_mir_transform/src/ssa.rs | 75 +++++++++++++++++++ 5 files changed, 79 insertions(+), 83 deletions(-) diff --git a/compiler/rustc_mir_dataflow/src/impls/initialized.rs b/compiler/rustc_mir_dataflow/src/impls/initialized.rs index 961a6d42891ed..18165b0b9bd08 100644 --- a/compiler/rustc_mir_dataflow/src/impls/initialized.rs +++ b/compiler/rustc_mir_dataflow/src/impls/initialized.rs @@ -558,80 +558,6 @@ impl<'tcx> Analysis<'tcx> for MaybeUninitializedPlaces<'_, 'tcx> { } } -/// A dataflow analysis that tracks locals that are maybe uninitialized. -/// -/// This is a simpler analysis than `MaybeUninitializedPlaces`, because it does not track -/// individual fields. -pub struct MaybeUninitializedLocals; - -impl MaybeUninitializedLocals { - pub fn new() -> Self { - Self {} - } -} - -impl<'tcx> Analysis<'tcx> for MaybeUninitializedLocals { - type Domain = DenseBitSet; - - const NAME: &'static str = "maybe_uninit_locals"; - - fn bottom_value(&self, body: &Body<'tcx>) -> Self::Domain { - // bottom = all locals are initialized. - DenseBitSet::new_empty(body.local_decls.len()) - } - - fn initialize_start_block(&self, body: &Body<'tcx>, state: &mut Self::Domain) { - // All locals start as uninitialized... - state.insert_all(); - // ...except for arguments, which are definitely initialized. - for arg in body.args_iter() { - state.remove(arg); - } - } - - fn apply_primary_statement_effect( - &mut self, - state: &mut Self::Domain, - statement: &mir::Statement<'tcx>, - _location: Location, - ) { - match statement.kind { - // An assignment makes a local initialized. - mir::StatementKind::Assign(box (place, _)) => { - if let Some(local) = place.as_local() { - state.remove(local); - } - } - // Deinit makes the local uninitialized. - mir::StatementKind::Deinit(box place) => { - // A deinit makes a local uninitialized. - if let Some(local) = place.as_local() { - state.insert(local); - } - } - // Storage{Live,Dead} makes a local uninitialized. - mir::StatementKind::StorageLive(local) | mir::StatementKind::StorageDead(local) => { - state.insert(local); - } - _ => {} - } - } - - fn apply_call_return_effect( - &mut self, - state: &mut Self::Domain, - _block: mir::BasicBlock, - return_places: CallReturnPlaces<'_, 'tcx>, - ) { - // The return place of a call is initialized. - return_places.for_each(|place| { - if let Some(local) = place.as_local() { - state.remove(local); - } - }); - } -} - /// There can be many more `InitIndex` than there are locals in a MIR body. /// We use a mixed bitset to avoid paying too high a memory footprint. pub type EverInitializedPlacesDomain = MixedBitSet; diff --git a/compiler/rustc_mir_dataflow/src/impls/mod.rs b/compiler/rustc_mir_dataflow/src/impls/mod.rs index 695298529c19c..3f29b819a6d18 100644 --- a/compiler/rustc_mir_dataflow/src/impls/mod.rs +++ b/compiler/rustc_mir_dataflow/src/impls/mod.rs @@ -6,7 +6,7 @@ mod storage_liveness; pub use self::borrowed_locals::{MaybeBorrowedLocals, borrowed_locals}; pub use self::initialized::{ EverInitializedPlaces, EverInitializedPlacesDomain, MaybeInitializedPlaces, - MaybeUninitializedLocals, MaybeUninitializedPlaces, MaybeUninitializedPlacesDomain, + MaybeUninitializedPlaces, MaybeUninitializedPlacesDomain, }; pub use self::liveness::{ MaybeLiveLocals, MaybeTransitiveLiveLocals, TransferFunction as LivenessTransferFunction, diff --git a/compiler/rustc_mir_transform/src/copy_prop.rs b/compiler/rustc_mir_transform/src/copy_prop.rs index e114f0d80ef62..aaed97ce3d9a6 100644 --- a/compiler/rustc_mir_transform/src/copy_prop.rs +++ b/compiler/rustc_mir_transform/src/copy_prop.rs @@ -3,11 +3,10 @@ use rustc_index::bit_set::DenseBitSet; use rustc_middle::mir::visit::*; use rustc_middle::mir::*; use rustc_middle::ty::TyCtxt; -use rustc_mir_dataflow::impls::MaybeUninitializedLocals; use rustc_mir_dataflow::{Analysis, ResultsCursor}; use tracing::{debug, instrument}; -use crate::ssa::SsaLocals; +use crate::ssa::{MaybeUninitializedLocals, SsaLocals}; /// Unify locals that copy each other. /// @@ -37,10 +36,7 @@ impl<'tcx> crate::MirPass<'tcx> for CopyProp { debug!(copy_classes = ?ssa.copy_classes()); let mut any_replacement = false; - let fully_moved = fully_moved_locals(&ssa, body); - debug!(?fully_moved); - - let mut storage_to_remove = DenseBitSet::new_empty(fully_moved.domain_size()); + let mut storage_to_remove = DenseBitSet::new_empty(body.local_decls.len()); for (local, &head) in ssa.copy_classes().iter_enumerated() { if local != head { diff --git a/compiler/rustc_mir_transform/src/gvn.rs b/compiler/rustc_mir_transform/src/gvn.rs index 496a1a0acd9b7..f41b23f7ce2e8 100644 --- a/compiler/rustc_mir_transform/src/gvn.rs +++ b/compiler/rustc_mir_transform/src/gvn.rs @@ -104,14 +104,13 @@ use rustc_middle::mir::visit::*; use rustc_middle::mir::*; use rustc_middle::ty::layout::HasTypingEnv; use rustc_middle::ty::{self, Ty, TyCtxt}; -use rustc_mir_dataflow::impls::MaybeUninitializedLocals; use rustc_mir_dataflow::{Analysis, ResultsCursor}; use rustc_span::DUMMY_SP; use rustc_span::def_id::DefId; use smallvec::SmallVec; use tracing::{debug, instrument, trace}; -use crate::ssa::SsaLocals; +use crate::ssa::{MaybeUninitializedLocals, SsaLocals}; pub(super) struct GVN; diff --git a/compiler/rustc_mir_transform/src/ssa.rs b/compiler/rustc_mir_transform/src/ssa.rs index 03b6f9b7ff3b8..3a1b204460dbe 100644 --- a/compiler/rustc_mir_transform/src/ssa.rs +++ b/compiler/rustc_mir_transform/src/ssa.rs @@ -14,6 +14,7 @@ use rustc_middle::middle::resolve_bound_vars::Set1; use rustc_middle::mir::visit::*; use rustc_middle::mir::*; use rustc_middle::ty::{self, TyCtxt}; +use rustc_mir_dataflow::Analysis; use tracing::{debug, instrument, trace}; pub(super) struct SsaLocals { @@ -405,3 +406,77 @@ impl StorageLiveLocals { matches!(self.storage_live[local], Set1::One(_)) } } + +/// A dataflow analysis that tracks locals that are maybe uninitialized. +/// +/// This is a simpler analysis than `MaybeUninitializedPlaces`, because it does not track +/// individual fields. +pub(crate) struct MaybeUninitializedLocals; + +impl MaybeUninitializedLocals { + pub(crate) fn new() -> Self { + Self {} + } +} + +impl<'tcx> Analysis<'tcx> for MaybeUninitializedLocals { + type Domain = DenseBitSet; + + const NAME: &'static str = "maybe_uninit_locals"; + + fn bottom_value(&self, body: &Body<'tcx>) -> Self::Domain { + // bottom = all locals are initialized. + DenseBitSet::new_empty(body.local_decls.len()) + } + + fn initialize_start_block(&self, body: &Body<'tcx>, state: &mut Self::Domain) { + // All locals start as uninitialized... + state.insert_all(); + // ...except for arguments, which are definitely initialized. + for arg in body.args_iter() { + state.remove(arg); + } + } + + fn apply_primary_statement_effect( + &mut self, + state: &mut Self::Domain, + statement: &Statement<'tcx>, + _location: Location, + ) { + match statement.kind { + // An assignment makes a local initialized. + StatementKind::Assign(box (place, _)) => { + if let Some(local) = place.as_local() { + state.remove(local); + } + } + // Deinit makes the local uninitialized. + StatementKind::Deinit(box place) => { + // A deinit makes a local uninitialized. + if let Some(local) = place.as_local() { + state.insert(local); + } + } + // Storage{Live,Dead} makes a local uninitialized. + StatementKind::StorageLive(local) | StatementKind::StorageDead(local) => { + state.insert(local); + } + _ => {} + } + } + + fn apply_call_return_effect( + &mut self, + state: &mut Self::Domain, + _block: BasicBlock, + return_places: CallReturnPlaces<'_, 'tcx>, + ) { + // The return place of a call is initialized. + return_places.for_each(|place| { + if let Some(local) = place.as_local() { + state.remove(local); + } + }); + } +} From 67b6ae310e321e94c94029d4a60adca054ff4007 Mon Sep 17 00:00:00 2001 From: Ohad Ravid Date: Sun, 29 Jun 2025 09:12:20 +0300 Subject: [PATCH 08/14] Added FileCheck to copy prop storage tests --- .../copy_prop_storage_preserve_head.rs | 6 +- ...moved_when_local_borrowed.f.CopyProp.diff} | 0 ...op_storage_removed_when_local_borrowed.rs} | 13 +- .../copy-prop/copy_prop_storage_twice.rs | 15 +- .../copy_prop_storage_unreachable.rs | 10 +- ...issue_141649.f_head_borrowed.CopyProp.diff | 32 ++++ .../issue_141649.f_move.CopyProp.diff | 25 +++ ...ssue_141649.main.CopyProp.panic-abort.diff | 142 ------------------ ...sue_141649.main.CopyProp.panic-unwind.diff | 142 ------------------ tests/mir-opt/copy-prop/issue_141649.rs | 91 +++++++---- .../issue_141649_debug.f_move.CopyProp.diff | 25 +++ ...41649_debug.main.CopyProp.panic-abort.diff | 100 ------------ ...1649_debug.main.CopyProp.panic-unwind.diff | 100 ------------ tests/mir-opt/copy-prop/issue_141649_debug.rs | 59 +++++--- 14 files changed, 213 insertions(+), 547 deletions(-) rename tests/mir-opt/copy-prop/{copy_prop_borrowed_storage_not_removed.f.CopyProp.diff => copy_prop_storage_removed_when_local_borrowed.f.CopyProp.diff} (100%) rename tests/mir-opt/copy-prop/{copy_prop_borrowed_storage_not_removed.rs => copy_prop_storage_removed_when_local_borrowed.rs} (57%) create mode 100644 tests/mir-opt/copy-prop/issue_141649.f_head_borrowed.CopyProp.diff create mode 100644 tests/mir-opt/copy-prop/issue_141649.f_move.CopyProp.diff delete mode 100644 tests/mir-opt/copy-prop/issue_141649.main.CopyProp.panic-abort.diff delete mode 100644 tests/mir-opt/copy-prop/issue_141649.main.CopyProp.panic-unwind.diff create mode 100644 tests/mir-opt/copy-prop/issue_141649_debug.f_move.CopyProp.diff delete mode 100644 tests/mir-opt/copy-prop/issue_141649_debug.main.CopyProp.panic-abort.diff delete mode 100644 tests/mir-opt/copy-prop/issue_141649_debug.main.CopyProp.panic-unwind.diff diff --git a/tests/mir-opt/copy-prop/copy_prop_storage_preserve_head.rs b/tests/mir-opt/copy-prop/copy_prop_storage_preserve_head.rs index c66da3aecb022..7a0fa273bbec9 100644 --- a/tests/mir-opt/copy-prop/copy_prop_storage_preserve_head.rs +++ b/tests/mir-opt/copy-prop/copy_prop_storage_preserve_head.rs @@ -1,4 +1,3 @@ -// skip-filecheck //@ test-mir-pass: CopyProp //@ compile-flags: -Zlint-mir=false @@ -9,10 +8,15 @@ use std::intrinsics::mir::*; #[custom_mir(dialect = "runtime", phase = "post-cleanup")] pub fn f(_1: &mut usize) { + // CHECK-LABEL: fn f( mir! { let _2: usize; let _3: usize; + // CHECK: bb0: { { + // CHECK: StorageLive(_2); + // CHECK: (*_1) = copy _2; + // CHECK: StorageDead(_2); StorageLive(_2); _2 = 0; _3 = _2; diff --git a/tests/mir-opt/copy-prop/copy_prop_borrowed_storage_not_removed.f.CopyProp.diff b/tests/mir-opt/copy-prop/copy_prop_storage_removed_when_local_borrowed.f.CopyProp.diff similarity index 100% rename from tests/mir-opt/copy-prop/copy_prop_borrowed_storage_not_removed.f.CopyProp.diff rename to tests/mir-opt/copy-prop/copy_prop_storage_removed_when_local_borrowed.f.CopyProp.diff diff --git a/tests/mir-opt/copy-prop/copy_prop_borrowed_storage_not_removed.rs b/tests/mir-opt/copy-prop/copy_prop_storage_removed_when_local_borrowed.rs similarity index 57% rename from tests/mir-opt/copy-prop/copy_prop_borrowed_storage_not_removed.rs rename to tests/mir-opt/copy-prop/copy_prop_storage_removed_when_local_borrowed.rs index 39a3fda47a8e5..0aef621a24d34 100644 --- a/tests/mir-opt/copy-prop/copy_prop_borrowed_storage_not_removed.rs +++ b/tests/mir-opt/copy-prop/copy_prop_storage_removed_when_local_borrowed.rs @@ -1,23 +1,26 @@ -// skip-filecheck +//! Check that we remove the storage statements if one of the locals is borrowed, +//! and the head isn't borrowed. //@ test-mir-pass: CopyProp #![feature(custom_mir, core_intrinsics, freeze)] -// Check that we remove the storage statements if one of the locals is borrowed, -// and the head isn't borrowed. - use std::intrinsics::mir::*; use std::marker::Freeze; -// EMIT_MIR copy_prop_borrowed_storage_not_removed.f.CopyProp.diff +// EMIT_MIR copy_prop_storage_removed_when_local_borrowed.f.CopyProp.diff #[custom_mir(dialect = "runtime")] pub fn f(_1: (T, T)) -> T { + // CHECK-LABEL: fn f( mir! { let _2: T; let _3: T; let _4: &T; + // CHECK: bb0: { { + // CHECK-NOT: StorageLive(_2); + // CHECK: _4 = &_2; + // CHECK-NOT: StorageDead(_2); StorageLive(_2); _2 = _1.0; _3 = _2; diff --git a/tests/mir-opt/copy-prop/copy_prop_storage_twice.rs b/tests/mir-opt/copy-prop/copy_prop_storage_twice.rs index 421bb55d62ecc..4f9a561197526 100644 --- a/tests/mir-opt/copy-prop/copy_prop_storage_twice.rs +++ b/tests/mir-opt/copy-prop/copy_prop_storage_twice.rs @@ -1,4 +1,3 @@ -// skip-filecheck //@ test-mir-pass: CopyProp //@ compile-flags: -Zlint-mir=false @@ -10,45 +9,55 @@ use std::intrinsics::mir::*; // EMIT_MIR copy_prop_storage_twice.dead_twice.CopyProp.diff -// EMIT_MIR copy_prop_storage_twice.live_twice.CopyProp.diff - #[custom_mir(dialect = "runtime")] pub fn dead_twice(_1: T) -> T { + // CHECK-LABEL: fn dead_twice( mir! { let _2: T; let _3: T; { + // CHECK-NOT: StorageLive(_2); StorageLive(_2); Call(_2 = opaque(Move(_1)), ReturnTo(bb1), UnwindUnreachable()) } bb1 = { + // CHECK-NOT: StorageDead(_2); + // CHECK-NOT: StorageLive(_2); + // CHECK: _0 = opaque::(move _2) -> [return: bb2, unwind unreachable]; let _3 = Move(_2); StorageDead(_2); StorageLive(_2); Call(RET = opaque(Move(_3)), ReturnTo(bb2), UnwindUnreachable()) } bb2 = { + // CHECK-NOT: StorageDead(_2); StorageDead(_2); Return() } } } +// EMIT_MIR copy_prop_storage_twice.live_twice.CopyProp.diff #[custom_mir(dialect = "runtime")] pub fn live_twice(_1: T) -> T { + // CHECK-LABEL: fn live_twice( mir! { let _2: T; let _3: T; { + // CHECK-NOT: StorageLive(_2); StorageLive(_2); Call(_2 = opaque(Move(_1)), ReturnTo(bb1), UnwindUnreachable()) } bb1 = { + // CHECK-NOT: StorageLive(_2); + // CHECK: _0 = opaque::(copy _2) -> [return: bb2, unwind unreachable]; let _3 = Move(_2); StorageLive(_2); Call(RET = opaque(_3), ReturnTo(bb2), UnwindUnreachable()) } bb2 = { + // CHECK-NOT: StorageDead(_2); StorageDead(_2); Return() } diff --git a/tests/mir-opt/copy-prop/copy_prop_storage_unreachable.rs b/tests/mir-opt/copy-prop/copy_prop_storage_unreachable.rs index 65295acc8a226..2d28913ff8476 100644 --- a/tests/mir-opt/copy-prop/copy_prop_storage_unreachable.rs +++ b/tests/mir-opt/copy-prop/copy_prop_storage_unreachable.rs @@ -1,21 +1,23 @@ -// skip-filecheck +//! Check that we do not remove the storage statements if the head +//! is uninitialized in an unreachable block. //@ test-mir-pass: CopyProp #![feature(custom_mir, core_intrinsics)] -// Check that we do not remove the storage statements if the head -// is uninitialized in an unreachable block. - use std::intrinsics::mir::*; // EMIT_MIR copy_prop_storage_unreachable.f.CopyProp.diff #[custom_mir(dialect = "runtime", phase = "post-cleanup")] pub fn f(_1: &mut usize) { + // CHECK-LABEL: fn f( mir! { let _2: usize; let _3: usize; { + // CHECK: StorageLive(_2); + // CHECK: (*_1) = copy _2; + // CHECK: StorageDead(_2); StorageLive(_2); _2 = 42; _3 = _2; diff --git a/tests/mir-opt/copy-prop/issue_141649.f_head_borrowed.CopyProp.diff b/tests/mir-opt/copy-prop/issue_141649.f_head_borrowed.CopyProp.diff new file mode 100644 index 0000000000000..f8c23f28ff1a9 --- /dev/null +++ b/tests/mir-opt/copy-prop/issue_141649.f_head_borrowed.CopyProp.diff @@ -0,0 +1,32 @@ +- // MIR for `f_head_borrowed` before CopyProp ++ // MIR for `f_head_borrowed` after CopyProp + + fn f_head_borrowed() -> () { + let mut _0: (); + let mut _1: S; + let mut _2: S; + let mut _3: S; + let mut _4: &S; + let mut _5: &S; + + bb0: { + StorageLive(_1); + _1 = S(const 1_u32, const 2_u32); +- StorageLive(_2); + _4 = &_1; +- _2 = copy _1; +- _3 = opaque::(move _1) -> [return: bb1, unwind unreachable]; ++ _3 = opaque::(copy _1) -> [return: bb1, unwind unreachable]; + } + + bb1: { +- StorageDead(_2); + StorageDead(_1); + _5 = opaque::<&S>(move _4) -> [return: bb2, unwind unreachable]; + } + + bb2: { + return; + } + } + diff --git a/tests/mir-opt/copy-prop/issue_141649.f_move.CopyProp.diff b/tests/mir-opt/copy-prop/issue_141649.f_move.CopyProp.diff new file mode 100644 index 0000000000000..89af99210124a --- /dev/null +++ b/tests/mir-opt/copy-prop/issue_141649.f_move.CopyProp.diff @@ -0,0 +1,25 @@ +- // MIR for `f_move` before CopyProp ++ // MIR for `f_move` after CopyProp + + fn f_move() -> () { + let mut _0: (); + let mut _1: S; + let mut _2: S; + let mut _3: S; + + bb0: { + StorageLive(_1); + _1 = S(const 1_u32, const 2_u32); +- StorageLive(_2); +- _2 = copy _1; +- _3 = opaque::(move _1) -> [return: bb1, unwind unreachable]; ++ _3 = opaque::(copy _1) -> [return: bb1, unwind unreachable]; + } + + bb1: { +- StorageDead(_2); + StorageDead(_1); + return; + } + } + diff --git a/tests/mir-opt/copy-prop/issue_141649.main.CopyProp.panic-abort.diff b/tests/mir-opt/copy-prop/issue_141649.main.CopyProp.panic-abort.diff deleted file mode 100644 index c68bfb1b8e94a..0000000000000 --- a/tests/mir-opt/copy-prop/issue_141649.main.CopyProp.panic-abort.diff +++ /dev/null @@ -1,142 +0,0 @@ -- // MIR for `main` before CopyProp -+ // MIR for `main` after CopyProp - - fn main() -> () { - let mut _0: (); - let _1: (); - let _2: main::S; - let _3: (); - let mut _4: main::S; - let _5: (); - let _6: main::S; - let _7: (); - let mut _8: main::S; - let _9: (); - let _10: main::S; - let _12: &main::S; - let mut _13: &main::S; - let _14: (); - let mut _15: main::S; - let _16: (); - let _17: main::C; - let _18: (); - let mut _19: main::C; - let _20: main::C; - let _21: (); - let mut _22: main::C; - scope 1 { - debug s1 => _2; - } - scope 2 { - debug s2 => _6; - } - scope 3 { - debug s3 => _10; - let _11: &main::S; - scope 4 { - debug borrowed_s3 => _11; - } - } - scope 5 { - debug c1 => _17; - } - scope 6 { - debug c2 => _20; - } - - bb0: { -- StorageLive(_1); - StorageLive(_2); - _2 = S(const 1_usize, const 2_usize); - StorageLive(_3); -- StorageLive(_4); -- _4 = move _2; -- _3 = std::mem::drop::(move _4) -> [return: bb1, unwind unreachable]; -+ _3 = std::mem::drop::(move _2) -> [return: bb1, unwind unreachable]; - } - - bb1: { -- StorageDead(_4); - StorageDead(_3); -- _1 = const (); - StorageDead(_2); -- StorageDead(_1); -- StorageLive(_5); - StorageLive(_6); - _6 = S(const 3_usize, const 4_usize); - StorageLive(_7); -- StorageLive(_8); -- _8 = move _6; -- _7 = std::mem::drop::(move _8) -> [return: bb2, unwind unreachable]; -+ _7 = std::mem::drop::(move _6) -> [return: bb2, unwind unreachable]; - } - - bb2: { -- StorageDead(_8); - StorageDead(_7); -- _5 = const (); - StorageDead(_6); -- StorageDead(_5); -- StorageLive(_9); - StorageLive(_10); - _10 = S(const 5_usize, const 6_usize); - StorageLive(_11); - _11 = &_10; - StorageLive(_12); -- StorageLive(_13); -- _13 = copy _11; -- _12 = opaque::<&S>(move _13) -> [return: bb3, unwind unreachable]; -+ _12 = opaque::<&S>(copy _11) -> [return: bb3, unwind unreachable]; - } - - bb3: { -- StorageDead(_13); - StorageDead(_12); - StorageLive(_14); -- StorageLive(_15); -- _15 = move _10; -- _14 = std::mem::drop::(move _15) -> [return: bb4, unwind unreachable]; -+ _14 = std::mem::drop::(move _10) -> [return: bb4, unwind unreachable]; - } - - bb4: { -- StorageDead(_15); - StorageDead(_14); -- _9 = const (); - StorageDead(_11); - StorageDead(_10); -- StorageDead(_9); -- StorageLive(_16); - StorageLive(_17); - _17 = C(const 1_usize, const 2_usize); - StorageLive(_18); -- StorageLive(_19); -- _19 = copy _17; -- _18 = std::mem::drop::(move _19) -> [return: bb5, unwind unreachable]; -+ _18 = std::mem::drop::(copy _17) -> [return: bb5, unwind unreachable]; - } - - bb5: { -- StorageDead(_19); - StorageDead(_18); -- _16 = const (); - StorageDead(_17); -- StorageDead(_16); - StorageLive(_20); - _20 = C(const 3_usize, const 4_usize); - StorageLive(_21); -- StorageLive(_22); -- _22 = copy _20; -- _21 = std::mem::drop::(move _22) -> [return: bb6, unwind unreachable]; -+ _21 = std::mem::drop::(copy _20) -> [return: bb6, unwind unreachable]; - } - - bb6: { -- StorageDead(_22); - StorageDead(_21); - _0 = const (); - StorageDead(_20); - return; - } - } - diff --git a/tests/mir-opt/copy-prop/issue_141649.main.CopyProp.panic-unwind.diff b/tests/mir-opt/copy-prop/issue_141649.main.CopyProp.panic-unwind.diff deleted file mode 100644 index 3535a9840f685..0000000000000 --- a/tests/mir-opt/copy-prop/issue_141649.main.CopyProp.panic-unwind.diff +++ /dev/null @@ -1,142 +0,0 @@ -- // MIR for `main` before CopyProp -+ // MIR for `main` after CopyProp - - fn main() -> () { - let mut _0: (); - let _1: (); - let _2: main::S; - let _3: (); - let mut _4: main::S; - let _5: (); - let _6: main::S; - let _7: (); - let mut _8: main::S; - let _9: (); - let _10: main::S; - let _12: &main::S; - let mut _13: &main::S; - let _14: (); - let mut _15: main::S; - let _16: (); - let _17: main::C; - let _18: (); - let mut _19: main::C; - let _20: main::C; - let _21: (); - let mut _22: main::C; - scope 1 { - debug s1 => _2; - } - scope 2 { - debug s2 => _6; - } - scope 3 { - debug s3 => _10; - let _11: &main::S; - scope 4 { - debug borrowed_s3 => _11; - } - } - scope 5 { - debug c1 => _17; - } - scope 6 { - debug c2 => _20; - } - - bb0: { -- StorageLive(_1); - StorageLive(_2); - _2 = S(const 1_usize, const 2_usize); - StorageLive(_3); -- StorageLive(_4); -- _4 = move _2; -- _3 = std::mem::drop::(move _4) -> [return: bb1, unwind continue]; -+ _3 = std::mem::drop::(move _2) -> [return: bb1, unwind continue]; - } - - bb1: { -- StorageDead(_4); - StorageDead(_3); -- _1 = const (); - StorageDead(_2); -- StorageDead(_1); -- StorageLive(_5); - StorageLive(_6); - _6 = S(const 3_usize, const 4_usize); - StorageLive(_7); -- StorageLive(_8); -- _8 = move _6; -- _7 = std::mem::drop::(move _8) -> [return: bb2, unwind continue]; -+ _7 = std::mem::drop::(move _6) -> [return: bb2, unwind continue]; - } - - bb2: { -- StorageDead(_8); - StorageDead(_7); -- _5 = const (); - StorageDead(_6); -- StorageDead(_5); -- StorageLive(_9); - StorageLive(_10); - _10 = S(const 5_usize, const 6_usize); - StorageLive(_11); - _11 = &_10; - StorageLive(_12); -- StorageLive(_13); -- _13 = copy _11; -- _12 = opaque::<&S>(move _13) -> [return: bb3, unwind continue]; -+ _12 = opaque::<&S>(copy _11) -> [return: bb3, unwind continue]; - } - - bb3: { -- StorageDead(_13); - StorageDead(_12); - StorageLive(_14); -- StorageLive(_15); -- _15 = move _10; -- _14 = std::mem::drop::(move _15) -> [return: bb4, unwind continue]; -+ _14 = std::mem::drop::(move _10) -> [return: bb4, unwind continue]; - } - - bb4: { -- StorageDead(_15); - StorageDead(_14); -- _9 = const (); - StorageDead(_11); - StorageDead(_10); -- StorageDead(_9); -- StorageLive(_16); - StorageLive(_17); - _17 = C(const 1_usize, const 2_usize); - StorageLive(_18); -- StorageLive(_19); -- _19 = copy _17; -- _18 = std::mem::drop::(move _19) -> [return: bb5, unwind continue]; -+ _18 = std::mem::drop::(copy _17) -> [return: bb5, unwind continue]; - } - - bb5: { -- StorageDead(_19); - StorageDead(_18); -- _16 = const (); - StorageDead(_17); -- StorageDead(_16); - StorageLive(_20); - _20 = C(const 3_usize, const 4_usize); - StorageLive(_21); -- StorageLive(_22); -- _22 = copy _20; -- _21 = std::mem::drop::(move _22) -> [return: bb6, unwind continue]; -+ _21 = std::mem::drop::(copy _20) -> [return: bb6, unwind continue]; - } - - bb6: { -- StorageDead(_22); - StorageDead(_21); - _0 = const (); - StorageDead(_20); - return; - } - } - diff --git a/tests/mir-opt/copy-prop/issue_141649.rs b/tests/mir-opt/copy-prop/issue_141649.rs index e3b9062d65101..25884a9808db9 100644 --- a/tests/mir-opt/copy-prop/issue_141649.rs +++ b/tests/mir-opt/copy-prop/issue_141649.rs @@ -1,34 +1,71 @@ -// skip-filecheck -// EMIT_MIR_FOR_EACH_PANIC_STRATEGY +//! Check that we do not remove storage statements when the head is alive for all usages. //@ test-mir-pass: CopyProp +// EMIT_MIR issue_141649.f_move.CopyProp.diff +// EMIT_MIR issue_141649.f_head_borrowed.CopyProp.diff -// EMIT_MIR issue_141649.main.CopyProp.diff -fn main() { - struct S(usize, usize); - { - let s1 = S(1, 2); - drop(s1); - } - { - let s2 = S(3, 4); - drop(s2); - } - { - let s3 = S(5, 6); - let borrowed_s3 = &s3; - opaque(borrowed_s3); - drop(s3); - } +#![feature(custom_mir, core_intrinsics)] + +use std::intrinsics::mir::*; - #[derive(Clone, Copy)] - struct C(usize, usize); - { - let c1 = C(1, 2); - drop(c1); +struct S(u32, u32); + +#[custom_mir(dialect = "runtime")] +pub fn f_move() { + // CHECK-LABEL: fn f_move( + mir! { + let _1: S; + let _2: S; + let _3: S; + { + // CHECK: StorageLive(_1); + // CHECK-NOT: StorageLive(_2); + // CHECK: _3 = opaque::(copy _1) -> [return: bb1, unwind unreachable]; + StorageLive(_1); + _1 = S(1, 2); + StorageLive(_2); + _2 = _1; + Call(_3 = opaque(Move(_1)), ReturnTo(bb1), UnwindUnreachable()) + } + bb1 = { + // CHECK-NOT: StorageDead(_2); + // CHECK: StorageDead(_1); + StorageDead(_2); + StorageDead(_1); + Return() + } } - { - let c2 = C(3, 4); - drop(c2); +} + +#[custom_mir(dialect = "runtime")] +fn f_head_borrowed() { + // CHECK-LABEL: fn f_head_borrowed( + mir! { + let _1: S; + let _2: S; + let _3: S; + let _4: &S; + let _5: &S; + { + // CHECK: StorageLive(_1); + // CHECK-NOT: StorageLive(_2); + // CHECK: _3 = opaque::(copy _1) -> [return: bb1, unwind unreachable]; + StorageLive(_1); + _1 = S(1, 2); + StorageLive(_2); + _4 = &_1; + _2 = _1; + Call(_3 = opaque(Move(_1)), ReturnTo(bb1), UnwindUnreachable()) + } + bb1 = { + // CHECK-NOT: StorageDead(_2); + // CHECK: StorageDead(_1); + StorageDead(_2); + StorageDead(_1); + Call(_5 = opaque(Move(_4)), ReturnTo(bb2), UnwindUnreachable()) + } + bb2 = { + Return() + } } } diff --git a/tests/mir-opt/copy-prop/issue_141649_debug.f_move.CopyProp.diff b/tests/mir-opt/copy-prop/issue_141649_debug.f_move.CopyProp.diff new file mode 100644 index 0000000000000..5cb3753399d59 --- /dev/null +++ b/tests/mir-opt/copy-prop/issue_141649_debug.f_move.CopyProp.diff @@ -0,0 +1,25 @@ +- // MIR for `f_move` before CopyProp ++ // MIR for `f_move` after CopyProp + + fn f_move() -> () { + let mut _0: (); + let mut _1: S; + let mut _2: S; + let mut _3: S; + + bb0: { +- StorageLive(_1); + _1 = S(const 1_u32, const 2_u32); +- StorageLive(_2); +- _2 = copy _1; +- _3 = opaque::(move _1) -> [return: bb1, unwind unreachable]; ++ _3 = opaque::(copy _1) -> [return: bb1, unwind unreachable]; + } + + bb1: { +- StorageDead(_2); +- StorageDead(_1); + return; + } + } + diff --git a/tests/mir-opt/copy-prop/issue_141649_debug.main.CopyProp.panic-abort.diff b/tests/mir-opt/copy-prop/issue_141649_debug.main.CopyProp.panic-abort.diff deleted file mode 100644 index 93629b0f9f3f9..0000000000000 --- a/tests/mir-opt/copy-prop/issue_141649_debug.main.CopyProp.panic-abort.diff +++ /dev/null @@ -1,100 +0,0 @@ -- // MIR for `main` before CopyProp -+ // MIR for `main` after CopyProp - - fn main() -> () { - let mut _0: (); - let _1: (); - let _2: main::S; - let _3: (); - let mut _4: main::S; - let _5: (); - let _6: main::S; - let _7: (); - let mut _8: main::S; - let _9: (); - let _10: main::C; - let _11: (); - let mut _12: main::C; - let _13: main::C; - let _14: (); - let mut _15: main::C; - scope 1 { - debug s1 => _2; - } - scope 2 { - debug s2 => _6; - } - scope 3 { - debug c1 => _10; - } - scope 4 { - debug c2 => _13; - } - - bb0: { -- StorageLive(_1); -- StorageLive(_2); - _2 = S(const 1_usize, const 2_usize); - StorageLive(_3); -- StorageLive(_4); -- _4 = move _2; -- _3 = std::mem::drop::(move _4) -> [return: bb1, unwind unreachable]; -+ _3 = std::mem::drop::(move _2) -> [return: bb1, unwind unreachable]; - } - - bb1: { -- StorageDead(_4); - StorageDead(_3); -- _1 = const (); -- StorageDead(_2); -- StorageDead(_1); -- StorageLive(_5); -- StorageLive(_6); - _6 = S(const 3_usize, const 4_usize); - StorageLive(_7); -- StorageLive(_8); -- _8 = move _6; -- _7 = std::mem::drop::(move _8) -> [return: bb2, unwind unreachable]; -+ _7 = std::mem::drop::(move _6) -> [return: bb2, unwind unreachable]; - } - - bb2: { -- StorageDead(_8); - StorageDead(_7); -- _5 = const (); -- StorageDead(_6); -- StorageDead(_5); -- StorageLive(_9); -- StorageLive(_10); - _10 = C(const 1_usize, const 2_usize); - StorageLive(_11); -- StorageLive(_12); -- _12 = copy _10; -- _11 = std::mem::drop::(move _12) -> [return: bb3, unwind unreachable]; -+ _11 = std::mem::drop::(copy _10) -> [return: bb3, unwind unreachable]; - } - - bb3: { -- StorageDead(_12); - StorageDead(_11); -- _9 = const (); -- StorageDead(_10); -- StorageDead(_9); -- StorageLive(_13); - _13 = C(const 3_usize, const 4_usize); - StorageLive(_14); -- StorageLive(_15); -- _15 = copy _13; -- _14 = std::mem::drop::(move _15) -> [return: bb4, unwind unreachable]; -+ _14 = std::mem::drop::(copy _13) -> [return: bb4, unwind unreachable]; - } - - bb4: { -- StorageDead(_15); - StorageDead(_14); - _0 = const (); -- StorageDead(_13); - return; - } - } - diff --git a/tests/mir-opt/copy-prop/issue_141649_debug.main.CopyProp.panic-unwind.diff b/tests/mir-opt/copy-prop/issue_141649_debug.main.CopyProp.panic-unwind.diff deleted file mode 100644 index e02fe72a47a7b..0000000000000 --- a/tests/mir-opt/copy-prop/issue_141649_debug.main.CopyProp.panic-unwind.diff +++ /dev/null @@ -1,100 +0,0 @@ -- // MIR for `main` before CopyProp -+ // MIR for `main` after CopyProp - - fn main() -> () { - let mut _0: (); - let _1: (); - let _2: main::S; - let _3: (); - let mut _4: main::S; - let _5: (); - let _6: main::S; - let _7: (); - let mut _8: main::S; - let _9: (); - let _10: main::C; - let _11: (); - let mut _12: main::C; - let _13: main::C; - let _14: (); - let mut _15: main::C; - scope 1 { - debug s1 => _2; - } - scope 2 { - debug s2 => _6; - } - scope 3 { - debug c1 => _10; - } - scope 4 { - debug c2 => _13; - } - - bb0: { -- StorageLive(_1); -- StorageLive(_2); - _2 = S(const 1_usize, const 2_usize); - StorageLive(_3); -- StorageLive(_4); -- _4 = move _2; -- _3 = std::mem::drop::(move _4) -> [return: bb1, unwind continue]; -+ _3 = std::mem::drop::(move _2) -> [return: bb1, unwind continue]; - } - - bb1: { -- StorageDead(_4); - StorageDead(_3); -- _1 = const (); -- StorageDead(_2); -- StorageDead(_1); -- StorageLive(_5); -- StorageLive(_6); - _6 = S(const 3_usize, const 4_usize); - StorageLive(_7); -- StorageLive(_8); -- _8 = move _6; -- _7 = std::mem::drop::(move _8) -> [return: bb2, unwind continue]; -+ _7 = std::mem::drop::(move _6) -> [return: bb2, unwind continue]; - } - - bb2: { -- StorageDead(_8); - StorageDead(_7); -- _5 = const (); -- StorageDead(_6); -- StorageDead(_5); -- StorageLive(_9); -- StorageLive(_10); - _10 = C(const 1_usize, const 2_usize); - StorageLive(_11); -- StorageLive(_12); -- _12 = copy _10; -- _11 = std::mem::drop::(move _12) -> [return: bb3, unwind continue]; -+ _11 = std::mem::drop::(copy _10) -> [return: bb3, unwind continue]; - } - - bb3: { -- StorageDead(_12); - StorageDead(_11); -- _9 = const (); -- StorageDead(_10); -- StorageDead(_9); -- StorageLive(_13); - _13 = C(const 3_usize, const 4_usize); - StorageLive(_14); -- StorageLive(_15); -- _15 = copy _13; -- _14 = std::mem::drop::(move _15) -> [return: bb4, unwind continue]; -+ _14 = std::mem::drop::(copy _13) -> [return: bb4, unwind continue]; - } - - bb4: { -- StorageDead(_15); - StorageDead(_14); - _0 = const (); -- StorageDead(_13); - return; - } - } - diff --git a/tests/mir-opt/copy-prop/issue_141649_debug.rs b/tests/mir-opt/copy-prop/issue_141649_debug.rs index 5769118700ca1..554228000b670 100644 --- a/tests/mir-opt/copy-prop/issue_141649_debug.rs +++ b/tests/mir-opt/copy-prop/issue_141649_debug.rs @@ -1,29 +1,42 @@ -// skip-filecheck -// EMIT_MIR_FOR_EACH_PANIC_STRATEGY -//! Tests that in lower opt levels we remove (more) storage statements using a simpler strategy. +//! In lower opt levels, we remove (more) storage statements using a simpler strategy. //@ test-mir-pass: CopyProp //@ compile-flags: -Copt-level=0 +// EMIT_MIR issue_141649_debug.f_move.CopyProp.diff -// EMIT_MIR issue_141649_debug.main.CopyProp.diff -fn main() { - struct S(usize, usize); - { - let s1 = S(1, 2); - drop(s1); - } - { - let s2 = S(3, 4); - drop(s2); - } +#![feature(custom_mir, core_intrinsics)] - #[derive(Clone, Copy)] - struct C(usize, usize); - { - let c1 = C(1, 2); - drop(c1); - } - { - let c2 = C(3, 4); - drop(c2); +use std::intrinsics::mir::*; + +struct S(u32, u32); + +#[custom_mir(dialect = "runtime")] +pub fn f_move() { + // CHECK-LABEL: fn f_move( + mir! { + let _1: S; + let _2: S; + let _3: S; + { + // CHECK-NOT: StorageLive(_1); + // CHECK-NOT: StorageLive(_2); + // CHECK: _3 = opaque::(copy _1) -> [return: bb1, unwind unreachable]; + StorageLive(_1); + _1 = S(1, 2); + StorageLive(_2); + _2 = _1; + Call(_3 = opaque(Move(_1)), ReturnTo(bb1), UnwindUnreachable()) + } + bb1 = { + // CHECK-NOT: StorageDead(_2); + // CHECK-NOT: StorageDead(_1); + StorageDead(_2); + StorageDead(_1); + Return() + } } } + +#[inline(never)] +fn opaque(a: T) -> T { + a +} From e69bef8a22d30866676f11fea5233a4be0bef997 Mon Sep 17 00:00:00 2001 From: Ohad Ravid Date: Sun, 29 Jun 2025 10:32:54 +0300 Subject: [PATCH 09/14] Simplify GVN storage checker to use a single bitset --- compiler/rustc_mir_transform/src/gvn.rs | 26 ++++++++++++------------- 1 file changed, 12 insertions(+), 14 deletions(-) diff --git a/compiler/rustc_mir_transform/src/gvn.rs b/compiler/rustc_mir_transform/src/gvn.rs index f41b23f7ce2e8..5304103e56359 100644 --- a/compiler/rustc_mir_transform/src/gvn.rs +++ b/compiler/rustc_mir_transform/src/gvn.rs @@ -149,7 +149,7 @@ impl<'tcx> crate::MirPass<'tcx> for GVN { .into_results_cursor(body); let mut storage_checker = StorageChecker { - storage_to_check: state.reused_locals.clone(), + reused_locals: &state.reused_locals, storage_to_remove: DenseBitSet::new_empty(body.local_decls.len()), maybe_uninit, }; @@ -1877,7 +1877,7 @@ impl<'tcx> MutVisitor<'tcx> for StorageRemover<'tcx> { } struct StorageChecker<'a, 'tcx> { - storage_to_check: DenseBitSet, + reused_locals: &'a DenseBitSet, storage_to_remove: DenseBitSet, maybe_uninit: ResultsCursor<'a, 'tcx, MaybeUninitializedLocals>, } @@ -1897,18 +1897,16 @@ impl<'a, 'tcx> Visitor<'tcx> for StorageChecker<'a, 'tcx> { PlaceContext::MutatingUse(_) | PlaceContext::NonMutatingUse(_) => {} } - if self.storage_to_check.contains(local) { - self.maybe_uninit.seek_before_primary_effect(location); - - if self.maybe_uninit.get().contains(local) { - debug!( - ?location, - ?local, - "local is maybe uninit in this location, removing storage" - ); - self.storage_to_remove.insert(local); - self.storage_to_check.remove(local); - } + // We only need to check reused locals which we haven't already removed storage for. + if !self.reused_locals.contains(local) || self.storage_to_remove.contains(local) { + return; + } + + self.maybe_uninit.seek_before_primary_effect(location); + + if self.maybe_uninit.get().contains(local) { + debug!(?location, ?local, "local is maybe uninit in this location, removing storage"); + self.storage_to_remove.insert(local); } } } From d59f79f87aa839d794ec1999326780eb4977f015 Mon Sep 17 00:00:00 2001 From: Ohad Ravid Date: Sun, 29 Jun 2025 11:13:35 +0300 Subject: [PATCH 10/14] Improve GVN storage tests --- .../gvn_storage_issue_141649.f.GVN.diff | 20 +++ tests/mir-opt/gvn_storage_issue_141649.rs | 32 +++++ .../gvn_storage_issue_141649_debug.f.GVN.diff | 22 ++++ .../mir-opt/gvn_storage_issue_141649_debug.rs | 31 +++++ tests/mir-opt/gvn_storage_twice.rs | 7 +- ...n_storage_remove.main.GVN.panic-abort.diff | 124 ------------------ ..._storage_remove.main.GVN.panic-unwind.diff | 124 ------------------ .../issue_141649_gvn_storage_remove.rs | 27 ---- 8 files changed, 111 insertions(+), 276 deletions(-) create mode 100644 tests/mir-opt/gvn_storage_issue_141649.f.GVN.diff create mode 100644 tests/mir-opt/gvn_storage_issue_141649.rs create mode 100644 tests/mir-opt/gvn_storage_issue_141649_debug.f.GVN.diff create mode 100644 tests/mir-opt/gvn_storage_issue_141649_debug.rs delete mode 100644 tests/mir-opt/issue_141649_gvn_storage_remove.main.GVN.panic-abort.diff delete mode 100644 tests/mir-opt/issue_141649_gvn_storage_remove.main.GVN.panic-unwind.diff delete mode 100644 tests/mir-opt/issue_141649_gvn_storage_remove.rs diff --git a/tests/mir-opt/gvn_storage_issue_141649.f.GVN.diff b/tests/mir-opt/gvn_storage_issue_141649.f.GVN.diff new file mode 100644 index 0000000000000..664839e792456 --- /dev/null +++ b/tests/mir-opt/gvn_storage_issue_141649.f.GVN.diff @@ -0,0 +1,20 @@ +- // MIR for `f` before GVN ++ // MIR for `f` after GVN + + fn f(_1: u32) -> () { + let mut _0: (); + let mut _2: S; + let mut _3: S; + + bb0: { + StorageLive(_2); + _2 = S(copy _1, const 2_u32); + StorageLive(_3); +- _3 = S(copy _1, const 2_u32); ++ _3 = copy _2; + StorageDead(_3); + StorageDead(_2); + return; + } + } + diff --git a/tests/mir-opt/gvn_storage_issue_141649.rs b/tests/mir-opt/gvn_storage_issue_141649.rs new file mode 100644 index 0000000000000..70323da03dea4 --- /dev/null +++ b/tests/mir-opt/gvn_storage_issue_141649.rs @@ -0,0 +1,32 @@ +//! Check that we do not remove storage statements when possible. +//@ test-mir-pass: GVN +// EMIT_MIR gvn_storage_issue_141649.f.GVN.diff + +#![feature(custom_mir, core_intrinsics)] + +use std::intrinsics::mir::*; + +struct S(u32, u32); + +#[custom_mir(dialect = "runtime")] +pub fn f(_1: u32) { + // CHECK-LABEL: fn f( + mir! { + let _2: S; + let _3: S; + { + // CHECK: StorageLive(_2); + // CHECK: StorageLive(_3); + // CHECK: _3 = copy _2; + // CHECK: StorageDead(_3); + // CHECK: StorageDead(_2); + StorageLive(_2); + _2 = S(_1, 2); + StorageLive(_3); + _3 = S(_1, 2); + StorageDead(_3); + StorageDead(_2); + Return() + } + } +} diff --git a/tests/mir-opt/gvn_storage_issue_141649_debug.f.GVN.diff b/tests/mir-opt/gvn_storage_issue_141649_debug.f.GVN.diff new file mode 100644 index 0000000000000..ee43324b2fe89 --- /dev/null +++ b/tests/mir-opt/gvn_storage_issue_141649_debug.f.GVN.diff @@ -0,0 +1,22 @@ +- // MIR for `f` before GVN ++ // MIR for `f` after GVN + + fn f(_1: u32) -> () { + let mut _0: (); + let mut _2: S; + let mut _3: S; + + bb0: { +- StorageLive(_2); ++ nop; + _2 = S(copy _1, const 2_u32); + StorageLive(_3); +- _3 = S(copy _1, const 2_u32); ++ _3 = copy _2; + StorageDead(_3); +- StorageDead(_2); ++ nop; + return; + } + } + diff --git a/tests/mir-opt/gvn_storage_issue_141649_debug.rs b/tests/mir-opt/gvn_storage_issue_141649_debug.rs new file mode 100644 index 0000000000000..2c397f58fe934 --- /dev/null +++ b/tests/mir-opt/gvn_storage_issue_141649_debug.rs @@ -0,0 +1,31 @@ +//! In lower opt levels, we remove any storage statements of reused locals. +//@ test-mir-pass: GVN +//@ compile-flags: -Copt-level=0 +// EMIT_MIR gvn_storage_issue_141649_debug.f.GVN.diff + +#![feature(custom_mir, core_intrinsics)] + +use std::intrinsics::mir::*; + +struct S(u32, u32); + +#[custom_mir(dialect = "runtime")] +pub fn f(_1: u32) { + // CHECK-LABEL: fn f( + mir! { + let _2: S; + let _3: S; + { + // CHECK-NOT: StorageLive(_2); + // CHECK: _3 = copy _2; + // CHECK-NOT: StorageDead(_2); + StorageLive(_2); + _2 = S(_1, 2); + StorageLive(_3); + _3 = S(_1, 2); + StorageDead(_3); + StorageDead(_2); + Return() + } + } +} diff --git a/tests/mir-opt/gvn_storage_twice.rs b/tests/mir-opt/gvn_storage_twice.rs index d6aa0ed87befe..624d8ef4efa8d 100644 --- a/tests/mir-opt/gvn_storage_twice.rs +++ b/tests/mir-opt/gvn_storage_twice.rs @@ -1,4 +1,3 @@ -// skip-filecheck //@ test-mir-pass: GVN //@ compile-flags: -Zlint-mir=false @@ -18,10 +17,12 @@ use std::intrinsics::mir::*; #[custom_mir(dialect = "runtime")] pub fn repeat_local(_1: usize, _2: usize, _3: i32) -> i32 { + // CHECK-LABEL: fn repeat_local( mir! { { let _4 = [_3; 5]; let _5 = &_4[_1]; + // CHECK: _0 = copy _3; RET = *_5; Return() } @@ -32,11 +33,13 @@ pub fn repeat_local(_1: usize, _2: usize, _3: i32) -> i32 { #[custom_mir(dialect = "runtime")] pub fn repeat_local_dead(_1: usize, _2: usize, _3: i32) -> i32 { + // CHECK-LABEL: fn repeat_local_dead( mir! { { let _4 = [_3; 5]; let _5 = &_4[_1]; StorageDead(_3); + // CHECK: _0 = copy _3; RET = *_5; Return() } @@ -47,12 +50,14 @@ pub fn repeat_local_dead(_1: usize, _2: usize, _3: i32) -> i32 { #[custom_mir(dialect = "runtime")] pub fn repeat_local_dead_live(_1: usize, _2: usize, _3: i32) -> i32 { + // CHECK-LABEL: fn repeat_local_dead_live( mir! { { let _4 = [_3; 5]; let _5 = &_4[_1]; StorageDead(_3); StorageLive(_3); + // CHECK: _0 = copy _3; RET = *_5; Return() } diff --git a/tests/mir-opt/issue_141649_gvn_storage_remove.main.GVN.panic-abort.diff b/tests/mir-opt/issue_141649_gvn_storage_remove.main.GVN.panic-abort.diff deleted file mode 100644 index 79230f8e354a5..0000000000000 --- a/tests/mir-opt/issue_141649_gvn_storage_remove.main.GVN.panic-abort.diff +++ /dev/null @@ -1,124 +0,0 @@ -- // MIR for `main` before GVN -+ // MIR for `main` after GVN - - fn main() -> () { - let mut _0: (); - let _1: (); - let _2: main::S; - let _3: (); - let mut _4: main::S; - let _5: (); - let _6: main::S; - let _7: (); - let mut _8: main::S; - let _9: (); - let _10: main::C; - let _11: (); - let mut _12: main::C; - let _13: main::C; - let _14: (); - let mut _15: main::C; - scope 1 { - debug s1 => _2; - } - scope 2 { - debug s2 => _6; - } - scope 3 { - debug c1 => _10; - } - scope 4 { - debug c2 => _13; - } - - bb0: { - StorageLive(_1); - StorageLive(_2); -- _2 = S(const 1_u32, const 2_u32); -+ _2 = const S(1_u32, 2_u32); - StorageLive(_3); - StorageLive(_4); -- _4 = move _2; -- _3 = std::mem::drop::(move _4) -> [return: bb1, unwind unreachable]; -+ _4 = const S(1_u32, 2_u32); -+ _3 = std::mem::drop::(const S(1_u32, 2_u32)) -> [return: bb1, unwind unreachable]; - } - - bb1: { - StorageDead(_4); - StorageDead(_3); - _1 = const (); - StorageDead(_2); - StorageDead(_1); - StorageLive(_5); - StorageLive(_6); -- _6 = S(const 3_u32, const 4_u32); -+ _6 = const S(3_u32, 4_u32); - StorageLive(_7); - StorageLive(_8); -- _8 = move _6; -- _7 = std::mem::drop::(move _8) -> [return: bb2, unwind unreachable]; -+ _8 = const S(3_u32, 4_u32); -+ _7 = std::mem::drop::(const S(3_u32, 4_u32)) -> [return: bb2, unwind unreachable]; - } - - bb2: { - StorageDead(_8); - StorageDead(_7); - _5 = const (); - StorageDead(_6); - StorageDead(_5); - StorageLive(_9); - StorageLive(_10); -- _10 = C(const 1_u32, const 2_u32); -+ _10 = const C(1_u32, 2_u32); - StorageLive(_11); - StorageLive(_12); -- _12 = copy _10; -- _11 = std::mem::drop::(move _12) -> [return: bb3, unwind unreachable]; -+ _12 = const C(1_u32, 2_u32); -+ _11 = std::mem::drop::(const C(1_u32, 2_u32)) -> [return: bb3, unwind unreachable]; - } - - bb3: { - StorageDead(_12); - StorageDead(_11); - _9 = const (); - StorageDead(_10); - StorageDead(_9); - StorageLive(_13); -- _13 = C(const 3_u32, const 4_u32); -+ _13 = const C(3_u32, 4_u32); - StorageLive(_14); - StorageLive(_15); -- _15 = copy _13; -- _14 = std::mem::drop::(move _15) -> [return: bb4, unwind unreachable]; -+ _15 = const C(3_u32, 4_u32); -+ _14 = std::mem::drop::(const C(3_u32, 4_u32)) -> [return: bb4, unwind unreachable]; - } - - bb4: { - StorageDead(_15); - StorageDead(_14); - _0 = const (); - StorageDead(_13); - return; - } -+ } -+ -+ ALLOC0 (size: 8, align: 4) { -+ 03 00 00 00 04 00 00 00 │ ........ -+ } -+ -+ ALLOC1 (size: 8, align: 4) { -+ 01 00 00 00 02 00 00 00 │ ........ -+ } -+ -+ ALLOC2 (size: 8, align: 4) { -+ 03 00 00 00 04 00 00 00 │ ........ -+ } -+ -+ ALLOC3 (size: 8, align: 4) { -+ 01 00 00 00 02 00 00 00 │ ........ - } - diff --git a/tests/mir-opt/issue_141649_gvn_storage_remove.main.GVN.panic-unwind.diff b/tests/mir-opt/issue_141649_gvn_storage_remove.main.GVN.panic-unwind.diff deleted file mode 100644 index a9c68d742f504..0000000000000 --- a/tests/mir-opt/issue_141649_gvn_storage_remove.main.GVN.panic-unwind.diff +++ /dev/null @@ -1,124 +0,0 @@ -- // MIR for `main` before GVN -+ // MIR for `main` after GVN - - fn main() -> () { - let mut _0: (); - let _1: (); - let _2: main::S; - let _3: (); - let mut _4: main::S; - let _5: (); - let _6: main::S; - let _7: (); - let mut _8: main::S; - let _9: (); - let _10: main::C; - let _11: (); - let mut _12: main::C; - let _13: main::C; - let _14: (); - let mut _15: main::C; - scope 1 { - debug s1 => _2; - } - scope 2 { - debug s2 => _6; - } - scope 3 { - debug c1 => _10; - } - scope 4 { - debug c2 => _13; - } - - bb0: { - StorageLive(_1); - StorageLive(_2); -- _2 = S(const 1_u32, const 2_u32); -+ _2 = const S(1_u32, 2_u32); - StorageLive(_3); - StorageLive(_4); -- _4 = move _2; -- _3 = std::mem::drop::(move _4) -> [return: bb1, unwind continue]; -+ _4 = const S(1_u32, 2_u32); -+ _3 = std::mem::drop::(const S(1_u32, 2_u32)) -> [return: bb1, unwind continue]; - } - - bb1: { - StorageDead(_4); - StorageDead(_3); - _1 = const (); - StorageDead(_2); - StorageDead(_1); - StorageLive(_5); - StorageLive(_6); -- _6 = S(const 3_u32, const 4_u32); -+ _6 = const S(3_u32, 4_u32); - StorageLive(_7); - StorageLive(_8); -- _8 = move _6; -- _7 = std::mem::drop::(move _8) -> [return: bb2, unwind continue]; -+ _8 = const S(3_u32, 4_u32); -+ _7 = std::mem::drop::(const S(3_u32, 4_u32)) -> [return: bb2, unwind continue]; - } - - bb2: { - StorageDead(_8); - StorageDead(_7); - _5 = const (); - StorageDead(_6); - StorageDead(_5); - StorageLive(_9); - StorageLive(_10); -- _10 = C(const 1_u32, const 2_u32); -+ _10 = const C(1_u32, 2_u32); - StorageLive(_11); - StorageLive(_12); -- _12 = copy _10; -- _11 = std::mem::drop::(move _12) -> [return: bb3, unwind continue]; -+ _12 = const C(1_u32, 2_u32); -+ _11 = std::mem::drop::(const C(1_u32, 2_u32)) -> [return: bb3, unwind continue]; - } - - bb3: { - StorageDead(_12); - StorageDead(_11); - _9 = const (); - StorageDead(_10); - StorageDead(_9); - StorageLive(_13); -- _13 = C(const 3_u32, const 4_u32); -+ _13 = const C(3_u32, 4_u32); - StorageLive(_14); - StorageLive(_15); -- _15 = copy _13; -- _14 = std::mem::drop::(move _15) -> [return: bb4, unwind continue]; -+ _15 = const C(3_u32, 4_u32); -+ _14 = std::mem::drop::(const C(3_u32, 4_u32)) -> [return: bb4, unwind continue]; - } - - bb4: { - StorageDead(_15); - StorageDead(_14); - _0 = const (); - StorageDead(_13); - return; - } -+ } -+ -+ ALLOC0 (size: 8, align: 4) { -+ 03 00 00 00 04 00 00 00 │ ........ -+ } -+ -+ ALLOC1 (size: 8, align: 4) { -+ 01 00 00 00 02 00 00 00 │ ........ -+ } -+ -+ ALLOC2 (size: 8, align: 4) { -+ 03 00 00 00 04 00 00 00 │ ........ -+ } -+ -+ ALLOC3 (size: 8, align: 4) { -+ 01 00 00 00 02 00 00 00 │ ........ - } - diff --git a/tests/mir-opt/issue_141649_gvn_storage_remove.rs b/tests/mir-opt/issue_141649_gvn_storage_remove.rs deleted file mode 100644 index eb2b5337d0c41..0000000000000 --- a/tests/mir-opt/issue_141649_gvn_storage_remove.rs +++ /dev/null @@ -1,27 +0,0 @@ -// skip-filecheck -// EMIT_MIR_FOR_EACH_PANIC_STRATEGY -//@ test-mir-pass: GVN - -// EMIT_MIR issue_141649_gvn_storage_remove.main.GVN.diff -fn main() { - struct S(u32, u32); - { - let s1 = S(1, 2); - drop(s1); - } - { - let s2 = S(3, 4); - drop(s2); - } - - #[derive(Clone, Copy)] - struct C(u32, u32); - { - let c1 = C(1, 2); - drop(c1); - } - { - let c2 = C(3, 4); - drop(c2); - } -} From 228ad1e555e5ccb6446956d0b00ac31c4a381035 Mon Sep 17 00:00:00 2001 From: Ohad Ravid Date: Sun, 29 Jun 2025 11:23:35 +0300 Subject: [PATCH 11/14] GVN unnit analysis shouldn't check unreachable blocks --- compiler/rustc_mir_transform/src/gvn.rs | 4 +- .../gvn_storage_unreachable.f.GVN.diff | 28 +++++++++++++ tests/mir-opt/gvn_storage_unreachable.rs | 41 +++++++++++++++++++ 3 files changed, 72 insertions(+), 1 deletion(-) create mode 100644 tests/mir-opt/gvn_storage_unreachable.f.GVN.diff create mode 100644 tests/mir-opt/gvn_storage_unreachable.rs diff --git a/compiler/rustc_mir_transform/src/gvn.rs b/compiler/rustc_mir_transform/src/gvn.rs index 5304103e56359..2b105eb1dbc7b 100644 --- a/compiler/rustc_mir_transform/src/gvn.rs +++ b/compiler/rustc_mir_transform/src/gvn.rs @@ -154,7 +154,9 @@ impl<'tcx> crate::MirPass<'tcx> for GVN { maybe_uninit, }; - storage_checker.visit_body(body); + for (bb, data) in traversal::reachable(body) { + storage_checker.visit_basic_block_data(bb, data); + } storage_checker.storage_to_remove } else { diff --git a/tests/mir-opt/gvn_storage_unreachable.f.GVN.diff b/tests/mir-opt/gvn_storage_unreachable.f.GVN.diff new file mode 100644 index 0000000000000..e29cbe0e2b00d --- /dev/null +++ b/tests/mir-opt/gvn_storage_unreachable.f.GVN.diff @@ -0,0 +1,28 @@ +- // MIR for `f` before GVN ++ // MIR for `f` after GVN + + fn f(_1: u32) -> () { + let mut _0: (); + let mut _2: S; + let mut _3: S; + let mut _4: S; + + bb0: { + StorageLive(_2); + _2 = S(copy _1, const 2_u32); + StorageLive(_3); +- _3 = S(copy _1, const 2_u32); ++ _3 = copy _2; + StorageDead(_3); + StorageDead(_2); + return; + } + + bb1: { + StorageLive(_2); + _4 = copy _2; + StorageDead(_2); + return; + } + } + diff --git a/tests/mir-opt/gvn_storage_unreachable.rs b/tests/mir-opt/gvn_storage_unreachable.rs new file mode 100644 index 0000000000000..20e362d1a71de --- /dev/null +++ b/tests/mir-opt/gvn_storage_unreachable.rs @@ -0,0 +1,41 @@ +//! Check that we do not remove the storage statements if a reused local +//! is uninitialized in an unreachable block. +//@ test-mir-pass: GVN +// EMIT_MIR gvn_storage_unreachable.f.GVN.diff + +#![feature(custom_mir, core_intrinsics)] + +use std::intrinsics::mir::*; + +struct S(u32, u32); + +#[custom_mir(dialect = "runtime", phase = "post-cleanup")] +pub fn f(_1: u32) { + // CHECK-LABEL: fn f( + mir! { + let _2: S; + let _3: S; + let _4: S; + { + // CHECK: StorageLive(_2); + // CHECK: StorageLive(_3); + // CHECK: _3 = copy _2; + // CHECK: StorageDead(_3); + // CHECK: StorageDead(_2); + StorageLive(_2); + _2 = S(_1, 2); + StorageLive(_3); + _3 = S(_1, 2); + StorageDead(_3); + StorageDead(_2); + Return() + } + bb1 = { + StorageLive(_2); + // CHECK: _4 = copy _2; + _4 = _2; + StorageDead(_2); + Return() + } + } +} From 3a2a0991ed471a4bf1cbaa815a6f202e5f6c41ec Mon Sep 17 00:00:00 2001 From: Ohad Ravid Date: Sun, 29 Jun 2025 11:25:29 +0300 Subject: [PATCH 12/14] Add more FileCheck statements in gvn storage tests --- tests/mir-opt/gvn_storage_twice.rs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/tests/mir-opt/gvn_storage_twice.rs b/tests/mir-opt/gvn_storage_twice.rs index 624d8ef4efa8d..ca040f7efd5d7 100644 --- a/tests/mir-opt/gvn_storage_twice.rs +++ b/tests/mir-opt/gvn_storage_twice.rs @@ -38,6 +38,7 @@ pub fn repeat_local_dead(_1: usize, _2: usize, _3: i32) -> i32 { { let _4 = [_3; 5]; let _5 = &_4[_1]; + // CHECK-NOT: StorageDead(_3); StorageDead(_3); // CHECK: _0 = copy _3; RET = *_5; @@ -55,6 +56,8 @@ pub fn repeat_local_dead_live(_1: usize, _2: usize, _3: i32) -> i32 { { let _4 = [_3; 5]; let _5 = &_4[_1]; + // CHECK-NOT: StorageLive(_3); + // CHECK-NOT: StorageDead(_3); StorageDead(_3); StorageLive(_3); // CHECK: _0 = copy _3; From 7c6b388c78aa94cd8aaa817e58640938173e3448 Mon Sep 17 00:00:00 2001 From: Ohad Ravid Date: Sun, 29 Jun 2025 11:31:33 +0300 Subject: [PATCH 13/14] Added a GVN storage test for borrowed value --- ...n_storage_issue_141649.f_borrowed.GVN.diff | 25 +++++++++++++++++ tests/mir-opt/gvn_storage_issue_141649.rs | 27 +++++++++++++++++++ 2 files changed, 52 insertions(+) create mode 100644 tests/mir-opt/gvn_storage_issue_141649.f_borrowed.GVN.diff diff --git a/tests/mir-opt/gvn_storage_issue_141649.f_borrowed.GVN.diff b/tests/mir-opt/gvn_storage_issue_141649.f_borrowed.GVN.diff new file mode 100644 index 0000000000000..4e9d355be6083 --- /dev/null +++ b/tests/mir-opt/gvn_storage_issue_141649.f_borrowed.GVN.diff @@ -0,0 +1,25 @@ +- // MIR for `f_borrowed` before GVN ++ // MIR for `f_borrowed` after GVN + + fn f_borrowed(_1: u32) -> () { + let mut _0: (); + let mut _2: S; + let mut _3: S; + let mut _4: &S; + let mut _5: S; + + bb0: { +- StorageLive(_2); ++ nop; + _2 = S(copy _1, const 2_u32); +- _3 = S(copy _1, const 2_u32); ++ _3 = copy _2; + _4 = &_3; +- StorageDead(_2); +- _5 = copy (*_4); ++ nop; ++ _5 = copy _2; + return; + } + } + diff --git a/tests/mir-opt/gvn_storage_issue_141649.rs b/tests/mir-opt/gvn_storage_issue_141649.rs index 70323da03dea4..f6375119080c0 100644 --- a/tests/mir-opt/gvn_storage_issue_141649.rs +++ b/tests/mir-opt/gvn_storage_issue_141649.rs @@ -1,6 +1,7 @@ //! Check that we do not remove storage statements when possible. //@ test-mir-pass: GVN // EMIT_MIR gvn_storage_issue_141649.f.GVN.diff +// EMIT_MIR gvn_storage_issue_141649.f_borrowed.GVN.diff #![feature(custom_mir, core_intrinsics)] @@ -30,3 +31,29 @@ pub fn f(_1: u32) { } } } + +#[custom_mir(dialect = "runtime")] +pub fn f_borrowed(_1: u32) { + // CHECK-LABEL: fn f_borrowed( + mir! { + let _2: S; + let _3: S; + let _4: &S; + let _5: S; + { + // CHECK-NOT: StorageLive(_2); + // CHECK: _3 = copy _2; + // CHECK-NOT: StorageDead(_2); + // CHECK: _5 = copy _2; + StorageLive(_2); + _2 = S(_1, 2); + _3 = S(_1, 2); + _4 = &_3; + StorageDead(_2); + // Because `*_4` will be replaced with `_2`, + // we have to remove the storage statements of `_2`. + _5 = *_4; + Return() + } + } +} From 43f565472de59a24a942009d193b579d34d78e18 Mon Sep 17 00:00:00 2001 From: Ohad Ravid Date: Sun, 29 Jun 2025 12:09:04 +0300 Subject: [PATCH 14/14] Improved wording in comments and logs --- compiler/rustc_mir_transform/src/copy_prop.rs | 11 ++++++----- compiler/rustc_mir_transform/src/gvn.rs | 13 +++++++++---- 2 files changed, 15 insertions(+), 9 deletions(-) diff --git a/compiler/rustc_mir_transform/src/copy_prop.rs b/compiler/rustc_mir_transform/src/copy_prop.rs index aaed97ce3d9a6..8906356516e9f 100644 --- a/compiler/rustc_mir_transform/src/copy_prop.rs +++ b/compiler/rustc_mir_transform/src/copy_prop.rs @@ -52,9 +52,10 @@ impl<'tcx> crate::MirPass<'tcx> for CopyProp { let fully_moved = fully_moved_locals(&ssa, body); debug!(?fully_moved); - // We can determine if we can keep the head's storage statements (which enables better optimizations). - // For every local's usage location, we'll to remove it's storage statements only if the head is maybe-uninitialized, - // or if the local is borrowed (since we cannot easily identify when it is used). + // When emitting storage statements, we want to retain the head locals' storage statements, + // as this enables better optimizations. For each local use location, we mark the head for storage removal + // only if the head might be uninitialized at that point, or if the local is borrowed + // (since we cannot easily determine when it's used). let storage_to_remove = if tcx.sess.emit_lifetime_markers() { storage_to_remove.clear(); @@ -75,7 +76,7 @@ impl<'tcx> crate::MirPass<'tcx> for CopyProp { storage_checker.storage_to_remove } else { - // Conservatively remove all storage statements for the head locals. + // Remove the storage statements of all the head locals. storage_to_remove }; @@ -233,7 +234,7 @@ impl<'a, 'tcx> Visitor<'tcx> for StorageChecker<'a, 'tcx> { ?context, ?local, ?head, - "found a head at a location in which it is maybe uninit, marking head for storage statement removal" + "local's head is maybe uninit at this location, marking head for storage statement removal" ); self.storage_to_remove.insert(head); } diff --git a/compiler/rustc_mir_transform/src/gvn.rs b/compiler/rustc_mir_transform/src/gvn.rs index 2b105eb1dbc7b..fd0dff2519d7c 100644 --- a/compiler/rustc_mir_transform/src/gvn.rs +++ b/compiler/rustc_mir_transform/src/gvn.rs @@ -141,8 +141,9 @@ impl<'tcx> crate::MirPass<'tcx> for GVN { state.visit_basic_block_data(bb, data); } - // If we emit storage annotations, use `MaybeStorageDead` to check which reused locals - // require storage removal (making them alive for the duration of the function). + // When emitting storage statements, we want to retain the reused locals' storage statements, + // as this enables better optimizations. For each local use location, we mark it for storage removal + // only if it might be uninitialized at that point. let storage_to_remove = if tcx.sess.emit_lifetime_markers() { let maybe_uninit = MaybeUninitializedLocals::new() .iterate_to_fixpoint(tcx, body, Some("mir_opt::gvn")) @@ -160,7 +161,7 @@ impl<'tcx> crate::MirPass<'tcx> for GVN { storage_checker.storage_to_remove } else { - // Conservatively remove all storage statements for reused locals. + // Remove the storage statements of all the reused locals. state.reused_locals.clone() }; @@ -1907,7 +1908,11 @@ impl<'a, 'tcx> Visitor<'tcx> for StorageChecker<'a, 'tcx> { self.maybe_uninit.seek_before_primary_effect(location); if self.maybe_uninit.get().contains(local) { - debug!(?location, ?local, "local is maybe uninit in this location, removing storage"); + debug!( + ?location, + ?local, + "local is reused and is maybe uninit at this location, marking it for storage statement removal" + ); self.storage_to_remove.insert(local); } }