@@ -143,8 +143,9 @@ impl<'tcx> crate::MirPass<'tcx> for GVN {
143143 state. visit_basic_block_data ( bb, data) ;
144144 }
145145
146- // If we emit storage annotations, use `MaybeStorageDead` to check which reused locals
147- // require storage removal (making them alive for the duration of the function).
146+ // When emitting storage statements, we want to retain the reused locals' storage statements,
147+ // as this enables better optimizations. For each local use location, we mark it for storage removal
148+ // only if it might be uninitialized at that point.
148149 let storage_to_remove = if tcx. sess . emit_lifetime_markers ( ) {
149150 let maybe_uninit = MaybeUninitializedLocals :: new ( )
150151 . iterate_to_fixpoint ( tcx, body, Some ( "mir_opt::gvn" ) )
@@ -162,7 +163,7 @@ impl<'tcx> crate::MirPass<'tcx> for GVN {
162163
163164 storage_checker. storage_to_remove
164165 } else {
165- // Conservatively remove all storage statements for reused locals.
166+ // Remove the storage statements of all the reused locals.
166167 state. reused_locals . clone ( )
167168 } ;
168169
@@ -1938,7 +1939,11 @@ impl<'a, 'tcx> Visitor<'tcx> for StorageChecker<'a, 'tcx> {
19381939 self . maybe_uninit . seek_before_primary_effect ( location) ;
19391940
19401941 if self . maybe_uninit . get ( ) . contains ( local) {
1941- debug ! ( ?location, ?local, "local is maybe uninit in this location, removing storage" ) ;
1942+ debug ! (
1943+ ?location,
1944+ ?local,
1945+ "local is reused and is maybe uninit at this location, marking it for storage statement removal"
1946+ ) ;
19421947 self . storage_to_remove . insert ( local) ;
19431948 }
19441949 }
0 commit comments