@@ -141,8 +141,9 @@ impl<'tcx> crate::MirPass<'tcx> for GVN {
141
141
state. visit_basic_block_data ( bb, data) ;
142
142
}
143
143
144
- // If we emit storage annotations, use `MaybeStorageDead` to check which reused locals
145
- // require storage removal (making them alive for the duration of the function).
144
+ // When emitting storage statements, we want to retain the reused locals' storage statements,
145
+ // as this enables better optimizations. For each local use location, we mark it for storage removal
146
+ // only if it might be uninitialized at that point.
146
147
let storage_to_remove = if tcx. sess . emit_lifetime_markers ( ) {
147
148
let maybe_uninit = MaybeUninitializedLocals :: new ( )
148
149
. iterate_to_fixpoint ( tcx, body, Some ( "mir_opt::gvn" ) )
@@ -160,7 +161,7 @@ impl<'tcx> crate::MirPass<'tcx> for GVN {
160
161
161
162
storage_checker. storage_to_remove
162
163
} else {
163
- // Conservatively remove all storage statements for reused locals.
164
+ // Remove the storage statements of all the reused locals.
164
165
state. reused_locals . clone ( )
165
166
} ;
166
167
@@ -1907,7 +1908,11 @@ impl<'a, 'tcx> Visitor<'tcx> for StorageChecker<'a, 'tcx> {
1907
1908
self . maybe_uninit . seek_before_primary_effect ( location) ;
1908
1909
1909
1910
if self . maybe_uninit . get ( ) . contains ( local) {
1910
- debug ! ( ?location, ?local, "local is maybe uninit in this location, removing storage" ) ;
1911
+ debug ! (
1912
+ ?location,
1913
+ ?local,
1914
+ "local is reused and is maybe uninit at this location, marking it for storage statement removal"
1915
+ ) ;
1911
1916
self . storage_to_remove . insert ( local) ;
1912
1917
}
1913
1918
}
0 commit comments