Skip to content

Commit

Permalink
Auto merge of rust-lang#115105 - cjgillot:dest-prop-default, r=<try>
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
bors committed Jan 18, 2024
2 parents 25f8d01 + dca02d6 commit a3b873c
Show file tree
Hide file tree
Showing 16 changed files with 320 additions and 580 deletions.
2 changes: 1 addition & 1 deletion compiler/rustc_mir_transform/src/dest_prop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ impl<'tcx> MirPass<'tcx> for DestinationPropagation {
// 2. Despite being an overall perf improvement, this still causes a 30% regression in
// keccak. We can temporarily fix this by bounding function size, but in the long term
// we should fix this by being smarter about invalidating analysis results.
sess.mir_opt_level() >= 3
sess.mir_opt_level() >= 2
}

fn run_pass(&self, tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) {
Expand Down
4 changes: 1 addition & 3 deletions compiler/rustc_mir_transform/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,6 @@ mod lower_slice_len;
mod match_branches;
mod multiple_return_terminators;
mod normalize_array_len;
mod nrvo;
mod prettify;
mod promote_consts;
mod ref_prop;
Expand Down Expand Up @@ -609,13 +608,12 @@ fn run_optimization_passes<'tcx>(tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) {
&jump_threading::JumpThreading,
&early_otherwise_branch::EarlyOtherwiseBranch,
&simplify_comparison_integral::SimplifyComparisonIntegral,
&dest_prop::DestinationPropagation,
&o1(simplify_branches::SimplifyConstCondition::Final),
&o1(remove_noop_landing_pads::RemoveNoopLandingPads),
&o1(simplify::SimplifyCfg::Final),
&copy_prop::CopyProp,
&dead_store_elimination::DeadStoreElimination::Final,
&nrvo::RenameReturnPlace,
&dest_prop::DestinationPropagation,
&simplify::SimplifyLocals::Final,
&multiple_return_terminators::MultipleReturnTerminators,
&deduplicate_blocks::DeduplicateBlocks,
Expand Down
237 changes: 0 additions & 237 deletions compiler/rustc_mir_transform/src/nrvo.rs

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
- // MIR for `nrvo` before RenameReturnPlace
+ // MIR for `nrvo` after RenameReturnPlace
- // MIR for `nrvo` before DestinationPropagation
+ // MIR for `nrvo` after DestinationPropagation

fn nrvo(_1: for<'a> fn(&'a mut [u8; 1024])) -> [u8; 1024] {
debug init => _1;
Expand All @@ -10,32 +10,33 @@
let mut _5: &mut [u8; 1024];
let mut _6: &mut [u8; 1024];
scope 1 {
- debug buf => _2;
+ debug buf => _0;
debug buf => _2;
}

bb0: {
- StorageLive(_2);
- _2 = [const 0_u8; 1024];
+ _0 = [const 0_u8; 1024];
StorageLive(_2);
_2 = [const 0_u8; 1024];
StorageLive(_3);
StorageLive(_4);
_4 = _1;
- StorageLive(_4);
- _4 = _1;
+ nop;
+ nop;
StorageLive(_5);
StorageLive(_6);
- _6 = &mut _2;
+ _6 = &mut _0;
_6 = &mut _2;
_5 = &mut (*_6);
_3 = move _4(move _5) -> [return: bb1, unwind unreachable];
- _3 = move _4(move _5) -> [return: bb1, unwind unreachable];
+ _3 = move _1(move _5) -> [return: bb1, unwind unreachable];
}

bb1: {
StorageDead(_5);
StorageDead(_4);
- StorageDead(_4);
+ nop;
StorageDead(_6);
StorageDead(_3);
- _0 = _2;
- StorageDead(_2);
_0 = _2;
StorageDead(_2);
return;
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
- // MIR for `nrvo` before RenameReturnPlace
+ // MIR for `nrvo` after RenameReturnPlace
- // MIR for `nrvo` before DestinationPropagation
+ // MIR for `nrvo` after DestinationPropagation

fn nrvo(_1: for<'a> fn(&'a mut [u8; 1024])) -> [u8; 1024] {
debug init => _1;
Expand All @@ -10,32 +10,33 @@
let mut _5: &mut [u8; 1024];
let mut _6: &mut [u8; 1024];
scope 1 {
- debug buf => _2;
+ debug buf => _0;
debug buf => _2;
}

bb0: {
- StorageLive(_2);
- _2 = [const 0_u8; 1024];
+ _0 = [const 0_u8; 1024];
StorageLive(_2);
_2 = [const 0_u8; 1024];
StorageLive(_3);
StorageLive(_4);
_4 = _1;
- StorageLive(_4);
- _4 = _1;
+ nop;
+ nop;
StorageLive(_5);
StorageLive(_6);
- _6 = &mut _2;
+ _6 = &mut _0;
_6 = &mut _2;
_5 = &mut (*_6);
_3 = move _4(move _5) -> [return: bb1, unwind continue];
- _3 = move _4(move _5) -> [return: bb1, unwind continue];
+ _3 = move _1(move _5) -> [return: bb1, unwind continue];
}

bb1: {
StorageDead(_5);
StorageDead(_4);
- StorageDead(_4);
+ nop;
StorageDead(_6);
StorageDead(_3);
- _0 = _2;
- StorageDead(_2);
_0 = _2;
StorageDead(_2);
return;
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
// skip-filecheck
// EMIT_MIR_FOR_EACH_PANIC_STRATEGY
// unit-test: RenameReturnPlace
// unit-test: DestinationPropagation

// EMIT_MIR nrvo_simple.nrvo.RenameReturnPlace.diff
// EMIT_MIR nrvo_borrowed.nrvo.DestinationPropagation.diff
fn nrvo(init: fn(&mut [u8; 1024])) -> [u8; 1024] {
let mut buf = [0; 1024];
init(&mut buf);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
bb0: {
StorageLive(_1);
StorageLive(_2);
_2 = const 1_u32;
nop;
_1 = Un { us: const 1_u32 };
StorageDead(_2);
StorageLive(_3);
Expand Down
Loading

0 comments on commit a3b873c

Please sign in to comment.