Skip to content

Commit 8cf5fad

Browse files
committed
Auto merge of #142870 - tmiasko:copy-prop-early-exit, r=cjgillot
Leave from CopyProp early when there are no replacements r? cjgillot
2 parents 2801f9a + c353539 commit 8cf5fad

File tree

1 file changed

+10
-8
lines changed

1 file changed

+10
-8
lines changed

compiler/rustc_mir_transform/src/copy_prop.rs

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -33,24 +33,26 @@ impl<'tcx> crate::MirPass<'tcx> for CopyProp {
3333
debug!(borrowed_locals = ?ssa.borrowed_locals());
3434
debug!(copy_classes = ?ssa.copy_classes());
3535

36-
let fully_moved = fully_moved_locals(&ssa, body);
37-
debug!(?fully_moved);
38-
39-
let mut storage_to_remove = DenseBitSet::new_empty(fully_moved.domain_size());
36+
let mut any_replacement = false;
37+
let mut storage_to_remove = DenseBitSet::new_empty(body.local_decls.len());
4038
for (local, &head) in ssa.copy_classes().iter_enumerated() {
4139
if local != head {
40+
any_replacement = true;
4241
storage_to_remove.insert(head);
4342
}
4443
}
4544

46-
let any_replacement = ssa.copy_classes().iter_enumerated().any(|(l, &h)| l != h);
45+
if !any_replacement {
46+
return;
47+
}
48+
49+
let fully_moved = fully_moved_locals(&ssa, body);
50+
debug!(?fully_moved);
4751

4852
Replacer { tcx, copy_classes: ssa.copy_classes(), fully_moved, storage_to_remove }
4953
.visit_body_preserves_cfg(body);
5054

51-
if any_replacement {
52-
crate::simplify::remove_unused_definitions(body);
53-
}
55+
crate::simplify::remove_unused_definitions(body);
5456
}
5557

5658
fn is_required(&self) -> bool {

0 commit comments

Comments
 (0)