@@ -971,7 +971,7 @@ impl<'body, 'a, 'tcx> VnState<'body, 'a, 'tcx> {
971
971
972
972
match self . compute_place_value ( * place, location) {
973
973
Ok ( value) => {
974
- if let Some ( new_place) = self . try_as_place ( value, location, true )
974
+ if let Some ( new_place) = self . try_as_place ( value, location, false )
975
975
&& ( new_place. local != place. local
976
976
|| new_place. projection . len ( ) < place. projection . len ( ) )
977
977
{
@@ -1014,7 +1014,6 @@ impl<'body, 'a, 'tcx> VnState<'body, 'a, 'tcx> {
1014
1014
#[ instrument( level = "trace" , skip( self ) , ret) ]
1015
1015
fn simplify_rvalue (
1016
1016
& mut self ,
1017
- lhs : & Place < ' tcx > ,
1018
1017
rvalue : & mut Rvalue < ' tcx > ,
1019
1018
location : Location ,
1020
1019
) -> Option < VnIndex > {
@@ -1034,7 +1033,7 @@ impl<'body, 'a, 'tcx> VnState<'body, 'a, 'tcx> {
1034
1033
Value :: Repeat ( op, amount)
1035
1034
}
1036
1035
Rvalue :: NullaryOp ( op, ty) => Value :: NullaryOp ( op, ty) ,
1037
- Rvalue :: Aggregate ( ..) => return self . simplify_aggregate ( lhs , rvalue, location) ,
1036
+ Rvalue :: Aggregate ( ..) => return self . simplify_aggregate ( rvalue, location) ,
1038
1037
Rvalue :: Ref ( _, borrow_kind, ref mut place) => {
1039
1038
self . simplify_place_projection ( place, location) ;
1040
1039
return self . new_pointer ( * place, AddressKind :: Ref ( borrow_kind) ) ;
@@ -1142,7 +1141,6 @@ impl<'body, 'a, 'tcx> VnState<'body, 'a, 'tcx> {
1142
1141
1143
1142
fn simplify_aggregate (
1144
1143
& mut self ,
1145
- lhs : & Place < ' tcx > ,
1146
1144
rvalue : & mut Rvalue < ' tcx > ,
1147
1145
location : Location ,
1148
1146
) -> Option < VnIndex > {
@@ -1225,15 +1223,6 @@ impl<'body, 'a, 'tcx> VnState<'body, 'a, 'tcx> {
1225
1223
}
1226
1224
1227
1225
if let Some ( value) = self . simplify_aggregate_to_copy ( ty, variant_index, & fields) {
1228
- // Allow introducing places with non-constant offsets, as those are still better than
1229
- // reconstructing an aggregate. But avoid creating `*a = copy (*b)`, as they might be
1230
- // aliases resulting in overlapping assignments.
1231
- let allow_complex_projection =
1232
- lhs. projection [ ..] . iter ( ) . all ( PlaceElem :: is_stable_offset) ;
1233
- if let Some ( place) = self . try_as_place ( value, location, allow_complex_projection) {
1234
- self . reused_locals . insert ( place. local ) ;
1235
- * rvalue = Rvalue :: Use ( Operand :: Copy ( place) ) ;
1236
- }
1237
1226
return Some ( value) ;
1238
1227
}
1239
1228
@@ -1879,13 +1868,21 @@ impl<'tcx> MutVisitor<'tcx> for VnState<'_, '_, 'tcx> {
1879
1868
) {
1880
1869
self . simplify_place_projection ( lhs, location) ;
1881
1870
1882
- let value = self . simplify_rvalue ( lhs , rvalue, location) ;
1871
+ let value = self . simplify_rvalue ( rvalue, location) ;
1883
1872
if let Some ( value) = value {
1873
+ // Allow introducing places with non-constant offsets, as those are still better than
1874
+ // reconstructing an aggregate. But avoid creating `*a = copy (*b)`, as they might be
1875
+ // aliases resulting in overlapping assignments.
1876
+ let allow_complex_projection =
1877
+ lhs. projection [ ..] . iter ( ) . all ( PlaceElem :: is_stable_offset) ;
1878
+
1884
1879
if let Some ( const_) = self . try_as_constant ( value) {
1885
1880
* rvalue = Rvalue :: Use ( Operand :: Constant ( Box :: new ( const_) ) ) ;
1886
- } else if let Some ( place) = self . try_as_place ( value, location, false )
1881
+ } else if let Some ( place) = self . try_as_place ( value, location, allow_complex_projection )
1887
1882
&& * rvalue != Rvalue :: Use ( Operand :: Move ( place) )
1888
1883
&& * rvalue != Rvalue :: Use ( Operand :: Copy ( place) )
1884
+ // Avoid introducing overlapping assignments to the same local.
1885
+ && place. local != lhs. local
1889
1886
{
1890
1887
* rvalue = Rvalue :: Use ( Operand :: Copy ( place) ) ;
1891
1888
self . reused_locals . insert ( place. local ) ;
0 commit comments