@@ -149,7 +149,7 @@ impl<'tcx> crate::MirPass<'tcx> for GVN {
149
149
. into_results_cursor ( body) ;
150
150
151
151
let mut storage_checker = StorageChecker {
152
- storage_to_check : state. reused_locals . clone ( ) ,
152
+ reused_locals : & state. reused_locals ,
153
153
storage_to_remove : DenseBitSet :: new_empty ( body. local_decls . len ( ) ) ,
154
154
maybe_uninit,
155
155
} ;
@@ -1877,7 +1877,7 @@ impl<'tcx> MutVisitor<'tcx> for StorageRemover<'tcx> {
1877
1877
}
1878
1878
1879
1879
struct StorageChecker < ' a , ' tcx > {
1880
- storage_to_check : DenseBitSet < Local > ,
1880
+ reused_locals : & ' a DenseBitSet < Local > ,
1881
1881
storage_to_remove : DenseBitSet < Local > ,
1882
1882
maybe_uninit : ResultsCursor < ' a , ' tcx , MaybeUninitializedLocals > ,
1883
1883
}
@@ -1897,18 +1897,16 @@ impl<'a, 'tcx> Visitor<'tcx> for StorageChecker<'a, 'tcx> {
1897
1897
PlaceContext :: MutatingUse ( _) | PlaceContext :: NonMutatingUse ( _) => { }
1898
1898
}
1899
1899
1900
- if self . storage_to_check . contains ( local) {
1901
- self . maybe_uninit . seek_before_primary_effect ( location) ;
1902
-
1903
- if self . maybe_uninit . get ( ) . contains ( local) {
1904
- debug ! (
1905
- ?location,
1906
- ?local,
1907
- "local is maybe uninit in this location, removing storage"
1908
- ) ;
1909
- self . storage_to_remove . insert ( local) ;
1910
- self . storage_to_check . remove ( local) ;
1911
- }
1900
+ // We only need to check reused locals which we haven't already removed storage for.
1901
+ if !self . reused_locals . contains ( local) || self . storage_to_remove . contains ( local) {
1902
+ return ;
1903
+ }
1904
+
1905
+ self . maybe_uninit . seek_before_primary_effect ( location) ;
1906
+
1907
+ if self . maybe_uninit . get ( ) . contains ( local) {
1908
+ debug ! ( ?location, ?local, "local is maybe uninit in this location, removing storage" ) ;
1909
+ self . storage_to_remove . insert ( local) ;
1912
1910
}
1913
1911
}
1914
1912
}
0 commit comments