Auto merge of #105323 - cjgillot:simplify-const-prop, r=davidtwco
Perform SimplifyLocals before ConstProp. MIR before `ConstProp` may have a lot of dead writes, this makes `ConstProp` do unnecessary work. r? `@ghost`
This commit is contained in:
commit
b1691f6413
81 changed files with 379 additions and 512 deletions
|
@ -71,7 +71,7 @@ pub fn eliminate<'tcx>(tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>, borrowed: &BitS
|
|||
bbs[block].statements[statement_index].make_nop();
|
||||
}
|
||||
|
||||
crate::simplify::SimplifyLocals.run_pass(tcx, body)
|
||||
crate::simplify::simplify_locals(body, tcx)
|
||||
}
|
||||
|
||||
pub struct DeadStoreElimination;
|
||||
|
|
|
@ -557,6 +557,7 @@ fn run_optimization_passes<'tcx>(tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) {
|
|||
&multiple_return_terminators::MultipleReturnTerminators,
|
||||
&instcombine::InstCombine,
|
||||
&separate_const_switch::SeparateConstSwitch,
|
||||
&simplify::SimplifyLocals::new("before-const-prop"),
|
||||
//
|
||||
// FIXME(#70073): This pass is responsible for both optimization as well as some lints.
|
||||
&const_prop::ConstProp,
|
||||
|
@ -575,7 +576,7 @@ fn run_optimization_passes<'tcx>(tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) {
|
|||
&o1(remove_noop_landing_pads::RemoveNoopLandingPads),
|
||||
&o1(simplify::SimplifyCfg::new("final")),
|
||||
&nrvo::RenameReturnPlace,
|
||||
&simplify::SimplifyLocals,
|
||||
&simplify::SimplifyLocals::new("final"),
|
||||
&multiple_return_terminators::MultipleReturnTerminators,
|
||||
&deduplicate_blocks::DeduplicateBlocks,
|
||||
// Some cleanup necessary at least for LLVM and potentially other codegen backends.
|
||||
|
|
|
@ -379,9 +379,21 @@ fn save_unreachable_coverage(
|
|||
));
|
||||
}
|
||||
|
||||
pub struct SimplifyLocals;
|
||||
pub struct SimplifyLocals {
|
||||
label: String,
|
||||
}
|
||||
|
||||
impl SimplifyLocals {
|
||||
pub fn new(label: &str) -> SimplifyLocals {
|
||||
SimplifyLocals { label: format!("SimplifyLocals-{}", label) }
|
||||
}
|
||||
}
|
||||
|
||||
impl<'tcx> MirPass<'tcx> for SimplifyLocals {
|
||||
fn name(&self) -> &str {
|
||||
&self.label
|
||||
}
|
||||
|
||||
fn is_enabled(&self, sess: &rustc_session::Session) -> bool {
|
||||
sess.mir_opt_level() > 0
|
||||
}
|
||||
|
@ -557,6 +569,7 @@ fn remove_unused_definitions(used_locals: &mut UsedLocals, body: &mut Body<'_>)
|
|||
|
||||
StatementKind::SetDiscriminant { ref place, .. }
|
||||
| StatementKind::Deinit(ref place) => used_locals.is_used(place.local),
|
||||
StatementKind::Nop => false,
|
||||
_ => true,
|
||||
};
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue