Skip to content

Commit 68abf63

Browse files
committed
Always enable MultipleReturnTerminators
1 parent 574b64a commit 68abf63

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

compiler/rustc_mir_transform/src/multiple_return_terminators.rs

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,6 @@ use rustc_middle::ty::TyCtxt;
99
pub struct MultipleReturnTerminators;
1010

1111
impl<'tcx> MirPass<'tcx> for MultipleReturnTerminators {
12-
fn is_enabled(&self, sess: &rustc_session::Session) -> bool {
13-
sess.mir_opt_level() >= 4
14-
}
15-
1612
fn run_pass(&self, tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) {
1713
// find basic blocks with no statement and a return terminator
1814
let mut bbs_simple_returns = BitSet::new_empty(body.basic_blocks.len());
@@ -26,6 +22,10 @@ impl<'tcx> MirPass<'tcx> for MultipleReturnTerminators {
2622
}
2723
}
2824

25+
// This pass usually doesn't fire, but when it does we want to remove any dead blocks it
26+
// creates. So we only look for dead blocks if it does anything.
27+
let mut optimized = false;
28+
2929
for bb in bbs {
3030
if !tcx.consider_optimizing(|| format!("MultipleReturnTerminators {:?} ", def_id)) {
3131
break;
@@ -34,10 +34,13 @@ impl<'tcx> MirPass<'tcx> for MultipleReturnTerminators {
3434
if let TerminatorKind::Goto { target } = bb.terminator().kind {
3535
if bbs_simple_returns.contains(target) {
3636
bb.terminator_mut().kind = TerminatorKind::Return;
37+
optimized = true;
3738
}
3839
}
3940
}
4041

41-
simplify::remove_dead_blocks(tcx, body)
42+
if optimized {
43+
simplify::remove_dead_blocks(tcx, body)
44+
}
4245
}
4346
}

0 commit comments

Comments
 (0)