Skip to content

Commit 3be2167

Browse files
committed
CopyProp cleanups
1 parent 0b0011c commit 3be2167

File tree

1 file changed

+4
-8
lines changed

1 file changed

+4
-8
lines changed

compiler/rustc_mir_transform/src/copy_prop.rs

+4-8
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ fn propagate_ssa<'tcx>(tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) {
4848
}
4949
}
5050

51-
let any_replacement = ssa.copy_classes().iter_enumerated().any(|(l, &h)| l != h);
51+
let any_replacement = !storage_to_remove.is_empty() || !const_locals.is_empty();
5252

5353
Replacer {
5454
tcx,
@@ -79,9 +79,7 @@ fn fully_moved_locals(ssa: &SsaLocals, body: &Body<'_>) -> BitSet<Local> {
7979
let mut fully_moved = BitSet::new_filled(body.local_decls.len());
8080

8181
for (_, rvalue, _) in ssa.assignments(body) {
82-
let (Rvalue::Use(Operand::Copy(place) | Operand::Move(place))
83-
| Rvalue::CopyForDeref(place)) = rvalue
84-
else {
82+
let (Rvalue::Use(Operand::Copy(place)) | Rvalue::CopyForDeref(place)) = rvalue else {
8583
continue;
8684
};
8785

@@ -173,11 +171,9 @@ impl<'tcx> MutVisitor<'tcx> for Replacer<'_, 'tcx> {
173171
}
174172

175173
fn visit_operand(&mut self, operand: &mut Operand<'tcx>, loc: Location) {
176-
if let Operand::Move(place) = *operand
174+
if let Operand::Move(place) = *operand {
177175
// A move out of a projection of a copy is equivalent to a copy of the original projection.
178-
&& !place.is_indirect_first_projection()
179-
{
180-
if !self.fully_moved.contains(place.local) {
176+
if !place.is_indirect_first_projection() && !self.fully_moved.contains(place.local) {
181177
*operand = Operand::Copy(place);
182178
} else if let Some(local) = place.as_local()
183179
&& let Some(val) = self.const_locals.get(&local)

0 commit comments

Comments
 (0)