@@ -1015,23 +1015,32 @@ impl<'tcx> MutVisitor<'tcx> for VnState<'_, 'tcx> {
1015
1015
}
1016
1016
1017
1017
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
+
1019
1021
// 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 ;
1031
1024
}
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 ;
1034
1042
}
1043
+ self . super_statement ( stmt, location) ;
1035
1044
}
1036
1045
}
1037
1046
0 commit comments