@@ -16,12 +16,22 @@ 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
23
debug ! ( "Running DeduplicateBlocks on `{:?}`" , body. source) ;
24
- let duplicates = find_duplicates ( body) ;
24
+
25
+ let limit = if tcx. sess . mir_opt_level ( ) < 3 {
26
+ 0
27
+ } else {
28
+ // Basic blocks can get really big, so to avoid checking for duplicates in basic blocks
29
+ // that are unlikely to have duplicates, we stop early. The early bail number has been
30
+ // found experimentally by eprintln while compiling the crates in the rustc-perf suite.
31
+ 10
32
+ } ;
33
+
34
+ let duplicates = find_duplicates ( body, limit) ;
25
35
let has_opts_to_apply = !duplicates. is_empty ( ) ;
26
36
27
37
if has_opts_to_apply {
@@ -54,7 +64,7 @@ impl<'tcx> MutVisitor<'tcx> for OptApplier<'tcx> {
54
64
}
55
65
}
56
66
57
- fn find_duplicates ( body : & Body < ' _ > ) -> FxHashMap < BasicBlock , BasicBlock > {
67
+ fn find_duplicates ( body : & Body < ' _ > , limit : usize ) -> FxHashMap < BasicBlock , BasicBlock > {
58
68
let mut duplicates = FxHashMap :: default ( ) ;
59
69
60
70
let bbs_to_go_through =
@@ -72,10 +82,7 @@ fn find_duplicates(body: &Body<'_>) -> FxHashMap<BasicBlock, BasicBlock> {
72
82
// with replacement bb3.
73
83
// When the duplicates are removed, we will end up with only bb3.
74
84
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 {
85
+ if bbd. statements . len ( ) > limit {
79
86
continue ;
80
87
}
81
88
0 commit comments