Skip to content

Commit

Permalink
Enable DestinationPropagation by default.
Browse files Browse the repository at this point in the history
  • Loading branch information
cjgillot committed May 29, 2024
1 parent debd22d commit 5fa0ec6
Show file tree
Hide file tree
Showing 21 changed files with 373 additions and 661 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 @@ -160,7 +160,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 @@ -88,7 +88,6 @@ mod match_branches;
mod mentioned_items;
mod multiple_return_terminators;
mod normalize_array_len;
mod nrvo;
mod prettify;
mod promote_consts;
mod ref_prop;
Expand Down Expand Up @@ -607,13 +606,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
235 changes: 0 additions & 235 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
//@ test-mir-pass: RenameReturnPlace
//@ test-mir-pass: 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
Loading

0 comments on commit 5fa0ec6

Please sign in to comment.