Skip to content

Commit e792ee8

Browse files
committed
Add more simplify passes.
1 parent 4a591aa commit e792ee8

7 files changed

+10
-36
lines changed

compiler/rustc_mir_transform/src/instsimplify.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
33
use crate::simplify::simplify_duplicate_switch_targets;
44
use rustc_hir::def::DefKind;
5-
use rustc_index::IndexVec;
65
use rustc_middle::mir::*;
76
use rustc_middle::ty::layout::ValidityRequirement;
87
use rustc_middle::ty::{self, GenericArgsRef, ParamEnv, Ty, TyCtxt};
@@ -332,7 +331,7 @@ impl<'tcx> InstSimplifyContext<'tcx, '_> {
332331
let kind = AggregateKind::Adt(adt_def.did(), variant_index, generics, None, None);
333332

334333
let args = std::mem::take(args);
335-
let fields = IndexVec::from_raw(args);
334+
let fields = args.into_iter().map(|n| n.node).collect();
336335

337336
let statement = Statement {
338337
kind: StatementKind::Assign(Box::new((

compiler/rustc_mir_transform/src/lib.rs

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