Rollup merge of #36959 - arielb1:simplify-cfg-fixes, r=eddyb
fix pred_count accounting in SimplifyCfg r? @eddyb
This commit is contained in:
commit
9f1089b56f
@ -50,6 +50,7 @@ impl<'a> SimplifyCfg<'a> {
|
|||||||
|
|
||||||
impl<'l, 'tcx> MirPass<'tcx> for SimplifyCfg<'l> {
|
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>) {
|
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();
|
CfgSimplifier::new(mir).simplify();
|
||||||
remove_dead_blocks(mir);
|
remove_dead_blocks(mir);
|
||||||
|
|
||||||
@ -78,6 +79,8 @@ impl<'a, 'tcx: 'a> CfgSimplifier<'a, 'tcx> {
|
|||||||
|
|
||||||
// we can't use mir.predecessors() here because that counts
|
// we can't use mir.predecessors() here because that counts
|
||||||
// dead blocks, which we don't want to.
|
// dead blocks, which we don't want to.
|
||||||
|
pred_count[START_BLOCK] = 1;
|
||||||
|
|
||||||
for (_, data) in traversal::preorder(mir) {
|
for (_, data) in traversal::preorder(mir) {
|
||||||
if let Some(ref term) = data.terminator {
|
if let Some(ref term) = data.terminator {
|
||||||
for &tgt in term.successors().iter() {
|
for &tgt in term.successors().iter() {
|
||||||
@ -157,8 +160,16 @@ impl<'a, 'tcx: 'a> CfgSimplifier<'a, 'tcx> {
|
|||||||
debug!("collapsing goto chain from {:?} to {:?}", *start, target);
|
debug!("collapsing goto chain from {:?} to {:?}", *start, target);
|
||||||
|
|
||||||
*changed |= *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;
|
*start = target;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -26,7 +26,7 @@ fn main() {}
|
|||||||
// _2 = _1;
|
// _2 = _1;
|
||||||
// _3 = _2;
|
// _3 = _2;
|
||||||
// _0 = Baz { x: _3, y: const F32(0), z: const false };
|
// _0 = Baz { x: _3, y: const F32(0), z: const false };
|
||||||
// goto -> bb1;
|
// return;
|
||||||
// }
|
// }
|
||||||
// END rustc.node13.Deaggregator.before.mir
|
// END rustc.node13.Deaggregator.before.mir
|
||||||
// START rustc.node13.Deaggregator.after.mir
|
// START rustc.node13.Deaggregator.after.mir
|
||||||
@ -36,6 +36,6 @@ fn main() {}
|
|||||||
// (_0.0: usize) = _3;
|
// (_0.0: usize) = _3;
|
||||||
// (_0.1: f32) = const F32(0);
|
// (_0.1: f32) = const F32(0);
|
||||||
// (_0.2: bool) = const false;
|
// (_0.2: bool) = const false;
|
||||||
// goto -> bb1;
|
// return;
|
||||||
// }
|
// }
|
||||||
// END rustc.node13.Deaggregator.after.mir
|
// END rustc.node13.Deaggregator.after.mir
|
||||||
|
@ -31,7 +31,7 @@ fn main() {
|
|||||||
// _2 = _1;
|
// _2 = _1;
|
||||||
// _3 = _2;
|
// _3 = _2;
|
||||||
// _0 = Baz::Foo { x: _3 };
|
// _0 = Baz::Foo { x: _3 };
|
||||||
// goto -> bb1;
|
// return;
|
||||||
// }
|
// }
|
||||||
// END rustc.node10.Deaggregator.before.mir
|
// END rustc.node10.Deaggregator.before.mir
|
||||||
// START rustc.node10.Deaggregator.after.mir
|
// START rustc.node10.Deaggregator.after.mir
|
||||||
@ -40,6 +40,6 @@ fn main() {
|
|||||||
// _3 = _2;
|
// _3 = _2;
|
||||||
// ((_0 as Foo).0: usize) = _3;
|
// ((_0 as Foo).0: usize) = _3;
|
||||||
// discriminant(_0) = 1;
|
// discriminant(_0) = 1;
|
||||||
// goto -> bb1;
|
// return;
|
||||||
// }
|
// }
|
||||||
// END rustc.node10.Deaggregator.after.mir
|
// END rustc.node10.Deaggregator.after.mir
|
||||||
|
@ -38,10 +38,6 @@ fn main() {
|
|||||||
// _0 = ();
|
// _0 = ();
|
||||||
// StorageDead(_6);
|
// StorageDead(_6);
|
||||||
// StorageDead(_1);
|
// StorageDead(_1);
|
||||||
// goto -> bb1;
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// bb1: {
|
|
||||||
// return;
|
// return;
|
||||||
// }
|
// }
|
||||||
// END rustc.node4.TypeckMir.before.mir
|
// END rustc.node4.TypeckMir.before.mir
|
||||||
|
Loading…
Reference in New Issue
Block a user