@@ -151,7 +151,7 @@ impl<'tcx> crate::MirPass<'tcx> for GVN {
151151 . into_results_cursor ( body) ;
152152
153153 let mut storage_checker = StorageChecker {
154- storage_to_check : state. reused_locals . clone ( ) ,
154+ reused_locals : & state. reused_locals ,
155155 storage_to_remove : DenseBitSet :: new_empty ( body. local_decls . len ( ) ) ,
156156 maybe_uninit,
157157 } ;
@@ -1908,7 +1908,7 @@ impl<'tcx> MutVisitor<'tcx> for StorageRemover<'tcx> {
19081908}
19091909
19101910struct StorageChecker < ' a , ' tcx > {
1911- storage_to_check : DenseBitSet < Local > ,
1911+ reused_locals : & ' a DenseBitSet < Local > ,
19121912 storage_to_remove : DenseBitSet < Local > ,
19131913 maybe_uninit : ResultsCursor < ' a , ' tcx , MaybeUninitializedLocals > ,
19141914}
@@ -1928,18 +1928,16 @@ impl<'a, 'tcx> Visitor<'tcx> for StorageChecker<'a, 'tcx> {
19281928 PlaceContext :: MutatingUse ( _) | PlaceContext :: NonMutatingUse ( _) => { }
19291929 }
19301930
1931- if self . storage_to_check . contains ( local) {
1932- self . maybe_uninit . seek_before_primary_effect ( location) ;
1933-
1934- if self . maybe_uninit . get ( ) . contains ( local) {
1935- debug ! (
1936- ?location,
1937- ?local,
1938- "local is maybe uninit in this location, removing storage"
1939- ) ;
1940- self . storage_to_remove . insert ( local) ;
1941- self . storage_to_check . remove ( local) ;
1942- }
1931+ // We only need to check reused locals which we haven't already removed storage for.
1932+ if !self . reused_locals . contains ( local) || self . storage_to_remove . contains ( local) {
1933+ return ;
1934+ }
1935+
1936+ self . maybe_uninit . seek_before_primary_effect ( location) ;
1937+
1938+ if self . maybe_uninit . get ( ) . contains ( local) {
1939+ debug ! ( ?location, ?local, "local is maybe uninit in this location, removing storage" ) ;
1940+ self . storage_to_remove . insert ( local) ;
19431941 }
19441942 }
19451943}
0 commit comments