Skip to content

Commit

Permalink
Rollup merge of rust-lang#36959 - arielb1:simplify-cfg-fixes, r=eddyb
Browse files Browse the repository at this point in the history
fix pred_count accounting in SimplifyCfg

r? @eddyb
  • Loading branch information
Jonathan Turner authored Oct 6, 2016
2 parents 534a2b5 + bfdf437 commit 9f1089b
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 10 deletions.
15 changes: 13 additions & 2 deletions src/librustc_mir/transform/simplify_cfg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ impl<'a> SimplifyCfg<'a> {

impl<'l, 'tcx> MirPass<'tcx> for SimplifyCfg<'l> {
fn run_pass<'a>(&mut self, _tcx: TyCtxt<'a, 'tcx, 'tcx>, _src: MirSource, mir: &mut Mir<'tcx>) {
debug!("SimplifyCfg({:?}) - simplifying {:?}", self.label, mir);
CfgSimplifier::new(mir).simplify();
remove_dead_blocks(mir);

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

// we can't use mir.predecessors() here because that counts
// dead blocks, which we don't want to.
pred_count[START_BLOCK] = 1;

for (_, data) in traversal::preorder(mir) {
if let Some(ref term) = data.terminator {
for &tgt in term.successors().iter() {
Expand Down Expand Up @@ -157,8 +160,16 @@ impl<'a, 'tcx: 'a> CfgSimplifier<'a, 'tcx> {
debug!("collapsing goto chain from {:?} to {:?}", *start, target);

*changed |= *start != target;
self.pred_count[target] += 1;
self.pred_count[*start] -= 1;

if self.pred_count[*start] == 1 {
// This is the last reference to *start, so the pred-count to
// to target is moved into the current block.
self.pred_count[*start] = 0;
} else {
self.pred_count[target] += 1;
self.pred_count[*start] -= 1;
}

*start = target;
}

Expand Down
4 changes: 2 additions & 2 deletions src/test/mir-opt/deaggregator_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ fn main() {}
// _2 = _1;
// _3 = _2;
// _0 = Baz { x: _3, y: const F32(0), z: const false };
// goto -> bb1;
// return;
// }
// END rustc.node13.Deaggregator.before.mir
// START rustc.node13.Deaggregator.after.mir
Expand All @@ -36,6 +36,6 @@ fn main() {}
// (_0.0: usize) = _3;
// (_0.1: f32) = const F32(0);
// (_0.2: bool) = const false;
// goto -> bb1;
// return;
// }
// END rustc.node13.Deaggregator.after.mir
4 changes: 2 additions & 2 deletions src/test/mir-opt/deaggregator_test_enum.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ fn main() {
// _2 = _1;
// _3 = _2;
// _0 = Baz::Foo { x: _3 };
// goto -> bb1;
// return;
// }
// END rustc.node10.Deaggregator.before.mir
// START rustc.node10.Deaggregator.after.mir
Expand All @@ -40,6 +40,6 @@ fn main() {
// _3 = _2;
// ((_0 as Foo).0: usize) = _3;
// discriminant(_0) = 1;
// goto -> bb1;
// return;
// }
// END rustc.node10.Deaggregator.after.mir
4 changes: 0 additions & 4 deletions src/test/mir-opt/storage_ranges.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,6 @@ fn main() {
// _0 = ();
// StorageDead(_6);
// StorageDead(_1);
// goto -> bb1;
// }
//
// bb1: {
// return;
// }
// END rustc.node4.TypeckMir.before.mir

0 comments on commit 9f1089b

Please sign in to comment.