Skip to content

Commit 7f6fa19

Browse files
committed
Reorder early post-inlining passes.
1 parent b8c2074 commit 7f6fa19

File tree

1 file changed

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

1 file changed

+15
-5
lines changed

compiler/rustc_mir_transform/src/lib.rs

+15-5
Original file line numberDiff line numberDiff line change
@@ -565,17 +565,27 @@ fn run_optimization_passes<'tcx>(tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) {
565565
body,
566566
&[
567567
&check_alignment::CheckAlignment,
568-
&lower_slice_len::LowerSliceLenCalls, // has to be done before inlining, otherwise actual call will be almost always inlined. Also simple, so can just do first
568+
// Before inlining: trim down MIR with passes to reduce inlining work.
569+
570+
// has to be done before inlining, otherwise actual call will be almost always inlined.
571+
// Also simple, so can just do first
572+
&lower_slice_len::LowerSliceLenCalls,
573+
// Perform inlining, which may add a lot of code.
569574
&inline::Inline,
570-
// Substitutions during inlining may introduce switch on enums with uninhabited branches.
575+
// Code from other crates may have storage markers, so this needs to happen after inlining.
576+
&remove_storage_markers::RemoveStorageMarkers,
577+
// Inlining and substitution may introduce ZST and useless drops.
578+
&remove_zsts::RemoveZsts,
579+
&remove_unneeded_drops::RemoveUnneededDrops,
580+
// Type substitution may create uninhabited enums.
571581
&uninhabited_enum_branching::UninhabitedEnumBranching,
572582
&unreachable_prop::UnreachablePropagation,
573583
&o1(simplify::SimplifyCfg::AfterUninhabitedEnumBranching),
574-
&remove_storage_markers::RemoveStorageMarkers,
575-
&remove_zsts::RemoveZsts,
584+
// Inlining may have introduced a lot of redundant code and a large move pattern.
585+
// Now, we need to shrink the generated MIR.
586+
576587
&normalize_array_len::NormalizeArrayLen, // has to run after `slice::len` lowering
577588
&const_goto::ConstGoto,
578-
&remove_unneeded_drops::RemoveUnneededDrops,
579589
&ref_prop::ReferencePropagation,
580590
&sroa::ScalarReplacementOfAggregates,
581591
&match_branches::MatchBranchSimplification,

0 commit comments

Comments
 (0)