@@ -148,7 +148,7 @@ impl<'tcx> crate::MirPass<'tcx> for GVN {
148148 . into_results_cursor ( body) ;
149149
150150 let mut storage_checker = StorageChecker {
151- storage_to_check : state. reused_locals . clone ( ) ,
151+ reused_locals : & state. reused_locals ,
152152 storage_to_remove : DenseBitSet :: new_empty ( body. local_decls . len ( ) ) ,
153153 maybe_uninit,
154154 } ;
@@ -1834,7 +1834,7 @@ impl<'tcx> MutVisitor<'tcx> for StorageRemover<'tcx> {
18341834}
18351835
18361836struct StorageChecker < ' a , ' tcx > {
1837- storage_to_check : DenseBitSet < Local > ,
1837+ reused_locals : & ' a DenseBitSet < Local > ,
18381838 storage_to_remove : DenseBitSet < Local > ,
18391839 maybe_uninit : ResultsCursor < ' a , ' tcx , MaybeUninitializedLocals > ,
18401840}
@@ -1854,18 +1854,16 @@ impl<'a, 'tcx> Visitor<'tcx> for StorageChecker<'a, 'tcx> {
18541854 PlaceContext :: MutatingUse ( _) | PlaceContext :: NonMutatingUse ( _) => { }
18551855 }
18561856
1857- if self . storage_to_check . contains ( local) {
1858- self . maybe_uninit . seek_before_primary_effect ( location) ;
1859-
1860- if self . maybe_uninit . get ( ) . contains ( local) {
1861- debug ! (
1862- ?location,
1863- ?local,
1864- "local is maybe uninit in this location, removing storage"
1865- ) ;
1866- self . storage_to_remove . insert ( local) ;
1867- self . storage_to_check . remove ( local) ;
1868- }
1857+ // We only need to check reused locals which we haven't already removed storage for.
1858+ if !self . reused_locals . contains ( local) || self . storage_to_remove . contains ( local) {
1859+ return ;
1860+ }
1861+
1862+ self . maybe_uninit . seek_before_primary_effect ( location) ;
1863+
1864+ if self . maybe_uninit . get ( ) . contains ( local) {
1865+ debug ! ( ?location, ?local, "local is maybe uninit in this location, removing storage" ) ;
1866+ self . storage_to_remove . insert ( local) ;
18691867 }
18701868 }
18711869}
0 commit comments