@@ -989,26 +989,15 @@ impl<'body, 'tcx> VnState<'body, 'tcx> {
989
989
}
990
990
991
991
let tcx = self . tcx ;
992
- let mut projection = SmallVec :: < [ PlaceElem < ' tcx > ; 1 ] > :: new ( ) ;
993
- loop {
994
- if let Some ( local) = self . try_as_local ( copy_from_local_value, location) {
995
- projection. reverse ( ) ;
996
- let place = Place { local, projection : tcx. mk_place_elems ( projection. as_slice ( ) ) } ;
997
- if rvalue. ty ( self . local_decls , tcx) == place. ty ( self . local_decls , tcx) . ty {
998
- self . reused_locals . insert ( local) ;
999
- * rvalue = Rvalue :: Use ( Operand :: Copy ( place) ) ;
1000
- return Some ( copy_from_value) ;
1001
- }
1002
- return None ;
1003
- } else if let Value :: Projection ( pointer, proj) = * self . get ( copy_from_local_value)
1004
- && let Some ( proj) = self . try_as_place_elem ( proj, location)
1005
- {
1006
- projection. push ( proj) ;
1007
- copy_from_local_value = pointer;
1008
- } else {
1009
- return None ;
992
+ if let Some ( place) = self . try_as_place ( copy_from_local_value, location) {
993
+ if rvalue. ty ( self . local_decls , tcx) == place. ty ( self . local_decls , tcx) . ty {
994
+ self . reused_locals . insert ( place. local ) ;
995
+ * rvalue = Rvalue :: Use ( Operand :: Copy ( place) ) ;
996
+ return Some ( copy_from_local_value) ;
1010
997
}
1011
998
}
999
+
1000
+ None
1012
1001
}
1013
1002
1014
1003
fn simplify_aggregate (
@@ -1688,9 +1677,9 @@ impl<'tcx> VnState<'_, 'tcx> {
1688
1677
fn try_as_operand ( & mut self , index : VnIndex , location : Location ) -> Option < Operand < ' tcx > > {
1689
1678
if let Some ( const_) = self . try_as_constant ( index) {
1690
1679
Some ( Operand :: Constant ( Box :: new ( const_) ) )
1691
- } else if let Some ( local ) = self . try_as_local ( index, location) {
1692
- self . reused_locals . insert ( local) ;
1693
- Some ( Operand :: Copy ( local . into ( ) ) )
1680
+ } else if let Some ( place ) = self . try_as_place ( index, location) {
1681
+ self . reused_locals . insert ( place . local ) ;
1682
+ Some ( Operand :: Copy ( place ) )
1694
1683
} else {
1695
1684
None
1696
1685
}
@@ -1723,6 +1712,26 @@ impl<'tcx> VnState<'_, 'tcx> {
1723
1712
Some ( ConstOperand { span : DUMMY_SP , user_ty : None , const_ } )
1724
1713
}
1725
1714
1715
+ #[ instrument( level="trace" , skip( self ) , ret) ]
1716
+ fn try_as_place ( & mut self , mut index : VnIndex , loc : Location ) -> Option < Place < ' tcx > > {
1717
+ let mut projection = SmallVec :: < [ PlaceElem < ' tcx > ; 1 ] > :: new ( ) ;
1718
+ loop {
1719
+ if let Some ( local) = self . try_as_local ( index, loc) {
1720
+ projection. reverse ( ) ;
1721
+ let place =
1722
+ Place { local, projection : self . tcx . mk_place_elems ( projection. as_slice ( ) ) } ;
1723
+ return Some ( place) ;
1724
+ } else if let Value :: Projection ( pointer, proj) = * self . get ( index)
1725
+ && let Some ( proj) = self . try_as_place_elem ( proj, loc)
1726
+ {
1727
+ projection. push ( proj) ;
1728
+ index = pointer;
1729
+ } else {
1730
+ return None ;
1731
+ }
1732
+ }
1733
+ }
1734
+
1726
1735
/// If there is a local which is assigned `index`, and its assignment strictly dominates `loc`,
1727
1736
/// return it. If you used this local, add it to `reused_locals` to remove storage statements.
1728
1737
fn try_as_local ( & mut self , index : VnIndex , loc : Location ) -> Option < Local > {
@@ -1764,11 +1773,11 @@ impl<'tcx> MutVisitor<'tcx> for VnState<'_, 'tcx> {
1764
1773
1765
1774
if let Some ( const_) = self . try_as_constant ( value) {
1766
1775
* rvalue = Rvalue :: Use ( Operand :: Constant ( Box :: new ( const_) ) ) ;
1767
- } else if let Some ( local ) = self . try_as_local ( value, location)
1768
- && * rvalue != Rvalue :: Use ( Operand :: Move ( local . into ( ) ) )
1776
+ } else if let Some ( place ) = self . try_as_place ( value, location)
1777
+ && * rvalue != Rvalue :: Use ( Operand :: Move ( place ) )
1769
1778
{
1770
- * rvalue = Rvalue :: Use ( Operand :: Copy ( local . into ( ) ) ) ;
1771
- self . reused_locals . insert ( local) ;
1779
+ * rvalue = Rvalue :: Use ( Operand :: Copy ( place ) ) ;
1780
+ self . reused_locals . insert ( place . local ) ;
1772
1781
}
1773
1782
1774
1783
return ;
0 commit comments