From 2533f78d62dfdaec52b77d37167bba246e211378 Mon Sep 17 00:00:00 2001 From: Camille Gillot Date: Wed, 8 Oct 2025 15:17:15 +0000 Subject: [PATCH 1/2] Reorder passes. --- compiler/rustc_mir_transform/src/lib.rs | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/compiler/rustc_mir_transform/src/lib.rs b/compiler/rustc_mir_transform/src/lib.rs index 9ff7e0b55003..acf5a5c86f71 100644 --- a/compiler/rustc_mir_transform/src/lib.rs +++ b/compiler/rustc_mir_transform/src/lib.rs @@ -684,6 +684,8 @@ pub(crate) fn run_optimization_passes<'tcx>(tcx: TyCtxt<'tcx>, body: &mut Body<' &inline::ForceInline, // Perform inlining, which may add a lot of code. &inline::Inline, + // Inlining may have introduced a lot of redundant code and a large move pattern. + // Now, we need to shrink the generated MIR. // Code from other crates may have storage markers, so this needs to happen after // inlining. &remove_storage_markers::RemoveStorageMarkers, @@ -695,14 +697,13 @@ pub(crate) fn run_optimization_passes<'tcx>(tcx: TyCtxt<'tcx>, body: &mut Body<' &unreachable_enum_branching::UnreachableEnumBranching, &unreachable_prop::UnreachablePropagation, &o1(simplify::SimplifyCfg::AfterUnreachableEnumBranching), - // Inlining may have introduced a lot of redundant code and a large move pattern. - // Now, we need to shrink the generated MIR. - &ref_prop::ReferencePropagation, - &sroa::ScalarReplacementOfAggregates, &multiple_return_terminators::MultipleReturnTerminators, // After simplifycfg, it allows us to discover new opportunities for peephole - // optimizations. + // optimizations. This invalidates CFG caches, so avoid putting between two SSA + // analyses. &instsimplify::InstSimplify::AfterSimplifyCfg, + &ref_prop::ReferencePropagation, + &sroa::ScalarReplacementOfAggregates, &simplify::SimplifyLocals::BeforeConstProp, &dead_store_elimination::DeadStoreElimination::Initial, &gvn::GVN, From c3432bbec01a6b72374b95f721e936969d4a04a8 Mon Sep 17 00:00:00 2001 From: Camille Gillot Date: Thu, 9 Oct 2025 11:51:17 +0000 Subject: [PATCH 2/2] Explicit comment. --- compiler/rustc_mir_transform/src/lib.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/compiler/rustc_mir_transform/src/lib.rs b/compiler/rustc_mir_transform/src/lib.rs index acf5a5c86f71..f4f61c80a220 100644 --- a/compiler/rustc_mir_transform/src/lib.rs +++ b/compiler/rustc_mir_transform/src/lib.rs @@ -699,8 +699,8 @@ pub(crate) fn run_optimization_passes<'tcx>(tcx: TyCtxt<'tcx>, body: &mut Body<' &o1(simplify::SimplifyCfg::AfterUnreachableEnumBranching), &multiple_return_terminators::MultipleReturnTerminators, // After simplifycfg, it allows us to discover new opportunities for peephole - // optimizations. This invalidates CFG caches, so avoid putting between two SSA - // analyses. + // optimizations. This invalidates CFG caches, so avoid putting between + // `ReferencePropagation` and `GVN` which both use the dominator tree. &instsimplify::InstSimplify::AfterSimplifyCfg, &ref_prop::ReferencePropagation, &sroa::ScalarReplacementOfAggregates,