@@ -872,7 +872,6 @@ impl<'body, 'a, 'tcx> VnState<'body, 'a, 'tcx> {
872872 #[ instrument( level = "trace" , skip( self ) , ret) ]
873873 fn simplify_rvalue (
874874 & mut self ,
875- lhs : & Place < ' tcx > ,
876875 rvalue : & mut Rvalue < ' tcx > ,
877876 location : Location ,
878877 ) -> Option < VnIndex > {
@@ -892,7 +891,7 @@ impl<'body, 'a, 'tcx> VnState<'body, 'a, 'tcx> {
892891 Value :: Repeat ( op, amount)
893892 }
894893 Rvalue :: NullaryOp ( op, ty) => Value :: NullaryOp ( op, ty) ,
895- Rvalue :: Aggregate ( ..) => return self . simplify_aggregate ( lhs , rvalue, location) ,
894+ Rvalue :: Aggregate ( ..) => return self . simplify_aggregate ( rvalue, location) ,
896895 Rvalue :: Ref ( _, borrow_kind, ref mut place) => {
897896 self . simplify_place_projection ( place, location) ;
898897 return self . new_pointer ( * place, AddressKind :: Ref ( borrow_kind) , location) ;
@@ -1001,7 +1000,6 @@ impl<'body, 'a, 'tcx> VnState<'body, 'a, 'tcx> {
10011000
10021001 fn simplify_aggregate (
10031002 & mut self ,
1004- lhs : & Place < ' tcx > ,
10051003 rvalue : & mut Rvalue < ' tcx > ,
10061004 location : Location ,
10071005 ) -> Option < VnIndex > {
@@ -1081,15 +1079,6 @@ impl<'body, 'a, 'tcx> VnState<'body, 'a, 'tcx> {
10811079 }
10821080
10831081 if let Some ( value) = self . simplify_aggregate_to_copy ( ty, variant_index, & fields) {
1084- // Allow introducing places with non-constant offsets, as those are still better than
1085- // reconstructing an aggregate. But avoid creating `*a = copy (*b)`, as they might be
1086- // aliases resulting in overlapping assignments.
1087- let allow_complex_projection =
1088- lhs. projection [ ..] . iter ( ) . all ( PlaceElem :: is_stable_offset) ;
1089- if let Some ( place) = self . try_as_place ( value, location, allow_complex_projection) {
1090- self . reused_locals . insert ( place. local ) ;
1091- * rvalue = Rvalue :: Use ( Operand :: Copy ( place) ) ;
1092- }
10931082 return Some ( value) ;
10941083 }
10951084
@@ -1760,13 +1749,21 @@ impl<'tcx> MutVisitor<'tcx> for VnState<'_, '_, 'tcx> {
17601749 ) {
17611750 self . simplify_place_projection ( lhs, location) ;
17621751
1763- let value = self . simplify_rvalue ( lhs , rvalue, location) ;
1752+ let value = self . simplify_rvalue ( rvalue, location) ;
17641753 if let Some ( value) = value {
1754+ // Allow introducing places with non-constant offsets, as those are still better than
1755+ // reconstructing an aggregate. But avoid creating `*a = copy (*b)`, as they might be
1756+ // aliases resulting in overlapping assignments.
1757+ let allow_complex_projection =
1758+ lhs. projection [ ..] . iter ( ) . all ( PlaceElem :: is_stable_offset) ;
1759+
17651760 if let Some ( const_) = self . try_as_constant ( value) {
17661761 * rvalue = Rvalue :: Use ( Operand :: Constant ( Box :: new ( const_) ) ) ;
1767- } else if let Some ( place) = self . try_as_place ( value, location, false )
1762+ } else if let Some ( place) = self . try_as_place ( value, location, allow_complex_projection )
17681763 && * rvalue != Rvalue :: Use ( Operand :: Move ( place) )
17691764 && * rvalue != Rvalue :: Use ( Operand :: Copy ( place) )
1765+ // Avoid introducing overlapping assignments to the same local.
1766+ && place. local != lhs. local
17701767 {
17711768 * rvalue = Rvalue :: Use ( Operand :: Copy ( place) ) ;
17721769 self . reused_locals . insert ( place. local ) ;
0 commit comments