@@ -1015,23 +1015,32 @@ impl<'tcx> MutVisitor<'tcx> for VnState<'_, 'tcx> {
10151015 }
10161016
10171017 fn visit_statement ( & mut self , stmt : & mut Statement < ' tcx > , location : Location ) {
1018- if let StatementKind :: Assign ( box ( _, ref mut rvalue) ) = stmt. kind
1018+ if let StatementKind :: Assign ( box ( ref mut lhs, ref mut rvalue) ) = stmt. kind {
1019+ self . simplify_place_projection ( lhs, location) ;
1020+
10191021 // Do not try to simplify a constant, it's already in canonical shape.
1020- && !matches ! ( rvalue, Rvalue :: Use ( Operand :: Constant ( _) ) )
1021- {
1022- if let Some ( value) = self . simplify_rvalue ( rvalue, location) {
1023- if let Some ( const_) = self . try_as_constant ( value) {
1024- * rvalue = Rvalue :: Use ( Operand :: Constant ( Box :: new ( const_) ) ) ;
1025- } else if let Some ( local) = self . try_as_local ( value, location)
1026- && * rvalue != Rvalue :: Use ( Operand :: Move ( local. into ( ) ) )
1027- {
1028- * rvalue = Rvalue :: Use ( Operand :: Copy ( local. into ( ) ) ) ;
1029- self . reused_locals . insert ( local) ;
1030- }
1022+ if matches ! ( rvalue, Rvalue :: Use ( Operand :: Constant ( _) ) ) {
1023+ return ;
10311024 }
1032- } else {
1033- self . super_statement ( stmt, location) ;
1025+
1026+ let value = lhs
1027+ . as_local ( )
1028+ . and_then ( |local| self . locals [ local] )
1029+ . or_else ( || self . simplify_rvalue ( rvalue, location) ) ;
1030+ let Some ( value) = value else { return } ;
1031+
1032+ if let Some ( const_) = self . try_as_constant ( value) {
1033+ * rvalue = Rvalue :: Use ( Operand :: Constant ( Box :: new ( const_) ) ) ;
1034+ } else if let Some ( local) = self . try_as_local ( value, location)
1035+ && * rvalue != Rvalue :: Use ( Operand :: Move ( local. into ( ) ) )
1036+ {
1037+ * rvalue = Rvalue :: Use ( Operand :: Copy ( local. into ( ) ) ) ;
1038+ self . reused_locals . insert ( local) ;
1039+ }
1040+
1041+ return ;
10341042 }
1043+ self . super_statement ( stmt, location) ;
10351044 }
10361045}
10371046
0 commit comments