@@ -16,12 +16,17 @@ pub struct DeduplicateBlocks;
16
16
17
17
impl < ' tcx > MirPass < ' tcx > for DeduplicateBlocks {
18
18
fn is_enabled ( & self , sess : & rustc_session:: Session ) -> bool {
19
- sess. mir_opt_level ( ) >= 4
19
+ sess. mir_opt_level ( ) >= 1
20
20
}
21
21
22
22
fn run_pass ( & self , tcx : TyCtxt < ' tcx > , body : & mut Body < ' tcx > ) {
23
+ // Basic blocks can get really big, so to avoid checking for duplicates in basic blocks
24
+ // that are unlikely to have duplicates, we stop early. The early bail number has been
25
+ // found experimentally by eprintln while compiling the crates in the rustc-perf suite.
26
+ let limit = if tcx. sess . mir_opt_level ( ) < 3 { 3 } else { 10 } ;
27
+
23
28
debug ! ( "Running DeduplicateBlocks on `{:?}`" , body. source) ;
24
- let duplicates = find_duplicates ( body) ;
29
+ let duplicates = find_duplicates ( body, limit ) ;
25
30
let has_opts_to_apply = !duplicates. is_empty ( ) ;
26
31
27
32
if has_opts_to_apply {
@@ -54,7 +59,7 @@ impl<'tcx> MutVisitor<'tcx> for OptApplier<'tcx> {
54
59
}
55
60
}
56
61
57
- fn find_duplicates ( body : & Body < ' _ > ) -> FxHashMap < BasicBlock , BasicBlock > {
62
+ fn find_duplicates ( body : & Body < ' _ > , limit : usize ) -> FxHashMap < BasicBlock , BasicBlock > {
58
63
let mut duplicates = FxHashMap :: default ( ) ;
59
64
60
65
let bbs_to_go_through =
@@ -72,10 +77,7 @@ fn find_duplicates(body: &Body<'_>) -> FxHashMap<BasicBlock, BasicBlock> {
72
77
// with replacement bb3.
73
78
// When the duplicates are removed, we will end up with only bb3.
74
79
for ( bb, bbd) in body. basic_blocks . iter_enumerated ( ) . rev ( ) . filter ( |( _, bbd) | !bbd. is_cleanup ) {
75
- // Basic blocks can get really big, so to avoid checking for duplicates in basic blocks
76
- // that are unlikely to have duplicates, we stop early. The early bail number has been
77
- // found experimentally by eprintln while compiling the crates in the rustc-perf suite.
78
- if bbd. statements . len ( ) > 10 {
80
+ if bbd. statements . len ( ) > limit {
79
81
continue ;
80
82
}
81
83
0 commit comments