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