Auto merge of #106908 - cjgillot:copyprop-ssa, r=oli-obk
Implement simple CopyPropagation based on SSA analysis This PR extracts the "copy propagation" logic from https://github.com/rust-lang/rust/pull/106285. MIR may produce chains of assignment between locals, like `_x = move? _y`. This PR attempts to remove such chains by unifying locals. The current implementation is a bit overzealous in turning moves into copies, and in removing storage statements.
This commit is contained in:
commit
2a4b00beaa
68 changed files with 1948 additions and 278 deletions
|
@ -328,7 +328,8 @@ impl<'a, 'tcx> MutVisitor<'tcx> for Merger<'a, 'tcx> {
|
|||
match &statement.kind {
|
||||
StatementKind::Assign(box (dest, rvalue)) => {
|
||||
match rvalue {
|
||||
Rvalue::Use(Operand::Copy(place) | Operand::Move(place)) => {
|
||||
Rvalue::CopyForDeref(place)
|
||||
| Rvalue::Use(Operand::Copy(place) | Operand::Move(place)) => {
|
||||
// These might've been turned into self-assignments by the replacement
|
||||
// (this includes the original statement we wanted to eliminate).
|
||||
if dest == place {
|
||||
|
@ -755,7 +756,7 @@ impl<'tcx> Visitor<'tcx> for FindAssignments<'_, '_, 'tcx> {
|
|||
fn visit_statement(&mut self, statement: &Statement<'tcx>, _: Location) {
|
||||
if let StatementKind::Assign(box (
|
||||
lhs,
|
||||
Rvalue::Use(Operand::Copy(rhs) | Operand::Move(rhs)),
|
||||
Rvalue::CopyForDeref(rhs) | Rvalue::Use(Operand::Copy(rhs) | Operand::Move(rhs)),
|
||||
)) = &statement.kind
|
||||
{
|
||||
let Some((src, dest)) = places_to_candidate_pair(*lhs, *rhs, self.body) else {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue