Skip to content

Commit

Permalink
Also turn moves into copies even if through projections.
Browse files Browse the repository at this point in the history
  • Loading branch information
cjgillot committed Feb 5, 2024
1 parent c151ed4 commit 6fbd761
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 6 deletions.
4 changes: 2 additions & 2 deletions compiler/rustc_mir_transform/src/gvn.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1228,8 +1228,8 @@ impl<'tcx> MutVisitor<'tcx> for StorageRemover<'tcx> {

fn visit_operand(&mut self, operand: &mut Operand<'tcx>, _: Location) {
if let Operand::Move(place) = *operand
&& let Some(local) = place.as_local()
&& self.reused_locals.contains(local)
&& !place.is_indirect_first_projection()
&& self.reused_locals.contains(place.local)
{
*operand = Operand::Copy(place);
}
Expand Down
2 changes: 1 addition & 1 deletion tests/mir-opt/gvn_copy_moves.fn0.GVN.diff
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
_3 = (_2,);
_4 = _3;
- _5 = fn1(move (_3.0: [u128; 6]), _4) -> [return: bb1, unwind unreachable];
+ _5 = fn1(move (_3.0: [u128; 6]), _3) -> [return: bb1, unwind unreachable];
+ _5 = fn1((_3.0: [u128; 6]), _3) -> [return: bb1, unwind unreachable];
}

bb1: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@
_5 = ((_2 as Break).0: std::result::Result<std::convert::Infallible, i32>);
StorageLive(_6);
_6 = _5;
_12 = move ((_5 as Err).0: i32);
_12 = ((_5 as Err).0: i32);
_0 = Result::<i32, i32>::Err(_12);
StorageDead(_6);
StorageDead(_2);
Expand All @@ -83,7 +83,7 @@
}

bb4: {
_10 = move ((_1 as Err).0: i32);
_10 = ((_1 as Err).0: i32);
StorageLive(_11);
_11 = Result::<Infallible, i32>::Err(_10);
_2 = ControlFlow::<Result<Infallible, i32>, i32>::Break(move _11);
Expand All @@ -92,7 +92,7 @@
}

bb5: {
_9 = move ((_1 as Ok).0: i32);
_9 = ((_1 as Ok).0: i32);
_2 = ControlFlow::<Result<Infallible, i32>, i32>::Continue(_9);
goto -> bb3;
}
Expand Down

0 comments on commit 6fbd761

Please sign in to comment.