Skip to content

Commit 4505ff4

Browse files
committed
[mir-opt] Handle aggregates in SimplifyLocals pass
1 parent 8316701 commit 4505ff4

File tree

3 files changed

+17
-13
lines changed

3 files changed

+17
-13
lines changed

src/librustc_mir/transform/simplify.rs

+15-8
Original file line numberDiff line numberDiff line change
@@ -359,13 +359,20 @@ impl<'a, 'tcx> Visitor<'tcx> for DeclMarker<'a, 'tcx> {
359359
// Ignore stores of constants because `ConstProp` and `CopyProp` can remove uses of many
360360
// of these locals. However, if the local is still needed, then it will be referenced in
361361
// another place and we'll mark it as being used there.
362-
if ctx == PlaceContext::MutatingUse(MutatingUseContext::Store) {
363-
let stmt =
364-
&self.body.basic_blocks()[location.block].statements[location.statement_index];
365-
if let StatementKind::Assign(box (p, Rvalue::Use(Operand::Constant(c)))) = &stmt.kind {
366-
if p.as_local().is_some() {
367-
trace!("skipping store of const value {:?} to {:?}", c, local);
368-
return;
362+
if ctx == PlaceContext::MutatingUse(MutatingUseContext::Store) ||
363+
ctx == PlaceContext::MutatingUse(MutatingUseContext::Projection) {
364+
let block = &self.body.basic_blocks()[location.block];
365+
if location.statement_index != block.statements.len() {
366+
let stmt =
367+
&block.statements[location.statement_index];
368+
369+
if let StatementKind::Assign(
370+
box (p, Rvalue::Use(Operand::Constant(c)))
371+
) = &stmt.kind {
372+
if !p.is_indirect() {
373+
trace!("skipping store of const value {:?} to {:?}", c, p);
374+
return;
375+
}
369376
}
370377
}
371378
}
@@ -392,7 +399,7 @@ impl<'tcx> MutVisitor<'tcx> for LocalUpdater<'tcx> {
392399
self.map[*l].is_some()
393400
}
394401
StatementKind::Assign(box (place, _)) => {
395-
if let Some(local) = place.as_local() {
402+
if let PlaceBase::Local(local) = place.base {
396403
self.map[local].is_some()
397404
} else {
398405
true

src/test/incremental/hashes/struct_constructors.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ pub fn change_constructor_path_regular_struct() {
152152
}
153153

154154
#[cfg(not(cfail1))]
155-
#[rustc_clean(cfg="cfail2", except="HirBody,optimized_mir,mir_built,typeck_tables_of")]
155+
#[rustc_clean(cfg="cfail2", except="HirBody,mir_built,typeck_tables_of")]
156156
#[rustc_clean(cfg="cfail3")]
157157
pub fn change_constructor_path_regular_struct() {
158158
let _ = RegularStruct2 {
@@ -213,7 +213,7 @@ pub fn change_constructor_path_tuple_struct() {
213213
}
214214

215215
#[cfg(not(cfail1))]
216-
#[rustc_clean(cfg="cfail2", except="HirBody,optimized_mir,mir_built,typeck_tables_of")]
216+
#[rustc_clean(cfg="cfail2", except="HirBody,mir_built,typeck_tables_of")]
217217
#[rustc_clean(cfg="cfail3")]
218218
pub fn change_constructor_path_tuple_struct() {
219219
let _ = TupleStruct2(0, 1, 2);

src/test/mir-opt/const_prop/return_place.rs

-3
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,7 @@ fn main() {
4646
// START rustc.add.PreCodegen.before.mir
4747
// fn add() -> u32 {
4848
// let mut _0: u32;
49-
// let mut _1: (u32, bool);
5049
// bb0: {
51-
// (_1.0: u32) = const 4u32;
52-
// (_1.1: bool) = const false;
5350
// _0 = const 4u32;
5451
// return;
5552
// }

0 commit comments

Comments
 (0)