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