Skip to content

Commit 35c8b0e

Browse files
committed
copy-prop: Remove unused self-assignment elimination
The assignments that are starting point for the copy propagation are removed separately. The copy propagation does not introduce self-assignments otherwise, so the code for self-assignments elimination is functionally inert. Remove it. No functional changes intended.
1 parent 2ee57d7 commit 35c8b0e

File tree

1 file changed

+0
-44
lines changed

1 file changed

+0
-44
lines changed

compiler/rustc_mir/src/transform/copy_prop.rs

-44
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,6 @@ impl<'tcx> MirPass<'tcx> for CopyPropagation {
4343
for dest_local in body.local_decls.indices() {
4444
if changed {
4545
def_use_analysis.analyze(body);
46-
if eliminate_self_assignments(body, &def_use_analysis) {
47-
def_use_analysis.analyze(body);
48-
}
4946
changed = false;
5047
}
5148

@@ -147,47 +144,6 @@ impl<'tcx> MirPass<'tcx> for CopyPropagation {
147144
}
148145
}
149146

150-
fn eliminate_self_assignments(body: &mut Body<'_>, def_use_analysis: &DefUseAnalysis) -> bool {
151-
let mut changed = false;
152-
153-
for dest_local in body.local_decls.indices() {
154-
let dest_use_info = def_use_analysis.local_info(dest_local);
155-
156-
for def in dest_use_info.defs_not_including_drop() {
157-
let location = def.location;
158-
if let Some(stmt) = body[location.block].statements.get(location.statement_index) {
159-
match &stmt.kind {
160-
StatementKind::Assign(box (
161-
place,
162-
Rvalue::Use(Operand::Copy(src_place) | Operand::Move(src_place)),
163-
)) => {
164-
if let (Some(local), Some(src_local)) =
165-
(place.as_local(), src_place.as_local())
166-
{
167-
if local == dest_local && dest_local == src_local {
168-
} else {
169-
continue;
170-
}
171-
} else {
172-
continue;
173-
}
174-
}
175-
_ => {
176-
continue;
177-
}
178-
}
179-
} else {
180-
continue;
181-
}
182-
debug!("deleting a self-assignment for {:?}", dest_local);
183-
body.make_statement_nop(location);
184-
changed = true;
185-
}
186-
}
187-
188-
changed
189-
}
190-
191147
enum Action<'tcx> {
192148
PropagateLocalCopy(Local),
193149
PropagateConstant(Constant<'tcx>),

0 commit comments

Comments
 (0)