Skip to content

Commit a8c4d43

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

9 files changed

+27
-44
lines changed

Diff for: compiler/rustc_mir_transform/src/lib.rs

+17-6
Original file line numberDiff line numberDiff line change
@@ -565,17 +565,28 @@ 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,
576-
&normalize_array_len::NormalizeArrayLen, // has to run after `slice::len` lowering
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+
587+
// Has to run after `slice::len` lowering
588+
&normalize_array_len::NormalizeArrayLen,
577589
&const_goto::ConstGoto,
578-
&remove_unneeded_drops::RemoveUnneededDrops,
579590
&ref_prop::ReferencePropagation,
580591
&sroa::ScalarReplacementOfAggregates,
581592
&match_branches::MatchBranchSimplification,

Diff for: tests/mir-opt/pre-codegen/optimizes_into_variable.main.ScalarReplacementOfAggregates.32bit.panic-abort.diff

-1
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,6 @@
6161
+ StorageDead(_10);
6262
+ StorageDead(_11);
6363
+ nop;
64-
nop;
6564
StorageDead(_8);
6665
StorageDead(_3);
6766
StorageDead(_1);

Diff for: tests/mir-opt/pre-codegen/optimizes_into_variable.main.ScalarReplacementOfAggregates.32bit.panic-unwind.diff

-1
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,6 @@
6161
+ StorageDead(_10);
6262
+ StorageDead(_11);
6363
+ nop;
64-
nop;
6564
StorageDead(_8);
6665
StorageDead(_3);
6766
StorageDead(_1);

Diff for: tests/mir-opt/pre-codegen/optimizes_into_variable.main.ScalarReplacementOfAggregates.64bit.panic-abort.diff

-1
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,6 @@
6161
+ StorageDead(_10);
6262
+ StorageDead(_11);
6363
+ nop;
64-
nop;
6564
StorageDead(_8);
6665
StorageDead(_3);
6766
StorageDead(_1);

Diff for: tests/mir-opt/pre-codegen/optimizes_into_variable.main.ScalarReplacementOfAggregates.64bit.panic-unwind.diff

-1
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,6 @@
6161
+ StorageDead(_10);
6262
+ StorageDead(_11);
6363
+ nop;
64-
nop;
6564
StorageDead(_8);
6665
StorageDead(_3);
6766
StorageDead(_1);

Diff for: tests/mir-opt/simplify_if.main.SimplifyConstCondition-after-const-prop.panic-abort.diff

+2-10
Original file line numberDiff line numberDiff line change
@@ -6,23 +6,15 @@
66
let _1: ();
77

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

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

1717
bb2: {
18-
goto -> bb4;
19-
}
20-
21-
bb3: {
22-
goto -> bb4;
23-
}
24-
25-
bb4: {
2618
return;
2719
}
2820
}

Diff for: tests/mir-opt/simplify_if.main.SimplifyConstCondition-after-const-prop.panic-unwind.diff

+2-10
Original file line numberDiff line numberDiff line change
@@ -6,23 +6,15 @@
66
let _1: ();
77

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

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

1717
bb2: {
18-
goto -> bb4;
19-
}
20-
21-
bb3: {
22-
goto -> bb4;
23-
}
24-
25-
bb4: {
2618
return;
2719
}
2820
}

Diff for: tests/mir-opt/simplify_match.main.GVN.panic-abort.diff

+3-7
Original file line numberDiff line numberDiff line change
@@ -11,19 +11,15 @@
1111

1212
bb0: {
1313
_2 = const false;
14-
- switchInt(_2) -> [0: bb1, otherwise: bb2];
15-
+ switchInt(const false) -> [0: bb1, otherwise: bb2];
14+
- switchInt(_2) -> [0: bb2, otherwise: bb1];
15+
+ switchInt(const false) -> [0: bb2, otherwise: bb1];
1616
}
1717

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

2222
bb2: {
23-
_0 = noop() -> [return: bb3, unwind unreachable];
24-
}
25-
26-
bb3: {
2723
return;
2824
}
2925
}

Diff for: tests/mir-opt/simplify_match.main.GVN.panic-unwind.diff

+3-7
Original file line numberDiff line numberDiff line change
@@ -11,19 +11,15 @@
1111

1212
bb0: {
1313
_2 = const false;
14-
- switchInt(_2) -> [0: bb1, otherwise: bb2];
15-
+ switchInt(const false) -> [0: bb1, otherwise: bb2];
14+
- switchInt(_2) -> [0: bb2, otherwise: bb1];
15+
+ switchInt(const false) -> [0: bb2, otherwise: bb1];
1616
}
1717

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

2222
bb2: {
23-
_0 = noop() -> [return: bb3, unwind continue];
24-
}
25-
26-
bb3: {
2723
return;
2824
}
2925
}

0 commit comments

Comments
 (0)