Skip to content

Commit 0b278a5

Browse files
committed
Auto merge of #147483 - cjgillot:reorder-passes, r=nnethercote
Perform InstSimplify before ReferencePropagation. `InstSimplify` clears CFG caches. But it currently happens between `ReferencePropagation` and `GVN`, which both use dominators, a quite expensive computation. r? `@ghost`
2 parents 4b57d81 + c3432bb commit 0b278a5

File tree

1 file changed

+6
-5
lines changed
  • compiler/rustc_mir_transform/src

1 file changed

+6
-5
lines changed

compiler/rustc_mir_transform/src/lib.rs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -684,6 +684,8 @@ pub(crate) fn run_optimization_passes<'tcx>(tcx: TyCtxt<'tcx>, body: &mut Body<'
684684
&inline::ForceInline,
685685
// Perform inlining, which may add a lot of code.
686686
&inline::Inline,
687+
// Inlining may have introduced a lot of redundant code and a large move pattern.
688+
// Now, we need to shrink the generated MIR.
687689
// Code from other crates may have storage markers, so this needs to happen after
688690
// inlining.
689691
&remove_storage_markers::RemoveStorageMarkers,
@@ -695,14 +697,13 @@ pub(crate) fn run_optimization_passes<'tcx>(tcx: TyCtxt<'tcx>, body: &mut Body<'
695697
&unreachable_enum_branching::UnreachableEnumBranching,
696698
&unreachable_prop::UnreachablePropagation,
697699
&o1(simplify::SimplifyCfg::AfterUnreachableEnumBranching),
698-
// Inlining may have introduced a lot of redundant code and a large move pattern.
699-
// Now, we need to shrink the generated MIR.
700-
&ref_prop::ReferencePropagation,
701-
&sroa::ScalarReplacementOfAggregates,
702700
&multiple_return_terminators::MultipleReturnTerminators,
703701
// After simplifycfg, it allows us to discover new opportunities for peephole
704-
// optimizations.
702+
// optimizations. This invalidates CFG caches, so avoid putting between
703+
// `ReferencePropagation` and `GVN` which both use the dominator tree.
705704
&instsimplify::InstSimplify::AfterSimplifyCfg,
705+
&ref_prop::ReferencePropagation,
706+
&sroa::ScalarReplacementOfAggregates,
706707
&simplify::SimplifyLocals::BeforeConstProp,
707708
&dead_store_elimination::DeadStoreElimination::Initial,
708709
&gvn::GVN,

0 commit comments

Comments
 (0)