@@ -9,10 +9,6 @@ use rustc_middle::ty::TyCtxt;
9
9
pub struct MultipleReturnTerminators ;
10
10
11
11
impl < ' tcx > MirPass < ' tcx > for MultipleReturnTerminators {
12
- fn is_enabled ( & self , sess : & rustc_session:: Session ) -> bool {
13
- sess. mir_opt_level ( ) >= 4
14
- }
15
-
16
12
fn run_pass ( & self , tcx : TyCtxt < ' tcx > , body : & mut Body < ' tcx > ) {
17
13
// find basic blocks with no statement and a return terminator
18
14
let mut bbs_simple_returns = BitSet :: new_empty ( body. basic_blocks . len ( ) ) ;
@@ -26,6 +22,10 @@ impl<'tcx> MirPass<'tcx> for MultipleReturnTerminators {
26
22
}
27
23
}
28
24
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
+
29
29
for bb in bbs {
30
30
if !tcx. consider_optimizing ( || format ! ( "MultipleReturnTerminators {:?} " , def_id) ) {
31
31
break ;
@@ -34,10 +34,13 @@ impl<'tcx> MirPass<'tcx> for MultipleReturnTerminators {
34
34
if let TerminatorKind :: Goto { target } = bb. terminator ( ) . kind {
35
35
if bbs_simple_returns. contains ( target) {
36
36
bb. terminator_mut ( ) . kind = TerminatorKind :: Return ;
37
+ optimized = true ;
37
38
}
38
39
}
39
40
}
40
41
41
- simplify:: remove_dead_blocks ( tcx, body)
42
+ if optimized {
43
+ simplify:: remove_dead_blocks ( tcx, body)
44
+ }
42
45
}
43
46
}
0 commit comments