@@ -148,7 +148,7 @@ impl<'tcx> crate::MirPass<'tcx> for GVN {
148
148
. into_results_cursor ( body) ;
149
149
150
150
let mut storage_checker = StorageChecker {
151
- storage_to_check : state. reused_locals . clone ( ) ,
151
+ reused_locals : & state. reused_locals ,
152
152
storage_to_remove : DenseBitSet :: new_empty ( body. local_decls . len ( ) ) ,
153
153
maybe_uninit,
154
154
} ;
@@ -1834,7 +1834,7 @@ impl<'tcx> MutVisitor<'tcx> for StorageRemover<'tcx> {
1834
1834
}
1835
1835
1836
1836
struct StorageChecker < ' a , ' tcx > {
1837
- storage_to_check : DenseBitSet < Local > ,
1837
+ reused_locals : & ' a DenseBitSet < Local > ,
1838
1838
storage_to_remove : DenseBitSet < Local > ,
1839
1839
maybe_uninit : ResultsCursor < ' a , ' tcx , MaybeUninitializedLocals > ,
1840
1840
}
@@ -1854,18 +1854,16 @@ impl<'a, 'tcx> Visitor<'tcx> for StorageChecker<'a, 'tcx> {
1854
1854
PlaceContext :: MutatingUse ( _) | PlaceContext :: NonMutatingUse ( _) => { }
1855
1855
}
1856
1856
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) ;
1869
1867
}
1870
1868
}
1871
1869
}
0 commit comments