Skip to content

Reorder early post-inlining passes. #119677

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 17 additions & 6 deletions compiler/rustc_mir_transform/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -565,17 +565,28 @@ fn run_optimization_passes<'tcx>(tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) {
body,
&[
&check_alignment::CheckAlignment,
&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
// Before inlining: trim down MIR with passes to reduce inlining work.

// Has to be done before inlining, otherwise actual call will be almost always inlined.
// Also simple, so can just do first
&lower_slice_len::LowerSliceLenCalls,
// Perform inlining, which may add a lot of code.
&inline::Inline,
// Substitutions during inlining may introduce switch on enums with uninhabited branches.
// Code from other crates may have storage markers, so this needs to happen after inlining.
&remove_storage_markers::RemoveStorageMarkers,
// Inlining and substitution may introduce ZST and useless drops.
&remove_zsts::RemoveZsts,
&remove_unneeded_drops::RemoveUnneededDrops,
// Type substitution may create uninhabited enums.
&uninhabited_enum_branching::UninhabitedEnumBranching,
&unreachable_prop::UnreachablePropagation,
&o1(simplify::SimplifyCfg::AfterUninhabitedEnumBranching),
&remove_storage_markers::RemoveStorageMarkers,
&remove_zsts::RemoveZsts,
&normalize_array_len::NormalizeArrayLen, // has to run after `slice::len` lowering
// Inlining may have introduced a lot of redundant code and a large move pattern.
// Now, we need to shrink the generated MIR.

// Has to run after `slice::len` lowering
&normalize_array_len::NormalizeArrayLen,
&const_goto::ConstGoto,
&remove_unneeded_drops::RemoveUnneededDrops,
&ref_prop::ReferencePropagation,
&sroa::ScalarReplacementOfAggregates,
&match_branches::MatchBranchSimplification,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@
+ StorageDead(_10);
+ StorageDead(_11);
+ nop;
nop;
StorageDead(_8);
StorageDead(_3);
StorageDead(_1);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@
+ StorageDead(_10);
+ StorageDead(_11);
+ nop;
nop;
StorageDead(_8);
StorageDead(_3);
StorageDead(_1);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@
+ StorageDead(_10);
+ StorageDead(_11);
+ nop;
nop;
StorageDead(_8);
StorageDead(_3);
StorageDead(_1);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@
+ StorageDead(_10);
+ StorageDead(_11);
+ nop;
nop;
StorageDead(_8);
StorageDead(_3);
StorageDead(_1);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,15 @@
let _1: ();

bb0: {
- switchInt(const false) -> [0: bb3, otherwise: bb1];
+ goto -> bb3;
- switchInt(const false) -> [0: bb2, otherwise: bb1];
+ goto -> bb2;
}

bb1: {
_1 = noop() -> [return: bb2, unwind unreachable];
}

bb2: {
goto -> bb4;
}

bb3: {
goto -> bb4;
}

bb4: {
return;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,15 @@
let _1: ();

bb0: {
- switchInt(const false) -> [0: bb3, otherwise: bb1];
+ goto -> bb3;
- switchInt(const false) -> [0: bb2, otherwise: bb1];
+ goto -> bb2;
}

bb1: {
_1 = noop() -> [return: bb2, unwind continue];
}

bb2: {
goto -> bb4;
}

bb3: {
goto -> bb4;
}

bb4: {
return;
}
}
Expand Down
10 changes: 3 additions & 7 deletions tests/mir-opt/simplify_match.main.GVN.panic-abort.diff
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,15 @@

bb0: {
_2 = const false;
- switchInt(_2) -> [0: bb1, otherwise: bb2];
+ switchInt(const false) -> [0: bb1, otherwise: bb2];
- switchInt(_2) -> [0: bb2, otherwise: bb1];
+ switchInt(const false) -> [0: bb2, otherwise: bb1];
}

bb1: {
goto -> bb3;
_0 = noop() -> [return: bb2, unwind unreachable];
}

bb2: {
_0 = noop() -> [return: bb3, unwind unreachable];
}

bb3: {
return;
}
}
Expand Down
10 changes: 3 additions & 7 deletions tests/mir-opt/simplify_match.main.GVN.panic-unwind.diff
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,15 @@

bb0: {
_2 = const false;
- switchInt(_2) -> [0: bb1, otherwise: bb2];
+ switchInt(const false) -> [0: bb1, otherwise: bb2];
- switchInt(_2) -> [0: bb2, otherwise: bb1];
+ switchInt(const false) -> [0: bb2, otherwise: bb1];
}

bb1: {
goto -> bb3;
_0 = noop() -> [return: bb2, unwind continue];
}

bb2: {
_0 = noop() -> [return: bb3, unwind continue];
}

bb3: {
return;
}
}
Expand Down