@@ -866,7 +866,6 @@ impl<'body, 'a, 'tcx> VnState<'body, 'a, 'tcx> {
866866 #[ instrument( level = "trace" , skip( self ) , ret) ]
867867 fn simplify_rvalue (
868868 & mut self ,
869- lhs : & Place < ' tcx > ,
870869 rvalue : & mut Rvalue < ' tcx > ,
871870 location : Location ,
872871 ) -> Option < VnIndex > {
@@ -886,7 +885,7 @@ impl<'body, 'a, 'tcx> VnState<'body, 'a, 'tcx> {
886885 Value :: Repeat ( op, amount)
887886 }
888887 Rvalue :: NullaryOp ( op, ty) => Value :: NullaryOp ( op, ty) ,
889- Rvalue :: Aggregate ( ..) => return self . simplify_aggregate ( lhs , rvalue, location) ,
888+ Rvalue :: Aggregate ( ..) => return self . simplify_aggregate ( rvalue, location) ,
890889 Rvalue :: Ref ( _, borrow_kind, ref mut place) => {
891890 self . simplify_place_projection ( place, location) ;
892891 return self . new_pointer ( * place, AddressKind :: Ref ( borrow_kind) , location) ;
@@ -994,7 +993,6 @@ impl<'body, 'a, 'tcx> VnState<'body, 'a, 'tcx> {
994993
995994 fn simplify_aggregate (
996995 & mut self ,
997- lhs : & Place < ' tcx > ,
998996 rvalue : & mut Rvalue < ' tcx > ,
999997 location : Location ,
1000998 ) -> Option < VnIndex > {
@@ -1074,15 +1072,6 @@ impl<'body, 'a, 'tcx> VnState<'body, 'a, 'tcx> {
10741072 }
10751073
10761074 if let Some ( value) = self . simplify_aggregate_to_copy ( ty, variant_index, & fields) {
1077- // Allow introducing places with non-constant offsets, as those are still better than
1078- // reconstructing an aggregate. But avoid creating `*a = copy (*b)`, as they might be
1079- // aliases resulting in overlapping assignments.
1080- let allow_complex_projection =
1081- lhs. projection [ ..] . iter ( ) . all ( PlaceElem :: is_stable_offset) ;
1082- if let Some ( place) = self . try_as_place ( value, location, allow_complex_projection) {
1083- self . reused_locals . insert ( place. local ) ;
1084- * rvalue = Rvalue :: Use ( Operand :: Copy ( place) ) ;
1085- }
10861075 return Some ( value) ;
10871076 }
10881077
@@ -1728,13 +1717,21 @@ impl<'tcx> MutVisitor<'tcx> for VnState<'_, '_, 'tcx> {
17281717 ) {
17291718 self . simplify_place_projection ( lhs, location) ;
17301719
1731- let value = self . simplify_rvalue ( lhs , rvalue, location) ;
1720+ let value = self . simplify_rvalue ( rvalue, location) ;
17321721 if let Some ( value) = value {
1722+ // Allow introducing places with non-constant offsets, as those are still better than
1723+ // reconstructing an aggregate. But avoid creating `*a = copy (*b)`, as they might be
1724+ // aliases resulting in overlapping assignments.
1725+ let allow_complex_projection =
1726+ lhs. projection [ ..] . iter ( ) . all ( PlaceElem :: is_stable_offset) ;
1727+
17331728 if let Some ( const_) = self . try_as_constant ( value) {
17341729 * rvalue = Rvalue :: Use ( Operand :: Constant ( Box :: new ( const_) ) ) ;
1735- } else if let Some ( place) = self . try_as_place ( value, location, false )
1730+ } else if let Some ( place) = self . try_as_place ( value, location, allow_complex_projection )
17361731 && * rvalue != Rvalue :: Use ( Operand :: Move ( place) )
17371732 && * rvalue != Rvalue :: Use ( Operand :: Copy ( place) )
1733+ // Avoid introducing overlapping assignments to the same local.
1734+ && place. local != lhs. local
17381735 {
17391736 * rvalue = Rvalue :: Use ( Operand :: Copy ( place) ) ;
17401737 self . reused_locals . insert ( place. local ) ;
0 commit comments