@@ -949,13 +949,8 @@ impl<'body, 'tcx> VnState<'body, 'tcx> {
949949 was_updated = true ;
950950 }
951951
952- if was_updated {
953- if let Some ( const_) = self . try_as_constant ( fields[ 0 ] ) {
954- field_ops[ FieldIdx :: ZERO ] = Operand :: Constant ( Box :: new ( const_) ) ;
955- } else if let Some ( local) = self . try_as_local ( fields[ 0 ] , location) {
956- field_ops[ FieldIdx :: ZERO ] = Operand :: Copy ( Place :: from ( local) ) ;
957- self . reused_locals . insert ( local) ;
958- }
952+ if was_updated && let Some ( op) = self . try_as_operand ( fields[ 0 ] , location) {
953+ field_ops[ FieldIdx :: ZERO ] = op;
959954 }
960955 }
961956
@@ -965,11 +960,8 @@ impl<'body, 'tcx> VnState<'body, 'tcx> {
965960 let first = fields[ 0 ] ;
966961 if fields. iter ( ) . all ( |& v| v == first) {
967962 let len = ty:: Const :: from_target_usize ( self . tcx , fields. len ( ) . try_into ( ) . unwrap ( ) ) ;
968- if let Some ( const_) = self . try_as_constant ( first) {
969- * rvalue = Rvalue :: Repeat ( Operand :: Constant ( Box :: new ( const_) ) , len) ;
970- } else if let Some ( local) = self . try_as_local ( first, location) {
971- * rvalue = Rvalue :: Repeat ( Operand :: Copy ( local. into ( ) ) , len) ;
972- self . reused_locals . insert ( local) ;
963+ if let Some ( op) = self . try_as_operand ( first, location) {
964+ * rvalue = Rvalue :: Repeat ( op, len) ;
973965 }
974966 return Some ( self . insert ( Value :: Repeat ( first, len) ) ) ;
975967 }
@@ -1174,13 +1166,8 @@ impl<'body, 'tcx> VnState<'body, 'tcx> {
11741166 }
11751167 }
11761168
1177- if was_updated {
1178- if let Some ( const_) = self . try_as_constant ( value) {
1179- * operand = Operand :: Constant ( Box :: new ( const_) ) ;
1180- } else if let Some ( local) = self . try_as_local ( value, location) {
1181- * operand = Operand :: Copy ( local. into ( ) ) ;
1182- self . reused_locals . insert ( local) ;
1183- }
1169+ if was_updated && let Some ( op) = self . try_as_operand ( value, location) {
1170+ * operand = op;
11841171 }
11851172
11861173 Some ( self . insert ( Value :: Cast { kind : * kind, value, from, to } ) )
@@ -1296,6 +1283,19 @@ fn op_to_prop_const<'tcx>(
12961283}
12971284
12981285impl < ' tcx > VnState < ' _ , ' tcx > {
1286+ /// If either [`Self::try_as_constant`] as [`Self::try_as_local`] succeeds,
1287+ /// returns that result as an [`Operand`].
1288+ fn try_as_operand ( & mut self , index : VnIndex , location : Location ) -> Option < Operand < ' tcx > > {
1289+ if let Some ( const_) = self . try_as_constant ( index) {
1290+ Some ( Operand :: Constant ( Box :: new ( const_) ) )
1291+ } else if let Some ( local) = self . try_as_local ( index, location) {
1292+ self . reused_locals . insert ( local) ;
1293+ Some ( Operand :: Copy ( local. into ( ) ) )
1294+ } else {
1295+ None
1296+ }
1297+ }
1298+
12991299 /// If `index` is a `Value::Constant`, return the `Constant` to be put in the MIR.
13001300 fn try_as_constant ( & mut self , index : VnIndex ) -> Option < ConstOperand < ' tcx > > {
13011301 // This was already constant in MIR, do not change it.
0 commit comments