@@ -953,13 +953,8 @@ impl<'body, 'tcx> VnState<'body, 'tcx> {
953
953
was_updated = true ;
954
954
}
955
955
956
- if was_updated {
957
- if let Some ( const_) = self . try_as_constant ( fields[ 0 ] ) {
958
- field_ops[ FieldIdx :: ZERO ] = Operand :: Constant ( Box :: new ( const_) ) ;
959
- } else if let Some ( local) = self . try_as_local ( fields[ 0 ] , location) {
960
- field_ops[ FieldIdx :: ZERO ] = Operand :: Copy ( Place :: from ( local) ) ;
961
- self . reused_locals . insert ( local) ;
962
- }
956
+ if was_updated && let Some ( op) = self . try_as_operand ( fields[ 0 ] , location) {
957
+ field_ops[ FieldIdx :: ZERO ] = op;
963
958
}
964
959
}
965
960
@@ -969,11 +964,8 @@ impl<'body, 'tcx> VnState<'body, 'tcx> {
969
964
let first = fields[ 0 ] ;
970
965
if fields. iter ( ) . all ( |& v| v == first) {
971
966
let len = ty:: Const :: from_target_usize ( self . tcx , fields. len ( ) . try_into ( ) . unwrap ( ) ) ;
972
- if let Some ( const_) = self . try_as_constant ( first) {
973
- * rvalue = Rvalue :: Repeat ( Operand :: Constant ( Box :: new ( const_) ) , len) ;
974
- } else if let Some ( local) = self . try_as_local ( first, location) {
975
- * rvalue = Rvalue :: Repeat ( Operand :: Copy ( local. into ( ) ) , len) ;
976
- self . reused_locals . insert ( local) ;
967
+ if let Some ( op) = self . try_as_operand ( first, location) {
968
+ * rvalue = Rvalue :: Repeat ( op, len) ;
977
969
}
978
970
return Some ( self . insert ( Value :: Repeat ( first, len) ) ) ;
979
971
}
@@ -1178,13 +1170,8 @@ impl<'body, 'tcx> VnState<'body, 'tcx> {
1178
1170
}
1179
1171
}
1180
1172
1181
- if was_updated {
1182
- if let Some ( const_) = self . try_as_constant ( value) {
1183
- * operand = Operand :: Constant ( Box :: new ( const_) ) ;
1184
- } else if let Some ( local) = self . try_as_local ( value, location) {
1185
- * operand = Operand :: Copy ( local. into ( ) ) ;
1186
- self . reused_locals . insert ( local) ;
1187
- }
1173
+ if was_updated && let Some ( op) = self . try_as_operand ( value, location) {
1174
+ * operand = op;
1188
1175
}
1189
1176
1190
1177
Some ( self . insert ( Value :: Cast { kind : * kind, value, from, to } ) )
@@ -1300,6 +1287,19 @@ fn op_to_prop_const<'tcx>(
1300
1287
}
1301
1288
1302
1289
impl < ' tcx > VnState < ' _ , ' tcx > {
1290
+ /// If either [`Self::try_as_constant`] as [`Self::try_as_local`] succeeds,
1291
+ /// returns that result as an [`Operand`].
1292
+ fn try_as_operand ( & mut self , index : VnIndex , location : Location ) -> Option < Operand < ' tcx > > {
1293
+ if let Some ( const_) = self . try_as_constant ( index) {
1294
+ Some ( Operand :: Constant ( Box :: new ( const_) ) )
1295
+ } else if let Some ( local) = self . try_as_local ( index, location) {
1296
+ self . reused_locals . insert ( local) ;
1297
+ Some ( Operand :: Copy ( local. into ( ) ) )
1298
+ } else {
1299
+ None
1300
+ }
1301
+ }
1302
+
1303
1303
/// If `index` is a `Value::Constant`, return the `Constant` to be put in the MIR.
1304
1304
fn try_as_constant ( & mut self , index : VnIndex ) -> Option < ConstOperand < ' tcx > > {
1305
1305
// This was already constant in MIR, do not change it.
0 commit comments