8484
8585use rustc_const_eval:: interpret:: { intern_const_alloc_for_constprop, MemoryKind } ;
8686use rustc_const_eval:: interpret:: { ImmTy , InterpCx , OpTy , Projectable , Scalar } ;
87- use rustc_data_structures:: fx:: { FxHashMap , FxIndexSet } ;
87+ use rustc_data_structures:: fx:: FxIndexSet ;
8888use rustc_data_structures:: graph:: dominators:: Dominators ;
8989use rustc_hir:: def:: DefKind ;
9090use rustc_index:: bit_set:: BitSet ;
@@ -238,8 +238,10 @@ struct VnState<'body, 'tcx> {
238238 local_decls : & ' body LocalDecls < ' tcx > ,
239239 /// Value stored in each local.
240240 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 > > ,
243245 values : FxIndexSet < Value < ' tcx > > ,
244246 /// Values evaluated as constants if possible.
245247 evaluated : IndexVec < VnIndex , Option < OpTy < ' tcx > > > ,
@@ -265,7 +267,7 @@ impl<'body, 'tcx> VnState<'body, 'tcx> {
265267 param_env,
266268 local_decls,
267269 locals : IndexVec :: from_elem ( None , local_decls) ,
268- rev_locals : FxHashMap :: default ( ) ,
270+ rev_locals : IndexVec :: default ( ) ,
269271 values : FxIndexSet :: default ( ) ,
270272 evaluated : IndexVec :: new ( ) ,
271273 next_opaque : Some ( 0 ) ,
@@ -319,7 +321,8 @@ impl<'body, 'tcx> VnState<'body, 'tcx> {
319321 let is_sized = !self . tcx . features ( ) . unsized_locals
320322 || self . local_decls [ local] . ty . is_sized ( self . tcx , self . param_env ) ;
321323 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) ;
323326 }
324327 }
325328
@@ -986,11 +989,11 @@ impl<'tcx> VnState<'_, 'tcx> {
986989 /// If there is a local which is assigned `index`, and its assignment strictly dominates `loc`,
987990 /// return it.
988991 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) ?;
990993 other
991994 . iter ( )
995+ . find ( |& & other| self . ssa . assignment_dominates ( self . dominators , other, loc) )
992996 . copied ( )
993- . find ( |& other| self . ssa . assignment_dominates ( self . dominators , other, loc) )
994997 }
995998}
996999
0 commit comments