Skip to content

Commit 362bc6a

Browse files
committed
Add more simplify passes.
1 parent c37ec99 commit 362bc6a

6 files changed

+9
-34
lines changed

compiler/rustc_mir_transform/src/lib.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -596,18 +596,19 @@ fn run_optimization_passes<'tcx>(tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) {
596596
&match_branches::MatchBranchSimplification,
597597
// inst combine is after MatchBranchSimplification to clean up Ne(_1, false)
598598
&instsimplify::InstSimplify,
599+
&o1(simplify::SimplifyCfg::AfterGVN),
599600
// Turn non-aliasing places into locals.
600601
// Helps `DeadStoreElimination` to remove them and `CopyProp` to merge them.
601602
&simplify::SimplifyLocals::BeforeSROA,
602603
&sroa::ScalarReplacementOfAggregates,
603604
// Compute `Len` when it comes from an unsizing cast.
604605
&normalize_array_len::NormalizeArrayLen,
605606
// Perform a first round of constant propagation.
606-
&o1(simplify::SimplifyCfg::BeforeConstProp),
607607
&simplify::SimplifyLocals::BeforeConstProp,
608608
// Turn `SwitchInt(Eq(x, constant))` into `SwitchInt(x)`.
609609
// Runs after ConstProp to increase probability to have constants.
610610
&simplify_comparison_integral::SimplifyComparisonIntegral,
611+
&o1(simplify::SimplifyCfg::AfterConstProp),
611612
&early_otherwise_branch::EarlyOtherwiseBranch,
612613
// Merge locals that just copy each another.
613614
&copy_prop::CopyProp,
@@ -623,7 +624,7 @@ fn run_optimization_passes<'tcx>(tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) {
623624
&gvn::GVN::Final,
624625
&o1(remove_noop_landing_pads::RemoveNoopLandingPads),
625626
&o1(simplify::SimplifyCfg::Final),
626-
&simplify::SimplifyLocals::AfterGVN,
627+
&simplify::SimplifyLocals::BeforeDestProp,
627628
&dest_prop::DestinationPropagation,
628629
// Attempt to promote call operands from copies to moves.
629630
&dead_store_elimination::DeadStoreElimination::Final,

compiler/rustc_mir_transform/src/simplify.rs

+6
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@ pub enum SimplifyCfg {
3939
RemoveFalseEdges,
4040
EarlyOpt,
4141
ElaborateDrops,
42+
AfterGVN,
43+
AfterConstProp,
4244
Final,
4345
MakeShim,
4446
AfterUninhabitedEnumBranching,
@@ -53,6 +55,8 @@ impl SimplifyCfg {
5355
SimplifyCfg::RemoveFalseEdges => "SimplifyCfg-remove-false-edges",
5456
SimplifyCfg::EarlyOpt => "SimplifyCfg-early-opt",
5557
SimplifyCfg::ElaborateDrops => "SimplifyCfg-elaborate-drops",
58+
SimplifyCfg::AfterGVN => "SimplifyCfg-after-gvn",
59+
SimplifyCfg::AfterConstProp => "SimplifyCfg-after-const-prop",
5660
SimplifyCfg::Final => "SimplifyCfg-final",
5761
SimplifyCfg::MakeShim => "SimplifyCfg-make_shim",
5862
SimplifyCfg::AfterUninhabitedEnumBranching => {
@@ -350,6 +354,7 @@ pub(crate) fn remove_dead_blocks(body: &mut Body<'_>) {
350354
pub enum SimplifyLocals {
351355
BeforeSROA,
352356
BeforeConstProp,
357+
BeforeDestProp,
353358
AfterGVN,
354359
Final,
355360
}
@@ -359,6 +364,7 @@ impl<'tcx> MirPass<'tcx> for SimplifyLocals {
359364
match &self {
360365
SimplifyLocals::BeforeSROA => "SimplifyLocals-before-sroa",
361366
SimplifyLocals::BeforeConstProp => "SimplifyLocals-before-const-prop",
367+
SimplifyLocals::BeforeDestProp => "SimplifyLocals-before-dest-prop",
362368
SimplifyLocals::AfterGVN => "SimplifyLocals-after-value-numbering",
363369
SimplifyLocals::Final => "SimplifyLocals-final",
364370
}

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

-8
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,6 @@
1414
}
1515

1616
bb0: {
17-
goto -> bb1;
18-
}
19-
20-
bb1: {
21-
goto -> bb2;
22-
}
23-
24-
bb2: {
2517
return;
2618
}
2719
}

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

-8
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,6 @@
1414
}
1515

1616
bb0: {
17-
goto -> bb1;
18-
}
19-
20-
bb1: {
21-
goto -> bb2;
22-
}
23-
24-
bb2: {
2517
return;
2618
}
2719
}

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

-8
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,6 @@
1414
}
1515

1616
bb0: {
17-
goto -> bb1;
18-
}
19-
20-
bb1: {
21-
goto -> bb2;
22-
}
23-
24-
bb2: {
2517
return;
2618
}
2719
}

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

-8
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,6 @@
1414
}
1515

1616
bb0: {
17-
goto -> bb1;
18-
}
19-
20-
bb1: {
21-
goto -> bb2;
22-
}
23-
24-
bb2: {
2517
return;
2618
}
2719
}

0 commit comments

Comments
 (0)