Skip to content

Commit

Permalink
[mir-opt] Handle aggregates in SimplifyLocals pass
Browse files Browse the repository at this point in the history
  • Loading branch information
wesleywiser committed Nov 9, 2019
1 parent 8316701 commit 4505ff4
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 13 deletions.
23 changes: 15 additions & 8 deletions src/librustc_mir/transform/simplify.rs
Expand Up @@ -359,13 +359,20 @@ impl<'a, 'tcx> Visitor<'tcx> for DeclMarker<'a, 'tcx> {
// Ignore stores of constants because `ConstProp` and `CopyProp` can remove uses of many
// of these locals. However, if the local is still needed, then it will be referenced in
// another place and we'll mark it as being used there.
if ctx == PlaceContext::MutatingUse(MutatingUseContext::Store) {
let stmt =
&self.body.basic_blocks()[location.block].statements[location.statement_index];
if let StatementKind::Assign(box (p, Rvalue::Use(Operand::Constant(c)))) = &stmt.kind {
if p.as_local().is_some() {
trace!("skipping store of const value {:?} to {:?}", c, local);
return;
if ctx == PlaceContext::MutatingUse(MutatingUseContext::Store) ||
ctx == PlaceContext::MutatingUse(MutatingUseContext::Projection) {
let block = &self.body.basic_blocks()[location.block];
if location.statement_index != block.statements.len() {
let stmt =
&block.statements[location.statement_index];

if let StatementKind::Assign(
box (p, Rvalue::Use(Operand::Constant(c)))
) = &stmt.kind {
if !p.is_indirect() {
trace!("skipping store of const value {:?} to {:?}", c, p);
return;
}
}
}
}
Expand All @@ -392,7 +399,7 @@ impl<'tcx> MutVisitor<'tcx> for LocalUpdater<'tcx> {
self.map[*l].is_some()
}
StatementKind::Assign(box (place, _)) => {
if let Some(local) = place.as_local() {
if let PlaceBase::Local(local) = place.base {
self.map[local].is_some()
} else {
true
Expand Down
4 changes: 2 additions & 2 deletions src/test/incremental/hashes/struct_constructors.rs
Expand Up @@ -152,7 +152,7 @@ pub fn change_constructor_path_regular_struct() {
}

#[cfg(not(cfail1))]
#[rustc_clean(cfg="cfail2", except="HirBody,optimized_mir,mir_built,typeck_tables_of")]
#[rustc_clean(cfg="cfail2", except="HirBody,mir_built,typeck_tables_of")]
#[rustc_clean(cfg="cfail3")]
pub fn change_constructor_path_regular_struct() {
let _ = RegularStruct2 {
Expand Down Expand Up @@ -213,7 +213,7 @@ pub fn change_constructor_path_tuple_struct() {
}

#[cfg(not(cfail1))]
#[rustc_clean(cfg="cfail2", except="HirBody,optimized_mir,mir_built,typeck_tables_of")]
#[rustc_clean(cfg="cfail2", except="HirBody,mir_built,typeck_tables_of")]
#[rustc_clean(cfg="cfail3")]
pub fn change_constructor_path_tuple_struct() {
let _ = TupleStruct2(0, 1, 2);
Expand Down
3 changes: 0 additions & 3 deletions src/test/mir-opt/const_prop/return_place.rs
Expand Up @@ -46,10 +46,7 @@ fn main() {
// START rustc.add.PreCodegen.before.mir
// fn add() -> u32 {
// let mut _0: u32;
// let mut _1: (u32, bool);
// bb0: {
// (_1.0: u32) = const 4u32;
// (_1.1: bool) = const false;
// _0 = const 4u32;
// return;
// }
Expand Down

0 comments on commit 4505ff4

Please sign in to comment.