@@ -954,7 +954,7 @@ impl<'body, 'a, 'tcx> VnState<'body, 'a, 'tcx> {
954
954
955
955
match self . compute_place_value ( * place, location) {
956
956
Ok ( value) => {
957
- if let Some ( new_place) = self . try_as_place ( value, location, true )
957
+ if let Some ( new_place) = self . try_as_place ( value, location, false )
958
958
&& ( new_place. local != place. local
959
959
|| new_place. projection . len ( ) < place. projection . len ( ) )
960
960
{
@@ -997,7 +997,6 @@ impl<'body, 'a, 'tcx> VnState<'body, 'a, 'tcx> {
997
997
#[ instrument( level = "trace" , skip( self ) , ret) ]
998
998
fn simplify_rvalue (
999
999
& mut self ,
1000
- lhs : & Place < ' tcx > ,
1001
1000
rvalue : & mut Rvalue < ' tcx > ,
1002
1001
location : Location ,
1003
1002
) -> Option < VnIndex > {
@@ -1017,7 +1016,7 @@ impl<'body, 'a, 'tcx> VnState<'body, 'a, 'tcx> {
1017
1016
Value :: Repeat ( op, amount)
1018
1017
}
1019
1018
Rvalue :: NullaryOp ( op, ty) => Value :: NullaryOp ( op, ty) ,
1020
- Rvalue :: Aggregate ( ..) => return self . simplify_aggregate ( lhs , rvalue, location) ,
1019
+ Rvalue :: Aggregate ( ..) => return self . simplify_aggregate ( rvalue, location) ,
1021
1020
Rvalue :: Ref ( _, borrow_kind, ref mut place) => {
1022
1021
self . simplify_place_projection ( place, location) ;
1023
1022
return self . new_pointer ( * place, AddressKind :: Ref ( borrow_kind) ) ;
@@ -1125,7 +1124,6 @@ impl<'body, 'a, 'tcx> VnState<'body, 'a, 'tcx> {
1125
1124
1126
1125
fn simplify_aggregate (
1127
1126
& mut self ,
1128
- lhs : & Place < ' tcx > ,
1129
1127
rvalue : & mut Rvalue < ' tcx > ,
1130
1128
location : Location ,
1131
1129
) -> Option < VnIndex > {
@@ -1205,15 +1203,6 @@ impl<'body, 'a, 'tcx> VnState<'body, 'a, 'tcx> {
1205
1203
}
1206
1204
1207
1205
if let Some ( value) = self . simplify_aggregate_to_copy ( ty, variant_index, & fields) {
1208
- // Allow introducing places with non-constant offsets, as those are still better than
1209
- // reconstructing an aggregate. But avoid creating `*a = copy (*b)`, as they might be
1210
- // aliases resulting in overlapping assignments.
1211
- let allow_complex_projection =
1212
- lhs. projection [ ..] . iter ( ) . all ( PlaceElem :: is_stable_offset) ;
1213
- if let Some ( place) = self . try_as_place ( value, location, allow_complex_projection) {
1214
- self . reused_locals . insert ( place. local ) ;
1215
- * rvalue = Rvalue :: Use ( Operand :: Copy ( place) ) ;
1216
- }
1217
1206
return Some ( value) ;
1218
1207
}
1219
1208
@@ -1859,13 +1848,21 @@ impl<'tcx> MutVisitor<'tcx> for VnState<'_, '_, 'tcx> {
1859
1848
) {
1860
1849
self . simplify_place_projection ( lhs, location) ;
1861
1850
1862
- let value = self . simplify_rvalue ( lhs , rvalue, location) ;
1851
+ let value = self . simplify_rvalue ( rvalue, location) ;
1863
1852
if let Some ( value) = value {
1853
+ // Allow introducing places with non-constant offsets, as those are still better than
1854
+ // reconstructing an aggregate. But avoid creating `*a = copy (*b)`, as they might be
1855
+ // aliases resulting in overlapping assignments.
1856
+ let allow_complex_projection =
1857
+ lhs. projection [ ..] . iter ( ) . all ( PlaceElem :: is_stable_offset) ;
1858
+
1864
1859
if let Some ( const_) = self . try_as_constant ( value) {
1865
1860
* rvalue = Rvalue :: Use ( Operand :: Constant ( Box :: new ( const_) ) ) ;
1866
- } else if let Some ( place) = self . try_as_place ( value, location, false )
1861
+ } else if let Some ( place) = self . try_as_place ( value, location, allow_complex_projection )
1867
1862
&& * rvalue != Rvalue :: Use ( Operand :: Move ( place) )
1868
1863
&& * rvalue != Rvalue :: Use ( Operand :: Copy ( place) )
1864
+ // Avoid introducing overlapping assignments to the same local.
1865
+ && place. local != lhs. local
1869
1866
{
1870
1867
* rvalue = Rvalue :: Use ( Operand :: Copy ( place) ) ;
1871
1868
self . reused_locals . insert ( place. local ) ;
0 commit comments