13
13
//!
14
14
15
15
use rustc_middle:: bug;
16
- use rustc_middle:: mir:: visit:: Visitor ;
16
+ use rustc_middle:: mir:: visit:: * ;
17
17
use rustc_middle:: mir:: * ;
18
18
use rustc_middle:: ty:: TyCtxt ;
19
19
use rustc_mir_dataflow:: debuginfo:: debuginfo_locals;
@@ -95,7 +95,7 @@ pub fn eliminate<'tcx>(tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) {
95
95
if !place. is_indirect ( ) && !always_live. contains ( place. local ) {
96
96
live. seek_before_primary_effect ( loc) ;
97
97
if !live. get ( ) . contains ( place. local ) {
98
- patch. push ( loc) ;
98
+ patch. push ( ( place . local , loc) ) ;
99
99
}
100
100
}
101
101
}
@@ -120,8 +120,31 @@ pub fn eliminate<'tcx>(tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) {
120
120
}
121
121
122
122
let bbs = body. basic_blocks . as_mut_preserves_cfg ( ) ;
123
- for Location { block, statement_index } in patch {
123
+ for ( local , Location { block, statement_index } ) in patch {
124
124
bbs[ block] . statements [ statement_index] . make_nop ( ) ;
125
+ if bbs[ block] . statements . iter ( ) . all ( |stmt| match stmt. kind {
126
+ StatementKind :: Assign ( box ( place, _) )
127
+ | StatementKind :: SetDiscriminant { place : box place, .. }
128
+ | StatementKind :: Deinit ( box place) => place. local != local,
129
+ _ => true ,
130
+ } ) {
131
+ if let Some ( storage_live_index) = bbs[ block]
132
+ . statements
133
+ . iter ( )
134
+ . take ( statement_index)
135
+ . position ( |stmt| stmt. kind == StatementKind :: StorageLive ( local) )
136
+ {
137
+ if let Some ( storage_dead_index) = bbs[ block]
138
+ . statements
139
+ . iter ( )
140
+ . skip ( statement_index)
141
+ . position ( |stmt| stmt. kind == StatementKind :: StorageDead ( local) )
142
+ {
143
+ bbs[ block] . statements [ storage_live_index] . make_nop ( ) ;
144
+ bbs[ block] . statements [ storage_dead_index + statement_index] . make_nop ( ) ;
145
+ }
146
+ }
147
+ }
125
148
}
126
149
for ( block, argument_index) in call_operands_to_move {
127
150
let TerminatorKind :: Call { ref mut args, .. } = bbs[ block] . terminator_mut ( ) . kind else {
0 commit comments