Skip to content

Commit 6fbd761

Browse files
committedFeb 5, 2024
Also turn moves into copies even if through projections.
1 parent c151ed4 commit 6fbd761

File tree

3 files changed

+6
-6
lines changed

3 files changed

+6
-6
lines changed
 

‎compiler/rustc_mir_transform/src/gvn.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1228,8 +1228,8 @@ impl<'tcx> MutVisitor<'tcx> for StorageRemover<'tcx> {
12281228

12291229
fn visit_operand(&mut self, operand: &mut Operand<'tcx>, _: Location) {
12301230
if let Operand::Move(place) = *operand
1231-
&& let Some(local) = place.as_local()
1232-
&& self.reused_locals.contains(local)
1231+
&& !place.is_indirect_first_projection()
1232+
&& self.reused_locals.contains(place.local)
12331233
{
12341234
*operand = Operand::Copy(place);
12351235
}

‎tests/mir-opt/gvn_copy_moves.fn0.GVN.diff

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
_3 = (_2,);
1818
_4 = _3;
1919
- _5 = fn1(move (_3.0: [u128; 6]), _4) -> [return: bb1, unwind unreachable];
20-
+ _5 = fn1(move (_3.0: [u128; 6]), _3) -> [return: bb1, unwind unreachable];
20+
+ _5 = fn1((_3.0: [u128; 6]), _3) -> [return: bb1, unwind unreachable];
2121
}
2222

2323
bb1: {

‎tests/mir-opt/separate_const_switch.identity.SeparateConstSwitch.diff

+3-3
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@
6666
_5 = ((_2 as Break).0: std::result::Result<std::convert::Infallible, i32>);
6767
StorageLive(_6);
6868
_6 = _5;
69-
_12 = move ((_5 as Err).0: i32);
69+
_12 = ((_5 as Err).0: i32);
7070
_0 = Result::<i32, i32>::Err(_12);
7171
StorageDead(_6);
7272
StorageDead(_2);
@@ -83,7 +83,7 @@
8383
}
8484

8585
bb4: {
86-
_10 = move ((_1 as Err).0: i32);
86+
_10 = ((_1 as Err).0: i32);
8787
StorageLive(_11);
8888
_11 = Result::<Infallible, i32>::Err(_10);
8989
_2 = ControlFlow::<Result<Infallible, i32>, i32>::Break(move _11);
@@ -92,7 +92,7 @@
9292
}
9393

9494
bb5: {
95-
_9 = move ((_1 as Ok).0: i32);
95+
_9 = ((_1 as Ok).0: i32);
9696
_2 = ControlFlow::<Result<Infallible, i32>, i32>::Continue(_9);
9797
goto -> bb3;
9898
}

0 commit comments

Comments
 (0)
Please sign in to comment.