84
84
85
85
use rustc_const_eval:: interpret:: { intern_const_alloc_for_constprop, MemoryKind } ;
86
86
use rustc_const_eval:: interpret:: { ImmTy , InterpCx , OpTy , Projectable , Scalar } ;
87
- use rustc_data_structures:: fx:: { FxHashMap , FxIndexSet } ;
87
+ use rustc_data_structures:: fx:: FxIndexSet ;
88
88
use rustc_data_structures:: graph:: dominators:: Dominators ;
89
89
use rustc_hir:: def:: DefKind ;
90
90
use rustc_index:: bit_set:: BitSet ;
@@ -238,8 +238,10 @@ struct VnState<'body, 'tcx> {
238
238
local_decls : & ' body LocalDecls < ' tcx > ,
239
239
/// Value stored in each local.
240
240
locals : IndexVec < Local , Option < VnIndex > > ,
241
- /// First local to be assigned that value.
242
- rev_locals : FxHashMap < VnIndex , Vec < Local > > ,
241
+ /// Locals that are assigned that value.
242
+ // This vector does not hold all the values of `VnIndex` that we create.
243
+ // It stops at the largest value created in the first phase of collecting assignments.
244
+ rev_locals : IndexVec < VnIndex , Vec < Local > > ,
243
245
values : FxIndexSet < Value < ' tcx > > ,
244
246
/// Values evaluated as constants if possible.
245
247
evaluated : IndexVec < VnIndex , Option < OpTy < ' tcx > > > ,
@@ -265,7 +267,7 @@ impl<'body, 'tcx> VnState<'body, 'tcx> {
265
267
param_env,
266
268
local_decls,
267
269
locals : IndexVec :: from_elem ( None , local_decls) ,
268
- rev_locals : FxHashMap :: default ( ) ,
270
+ rev_locals : IndexVec :: default ( ) ,
269
271
values : FxIndexSet :: default ( ) ,
270
272
evaluated : IndexVec :: new ( ) ,
271
273
next_opaque : Some ( 0 ) ,
@@ -319,7 +321,8 @@ impl<'body, 'tcx> VnState<'body, 'tcx> {
319
321
let is_sized = !self . tcx . features ( ) . unsized_locals
320
322
|| self . local_decls [ local] . ty . is_sized ( self . tcx , self . param_env ) ;
321
323
if is_sized {
322
- self . rev_locals . entry ( value) . or_default ( ) . push ( local) ;
324
+ self . rev_locals . ensure_contains_elem ( value, Vec :: new) ;
325
+ self . rev_locals [ value] . push ( local) ;
323
326
}
324
327
}
325
328
@@ -986,11 +989,11 @@ impl<'tcx> VnState<'_, 'tcx> {
986
989
/// If there is a local which is assigned `index`, and its assignment strictly dominates `loc`,
987
990
/// return it.
988
991
fn try_as_local ( & mut self , index : VnIndex , loc : Location ) -> Option < Local > {
989
- let other = self . rev_locals . get ( & index) ?;
992
+ let other = self . rev_locals . get ( index) ?;
990
993
other
991
994
. iter ( )
995
+ . find ( |& & other| self . ssa . assignment_dominates ( self . dominators , other, loc) )
992
996
. copied ( )
993
- . find ( |& other| self . ssa . assignment_dominates ( self . dominators , other, loc) )
994
997
}
995
998
}
996
999
0 commit comments