Skip to content

Commit

Permalink
rustc_mir::transform::simplify - remove nops first
Browse files Browse the repository at this point in the history
Removing nops can allow more basic blocks to be merged, but merging
basic blocks can't allow for more nops to be removed, so we should
remove nops first.

This doesn't matter *that* much, because normally we run SimplifyCfg
several times, but there's no reason not to do it.
  • Loading branch information
arielb1 committed Jul 31, 2017
1 parent ca3105c commit 5b99523
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 16 deletions.
4 changes: 2 additions & 2 deletions src/librustc_mir/transform/simplify.rs
Expand Up @@ -105,6 +105,8 @@ impl<'a, 'tcx: 'a> CfgSimplifier<'a, 'tcx> {
}

pub fn simplify(mut self) {
self.strip_nops();

loop {
let mut changed = false;

Expand Down Expand Up @@ -141,8 +143,6 @@ impl<'a, 'tcx: 'a> CfgSimplifier<'a, 'tcx> {

if !changed { break }
}

self.strip_nops()
}

// Collapse a goto chain starting from `start`
Expand Down
22 changes: 8 additions & 14 deletions src/test/mir-opt/basic_assignment.rs
Expand Up @@ -50,10 +50,10 @@ fn main() {
// StorageLive(_5);
// StorageLive(_6);
// _6 = _4;
// replace(_5 <- _6) -> [return: bb1, unwind: bb7];
// replace(_5 <- _6) -> [return: bb1, unwind: bb5];
// }
// bb1: {
// drop(_6) -> [return: bb8, unwind: bb5];
// drop(_6) -> [return: bb6, unwind: bb4];
// }
// bb2: {
// resume;
Expand All @@ -62,27 +62,21 @@ fn main() {
// drop(_4) -> bb2;
// }
// bb4: {
// goto -> bb3;
// drop(_5) -> bb3;
// }
// bb5: {
// drop(_5) -> bb4;
// drop(_6) -> bb4;
// }
// bb6: {
// goto -> bb5;
// }
// bb7: {
// drop(_6) -> bb6;
// }
// bb8: {
// StorageDead(_6);
// _0 = ();
// drop(_5) -> [return: bb9, unwind: bb3];
// drop(_5) -> [return: bb7, unwind: bb3];
// }
// bb9: {
// bb7: {
// StorageDead(_5);
// drop(_4) -> bb10;
// drop(_4) -> bb8;
// }
// bb10: {
// bb8: {
// StorageDead(_4);
// StorageDead(_2);
// StorageDead(_1);
Expand Down

0 comments on commit 5b99523

Please sign in to comment.