Skip to content

Commit 74be0a9

Browse files
committed
Enable DestinationPropagation by default.
1 parent 8811344 commit 74be0a9

26 files changed

+590
-923
lines changed

compiler/rustc_mir_transform/src/dest_prop.rs

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -153,15 +153,7 @@ pub(super) struct DestinationPropagation;
153153

154154
impl<'tcx> crate::MirPass<'tcx> for DestinationPropagation {
155155
fn is_enabled(&self, sess: &rustc_session::Session) -> bool {
156-
// For now, only run at MIR opt level 3. Two things need to be changed before this can be
157-
// turned on by default:
158-
// 1. Because of the overeager removal of storage statements, this can cause stack space
159-
// regressions. This opt is not the place to fix this though, it's a more general
160-
// problem in MIR.
161-
// 2. Despite being an overall perf improvement, this still causes a 30% regression in
162-
// keccak. We can temporarily fix this by bounding function size, but in the long term
163-
// we should fix this by being smarter about invalidating analysis results.
164-
sess.mir_opt_level() >= 3
156+
sess.mir_opt_level() >= 2
165157
}
166158

167159
#[tracing::instrument(level = "trace", skip(self, tcx, body))]

compiler/rustc_mir_transform/src/lib.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,6 @@ declare_passes! {
156156
mod match_branches : MatchBranchSimplification;
157157
mod mentioned_items : MentionedItems;
158158
mod multiple_return_terminators : MultipleReturnTerminators;
159-
mod nrvo : RenameReturnPlace;
160159
mod post_drop_elaboration : CheckLiveDrops;
161160
mod prettify : ReorderBasicBlocks, ReorderLocals;
162161
mod promote_consts : PromoteTemps;
@@ -715,15 +714,14 @@ pub(crate) fn run_optimization_passes<'tcx>(tcx: TyCtxt<'tcx>, body: &mut Body<'
715714
&jump_threading::JumpThreading,
716715
&early_otherwise_branch::EarlyOtherwiseBranch,
717716
&simplify_comparison_integral::SimplifyComparisonIntegral,
718-
&dest_prop::DestinationPropagation,
719717
&o1(simplify_branches::SimplifyConstCondition::Final),
720718
&o1(remove_noop_landing_pads::RemoveNoopLandingPads),
721719
&o1(simplify::SimplifyCfg::Final),
722720
// After the last SimplifyCfg, because this wants one-block functions.
723721
&strip_debuginfo::StripDebugInfo,
724722
&copy_prop::CopyProp,
725723
&dead_store_elimination::DeadStoreElimination::Final,
726-
&nrvo::RenameReturnPlace,
724+
&dest_prop::DestinationPropagation,
727725
&simplify::SimplifyLocals::Final,
728726
&multiple_return_terminators::MultipleReturnTerminators,
729727
&large_enums::EnumSizeOpt { discrepancy: 128 },

compiler/rustc_mir_transform/src/nrvo.rs

Lines changed: 0 additions & 234 deletions
This file was deleted.

tests/mir-opt/nrvo_simple.nrvo.RenameReturnPlace.panic-abort.diff renamed to tests/mir-opt/dest-prop/nrvo_borrowed.nrvo.DestinationPropagation.panic-abort.diff

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
- // MIR for `nrvo` before RenameReturnPlace
2-
+ // MIR for `nrvo` after RenameReturnPlace
1+
- // MIR for `nrvo` before DestinationPropagation
2+
+ // MIR for `nrvo` after DestinationPropagation
33

44
fn nrvo(_1: for<'a> fn(&'a mut [u8; 1024])) -> [u8; 1024] {
55
debug init => _1;
@@ -10,32 +10,33 @@
1010
let mut _5: &mut [u8; 1024];
1111
let mut _6: &mut [u8; 1024];
1212
scope 1 {
13-
- debug buf => _2;
14-
+ debug buf => _0;
13+
debug buf => _2;
1514
}
1615

1716
bb0: {
18-
- StorageLive(_2);
19-
- _2 = [const 0_u8; 1024];
20-
+ _0 = [const 0_u8; 1024];
17+
StorageLive(_2);
18+
_2 = [const 0_u8; 1024];
2119
StorageLive(_3);
22-
StorageLive(_4);
23-
_4 = copy _1;
20+
- StorageLive(_4);
21+
- _4 = copy _1;
22+
+ nop;
23+
+ nop;
2424
StorageLive(_5);
2525
StorageLive(_6);
26-
- _6 = &mut _2;
27-
+ _6 = &mut _0;
26+
_6 = &mut _2;
2827
_5 = &mut (*_6);
29-
_3 = move _4(move _5) -> [return: bb1, unwind unreachable];
28+
- _3 = move _4(move _5) -> [return: bb1, unwind unreachable];
29+
+ _3 = move _1(move _5) -> [return: bb1, unwind unreachable];
3030
}
3131

3232
bb1: {
3333
StorageDead(_5);
34-
StorageDead(_4);
34+
- StorageDead(_4);
35+
+ nop;
3536
StorageDead(_6);
3637
StorageDead(_3);
37-
- _0 = copy _2;
38-
- StorageDead(_2);
38+
_0 = copy _2;
39+
StorageDead(_2);
3940
return;
4041
}
4142
}

tests/mir-opt/nrvo_simple.nrvo.RenameReturnPlace.panic-unwind.diff renamed to tests/mir-opt/dest-prop/nrvo_borrowed.nrvo.DestinationPropagation.panic-unwind.diff

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
- // MIR for `nrvo` before RenameReturnPlace
2-
+ // MIR for `nrvo` after RenameReturnPlace
1+
- // MIR for `nrvo` before DestinationPropagation
2+
+ // MIR for `nrvo` after DestinationPropagation
33

44
fn nrvo(_1: for<'a> fn(&'a mut [u8; 1024])) -> [u8; 1024] {
55
debug init => _1;
@@ -10,32 +10,33 @@
1010
let mut _5: &mut [u8; 1024];
1111
let mut _6: &mut [u8; 1024];
1212
scope 1 {
13-
- debug buf => _2;
14-
+ debug buf => _0;
13+
debug buf => _2;
1514
}
1615

1716
bb0: {
18-
- StorageLive(_2);
19-
- _2 = [const 0_u8; 1024];
20-
+ _0 = [const 0_u8; 1024];
17+
StorageLive(_2);
18+
_2 = [const 0_u8; 1024];
2119
StorageLive(_3);
22-
StorageLive(_4);
23-
_4 = copy _1;
20+
- StorageLive(_4);
21+
- _4 = copy _1;
22+
+ nop;
23+
+ nop;
2424
StorageLive(_5);
2525
StorageLive(_6);
26-
- _6 = &mut _2;
27-
+ _6 = &mut _0;
26+
_6 = &mut _2;
2827
_5 = &mut (*_6);
29-
_3 = move _4(move _5) -> [return: bb1, unwind continue];
28+
- _3 = move _4(move _5) -> [return: bb1, unwind continue];
29+
+ _3 = move _1(move _5) -> [return: bb1, unwind continue];
3030
}
3131

3232
bb1: {
3333
StorageDead(_5);
34-
StorageDead(_4);
34+
- StorageDead(_4);
35+
+ nop;
3536
StorageDead(_6);
3637
StorageDead(_3);
37-
- _0 = copy _2;
38-
- StorageDead(_2);
38+
_0 = copy _2;
39+
StorageDead(_2);
3940
return;
4041
}
4142
}

tests/mir-opt/nrvo_simple.rs renamed to tests/mir-opt/dest-prop/nrvo_borrowed.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
// skip-filecheck
22
// EMIT_MIR_FOR_EACH_PANIC_STRATEGY
3-
//@ test-mir-pass: RenameReturnPlace
3+
//@ test-mir-pass: DestinationPropagation
44

5-
// EMIT_MIR nrvo_simple.nrvo.RenameReturnPlace.diff
5+
// EMIT_MIR nrvo_borrowed.nrvo.DestinationPropagation.diff
66
fn nrvo(init: fn(&mut [u8; 1024])) -> [u8; 1024] {
77
let mut buf = [0; 1024];
88
init(&mut buf);

0 commit comments

Comments
 (0)