Auto merge of #119672 - cjgillot:dse-sandwich, r=oli-obk
Sandwich MIR optimizations between DSE. This PR reorders MIR optimization passes in an attempt to increase their efficiency. - Stop running CopyProp before GVN, it's useless as GVN will do the same thing anyway. Instead, we perform CopyProp at the end of the pipeline, to ensure we do not emit copy/move chains. - Run DSE before GVN, as it increases the probability to have single-assignment locals. - Run DSE after the final CopyProp to turn copies into moves. r? `@ghost`
This commit is contained in:
commit
fa0dc208d0
71 changed files with 549 additions and 290 deletions
|
@ -123,13 +123,21 @@ pub fn eliminate<'tcx>(tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) {
|
|||
let Operand::Copy(place) = *arg else { bug!() };
|
||||
*arg = Operand::Move(place);
|
||||
}
|
||||
|
||||
crate::simplify::simplify_locals(body, tcx)
|
||||
}
|
||||
|
||||
pub struct DeadStoreElimination;
|
||||
pub enum DeadStoreElimination {
|
||||
Initial,
|
||||
Final,
|
||||
}
|
||||
|
||||
impl<'tcx> MirPass<'tcx> for DeadStoreElimination {
|
||||
fn name(&self) -> &'static str {
|
||||
match self {
|
||||
DeadStoreElimination::Initial => "DeadStoreElimination-initial",
|
||||
DeadStoreElimination::Final => "DeadStoreElimination-final",
|
||||
}
|
||||
}
|
||||
|
||||
fn is_enabled(&self, sess: &rustc_session::Session) -> bool {
|
||||
sess.mir_opt_level() >= 2
|
||||
}
|
||||
|
|
|
@ -596,24 +596,25 @@ fn run_optimization_passes<'tcx>(tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) {
|
|||
&multiple_return_terminators::MultipleReturnTerminators,
|
||||
&instsimplify::InstSimplify,
|
||||
&simplify::SimplifyLocals::BeforeConstProp,
|
||||
©_prop::CopyProp,
|
||||
&dead_store_elimination::DeadStoreElimination::Initial,
|
||||
&gvn::GVN,
|
||||
&simplify::SimplifyLocals::AfterGVN,
|
||||
// Perform `SeparateConstSwitch` after SSA-based analyses, as cloning blocks may
|
||||
// destroy the SSA property. It should still happen before const-propagation, so the
|
||||
// latter pass will leverage the created opportunities.
|
||||
&separate_const_switch::SeparateConstSwitch,
|
||||
&gvn::GVN,
|
||||
&simplify::SimplifyLocals::AfterGVN,
|
||||
&dataflow_const_prop::DataflowConstProp,
|
||||
&const_debuginfo::ConstDebugInfo,
|
||||
&o1(simplify_branches::SimplifyConstCondition::AfterConstProp),
|
||||
&jump_threading::JumpThreading,
|
||||
&early_otherwise_branch::EarlyOtherwiseBranch,
|
||||
&simplify_comparison_integral::SimplifyComparisonIntegral,
|
||||
&dead_store_elimination::DeadStoreElimination,
|
||||
&dest_prop::DestinationPropagation,
|
||||
&o1(simplify_branches::SimplifyConstCondition::Final),
|
||||
&o1(remove_noop_landing_pads::RemoveNoopLandingPads),
|
||||
&o1(simplify::SimplifyCfg::Final),
|
||||
©_prop::CopyProp,
|
||||
&dead_store_elimination::DeadStoreElimination::Final,
|
||||
&nrvo::RenameReturnPlace,
|
||||
&simplify::SimplifyLocals::Final,
|
||||
&multiple_return_terminators::MultipleReturnTerminators,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue