@@ -977,7 +977,7 @@ impl<'body, 'a, 'tcx> VnState<'body, 'a, 'tcx> {
977
977
978
978
match self . compute_place_value ( * place, location) {
979
979
Ok ( value) => {
980
- if let Some ( new_place) = self . try_as_place ( value, location, true )
980
+ if let Some ( new_place) = self . try_as_place ( value, location, false )
981
981
&& ( new_place. local != place. local
982
982
|| new_place. projection . len ( ) < place. projection . len ( ) )
983
983
{
@@ -1020,7 +1020,6 @@ impl<'body, 'a, 'tcx> VnState<'body, 'a, 'tcx> {
1020
1020
#[ instrument( level = "trace" , skip( self ) , ret) ]
1021
1021
fn simplify_rvalue (
1022
1022
& mut self ,
1023
- lhs : & Place < ' tcx > ,
1024
1023
rvalue : & mut Rvalue < ' tcx > ,
1025
1024
location : Location ,
1026
1025
) -> Option < VnIndex > {
@@ -1040,7 +1039,7 @@ impl<'body, 'a, 'tcx> VnState<'body, 'a, 'tcx> {
1040
1039
Value :: Repeat ( op, amount)
1041
1040
}
1042
1041
Rvalue :: NullaryOp ( op, ty) => Value :: NullaryOp ( op, ty) ,
1043
- Rvalue :: Aggregate ( ..) => return self . simplify_aggregate ( lhs , rvalue, location) ,
1042
+ Rvalue :: Aggregate ( ..) => return self . simplify_aggregate ( rvalue, location) ,
1044
1043
Rvalue :: Ref ( _, borrow_kind, ref mut place) => {
1045
1044
self . simplify_place_projection ( place, location) ;
1046
1045
return self . new_pointer ( * place, AddressKind :: Ref ( borrow_kind) ) ;
@@ -1148,7 +1147,6 @@ impl<'body, 'a, 'tcx> VnState<'body, 'a, 'tcx> {
1148
1147
1149
1148
fn simplify_aggregate (
1150
1149
& mut self ,
1151
- lhs : & Place < ' tcx > ,
1152
1150
rvalue : & mut Rvalue < ' tcx > ,
1153
1151
location : Location ,
1154
1152
) -> Option < VnIndex > {
@@ -1231,15 +1229,6 @@ impl<'body, 'a, 'tcx> VnState<'body, 'a, 'tcx> {
1231
1229
}
1232
1230
1233
1231
if let Some ( value) = self . simplify_aggregate_to_copy ( ty, variant_index, & fields) {
1234
- // Allow introducing places with non-constant offsets, as those are still better than
1235
- // reconstructing an aggregate. But avoid creating `*a = copy (*b)`, as they might be
1236
- // aliases resulting in overlapping assignments.
1237
- let allow_complex_projection =
1238
- lhs. projection [ ..] . iter ( ) . all ( PlaceElem :: is_stable_offset) ;
1239
- if let Some ( place) = self . try_as_place ( value, location, allow_complex_projection) {
1240
- self . reused_locals . insert ( place. local ) ;
1241
- * rvalue = Rvalue :: Use ( Operand :: Copy ( place) ) ;
1242
- }
1243
1232
return Some ( value) ;
1244
1233
}
1245
1234
@@ -1885,13 +1874,21 @@ impl<'tcx> MutVisitor<'tcx> for VnState<'_, '_, 'tcx> {
1885
1874
) {
1886
1875
self . simplify_place_projection ( lhs, location) ;
1887
1876
1888
- let value = self . simplify_rvalue ( lhs , rvalue, location) ;
1877
+ let value = self . simplify_rvalue ( rvalue, location) ;
1889
1878
if let Some ( value) = value {
1879
+ // Allow introducing places with non-constant offsets, as those are still better than
1880
+ // reconstructing an aggregate. But avoid creating `*a = copy (*b)`, as they might be
1881
+ // aliases resulting in overlapping assignments.
1882
+ let allow_complex_projection =
1883
+ lhs. projection [ ..] . iter ( ) . all ( PlaceElem :: is_stable_offset) ;
1884
+
1890
1885
if let Some ( const_) = self . try_as_constant ( value) {
1891
1886
* rvalue = Rvalue :: Use ( Operand :: Constant ( Box :: new ( const_) ) ) ;
1892
- } else if let Some ( place) = self . try_as_place ( value, location, false )
1887
+ } else if let Some ( place) = self . try_as_place ( value, location, allow_complex_projection )
1893
1888
&& * rvalue != Rvalue :: Use ( Operand :: Move ( place) )
1894
1889
&& * rvalue != Rvalue :: Use ( Operand :: Copy ( place) )
1890
+ // Avoid introducing overlapping assignments to the same local.
1891
+ && place. local != lhs. local
1895
1892
{
1896
1893
* rvalue = Rvalue :: Use ( Operand :: Copy ( place) ) ;
1897
1894
self . reused_locals . insert ( place. local ) ;
0 commit comments