Skip to content

Commit cfb7304

Browse files
committed
Auto merge of rust-lang#115105 - cjgillot:dest-prop-default, r=oli-obk
Enable DestinationPropagation by default. ~~Based on rust-lang#115291 This PR proposes to enable the destination propagation pass by default. This pass is meant to reduce the amount of copies present in MIR. At the same time, this PR removes the `RenameReturnPlace` pass, as it is currently unsound. `DestinationPropagation` is not limited to `_0`, but does not handle borrowed locals.
2 parents 91c0823 + 5fa0ec6 commit cfb7304

21 files changed

+373
-661
lines changed

compiler/rustc_mir_transform/src/dest_prop.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ impl<'tcx> MirPass<'tcx> for DestinationPropagation {
160160
// 2. Despite being an overall perf improvement, this still causes a 30% regression in
161161
// keccak. We can temporarily fix this by bounding function size, but in the long term
162162
// we should fix this by being smarter about invalidating analysis results.
163-
sess.mir_opt_level() >= 3
163+
sess.mir_opt_level() >= 2
164164
}
165165

166166
fn run_pass(&self, tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) {

compiler/rustc_mir_transform/src/lib.rs

+1-3
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,6 @@ mod match_branches;
8888
mod mentioned_items;
8989
mod multiple_return_terminators;
9090
mod normalize_array_len;
91-
mod nrvo;
9291
mod prettify;
9392
mod promote_consts;
9493
mod ref_prop;
@@ -608,13 +607,12 @@ fn run_optimization_passes<'tcx>(tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) {
608607
&jump_threading::JumpThreading,
609608
&early_otherwise_branch::EarlyOtherwiseBranch,
610609
&simplify_comparison_integral::SimplifyComparisonIntegral,
611-
&dest_prop::DestinationPropagation,
612610
&o1(simplify_branches::SimplifyConstCondition::Final),
613611
&o1(remove_noop_landing_pads::RemoveNoopLandingPads),
614612
&o1(simplify::SimplifyCfg::Final),
615613
&copy_prop::CopyProp,
616614
&dead_store_elimination::DeadStoreElimination::Final,
617-
&nrvo::RenameReturnPlace,
615+
&dest_prop::DestinationPropagation,
618616
&simplify::SimplifyLocals::Final,
619617
&multiple_return_terminators::MultipleReturnTerminators,
620618
&deduplicate_blocks::DeduplicateBlocks,

compiler/rustc_mir_transform/src/nrvo.rs

-235
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

+16-15
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 = _1;
20+
- StorageLive(_4);
21+
- _4 = _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 = _2;
38-
- StorageDead(_2);
38+
_0 = _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

+16-15
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 = _1;
20+
- StorageLive(_4);
21+
- _4 = _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 = _2;
38-
- StorageDead(_2);
38+
_0 = _2;
39+
StorageDead(_2);
3940
return;
4041
}
4142
}

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

+2-2
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)