@@ -152,8 +152,9 @@ impl<'tcx> crate::MirPass<'tcx> for GVN {
152152 state. visit_basic_block_data ( bb, data) ;
153153 }
154154
155- // If we emit storage annotations, use `MaybeStorageDead` to check which reused locals
156- // require storage removal (making them alive for the duration of the function).
155+ // When emitting storage statements, we want to retain the reused locals' storage statements,
156+ // as this enables better optimizations. For each local use location, we mark it for storage removal
157+ // only if it might be uninitialized at that point.
157158 let storage_to_remove = if tcx. sess . emit_lifetime_markers ( ) {
158159 let maybe_uninit = MaybeUninitializedLocals :: new ( )
159160 . iterate_to_fixpoint ( tcx, body, Some ( "mir_opt::gvn" ) )
@@ -171,7 +172,7 @@ impl<'tcx> crate::MirPass<'tcx> for GVN {
171172
172173 storage_checker. storage_to_remove
173174 } else {
174- // Conservatively remove all storage statements for reused locals.
175+ // Remove the storage statements of all the reused locals.
175176 state. reused_locals . clone ( )
176177 } ;
177178
@@ -2014,7 +2015,11 @@ impl<'a, 'tcx> Visitor<'tcx> for StorageChecker<'a, 'tcx> {
20142015 self . maybe_uninit . seek_before_primary_effect ( location) ;
20152016
20162017 if self . maybe_uninit . get ( ) . contains ( local) {
2017- debug ! ( ?location, ?local, "local is maybe uninit in this location, removing storage" ) ;
2018+ debug ! (
2019+ ?location,
2020+ ?local,
2021+ "local is reused and is maybe uninit at this location, marking it for storage statement removal"
2022+ ) ;
20182023 self . storage_to_remove . insert ( local) ;
20192024 }
20202025 }
0 commit comments