Skip to content

Commit ee29825

Browse files
committed
Enable DeduplicateBlocks
1 parent b1691f6 commit ee29825

File tree

1 file changed

+9
-7
lines changed

1 file changed

+9
-7
lines changed

compiler/rustc_mir_transform/src/deduplicate_blocks.rs

+9-7
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,17 @@ pub struct DeduplicateBlocks;
1616

1717
impl<'tcx> MirPass<'tcx> for DeduplicateBlocks {
1818
fn is_enabled(&self, sess: &rustc_session::Session) -> bool {
19-
sess.mir_opt_level() >= 4
19+
sess.mir_opt_level() >= 1
2020
}
2121

2222
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+
2328
debug!("Running DeduplicateBlocks on `{:?}`", body.source);
24-
let duplicates = find_duplicates(body);
29+
let duplicates = find_duplicates(body, limit);
2530
let has_opts_to_apply = !duplicates.is_empty();
2631

2732
if has_opts_to_apply {
@@ -54,7 +59,7 @@ impl<'tcx> MutVisitor<'tcx> for OptApplier<'tcx> {
5459
}
5560
}
5661

57-
fn find_duplicates(body: &Body<'_>) -> FxHashMap<BasicBlock, BasicBlock> {
62+
fn find_duplicates(body: &Body<'_>, limit: usize) -> FxHashMap<BasicBlock, BasicBlock> {
5863
let mut duplicates = FxHashMap::default();
5964

6065
let bbs_to_go_through =
@@ -72,10 +77,7 @@ fn find_duplicates(body: &Body<'_>) -> FxHashMap<BasicBlock, BasicBlock> {
7277
// with replacement bb3.
7378
// When the duplicates are removed, we will end up with only bb3.
7479
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 {
7981
continue;
8082
}
8183

0 commit comments

Comments
 (0)