@@ -99,6 +99,7 @@ use rustc_middle::ty::{self, Ty, TyCtxt, TypeAndMut};
99
99
use rustc_span:: def_id:: DefId ;
100
100
use rustc_span:: DUMMY_SP ;
101
101
use rustc_target:: abi:: { self , Abi , Size , VariantIdx , FIRST_VARIANT } ;
102
+ use smallvec:: SmallVec ;
102
103
use std:: borrow:: Cow ;
103
104
104
105
use crate :: dataflow_const_prop:: DummyMachine ;
@@ -241,13 +242,15 @@ struct VnState<'body, 'tcx> {
241
242
/// Locals that are assigned that value.
242
243
// This vector does not hold all the values of `VnIndex` that we create.
243
244
// It stops at the largest value created in the first phase of collecting assignments.
244
- rev_locals : IndexVec < VnIndex , Vec < Local > > ,
245
+ rev_locals : IndexVec < VnIndex , SmallVec < [ Local ; 1 ] > > ,
245
246
values : FxIndexSet < Value < ' tcx > > ,
246
247
/// Values evaluated as constants if possible.
247
248
evaluated : IndexVec < VnIndex , Option < OpTy < ' tcx > > > ,
248
249
/// Counter to generate different values.
249
250
/// This is an option to stop creating opaques during replacement.
250
251
next_opaque : Option < usize > ,
252
+ /// Cache the value of the `unsized_locals` features, to avoid fetching it repeatedly in a loop.
253
+ feature_unsized_locals : bool ,
251
254
ssa : & ' body SsaLocals ,
252
255
dominators : & ' body Dominators < BasicBlock > ,
253
256
reused_locals : BitSet < Local > ,
@@ -271,6 +274,7 @@ impl<'body, 'tcx> VnState<'body, 'tcx> {
271
274
values : FxIndexSet :: default ( ) ,
272
275
evaluated : IndexVec :: new ( ) ,
273
276
next_opaque : Some ( 0 ) ,
277
+ feature_unsized_locals : tcx. features ( ) . unsized_locals ,
274
278
ssa,
275
279
dominators,
276
280
reused_locals : BitSet :: new_empty ( local_decls. len ( ) ) ,
@@ -318,10 +322,10 @@ impl<'body, 'tcx> VnState<'body, 'tcx> {
318
322
self . locals [ local] = Some ( value) ;
319
323
320
324
// Only register the value if its type is `Sized`, as we will emit copies of it.
321
- let is_sized = !self . tcx . features ( ) . unsized_locals
325
+ let is_sized = !self . feature_unsized_locals
322
326
|| self . local_decls [ local] . ty . is_sized ( self . tcx , self . param_env ) ;
323
327
if is_sized {
324
- self . rev_locals . ensure_contains_elem ( value, Vec :: new) ;
328
+ self . rev_locals . ensure_contains_elem ( value, SmallVec :: new) ;
325
329
self . rev_locals [ value] . push ( local) ;
326
330
}
327
331
}
0 commit comments