@@ -228,6 +228,8 @@ AliasSet::PointerVector AliasSet::getPointers() const {
228
228
229
229
void AliasSetTracker::clear () {
230
230
PointerMap.clear ();
231
+ UndefPointerSets.clear ();
232
+ UndefPointerSetsVector.clear ();
231
233
AliasSets.clear ();
232
234
}
233
235
@@ -287,7 +289,8 @@ AliasSet &AliasSetTracker::getAliasSetFor(const MemoryLocation &MemLoc) {
287
289
// The PointerMap structure requires that all memory locations for the same
288
290
// value will be in the same alias set, which does not hold for undef values.
289
291
// So we keep UndefValue pointers associated with the nullptr in the pointer
290
- // map, and resort to a linear scan of all alias sets in that case.
292
+ // map, and instead keep a collection with the alias sets that contain memory
293
+ // locations with undef pointer values.
291
294
auto [It, Inserted] = PointerMap.insert ({MemLoc.Ptr , nullptr });
292
295
AliasSet *&MapEntry = It->second ;
293
296
if (!Inserted) {
@@ -302,12 +305,27 @@ AliasSet &AliasSetTracker::getAliasSetFor(const MemoryLocation &MemLoc) {
302
305
return *AS;
303
306
}
304
307
} else {
305
- for (auto &AS : *this ) {
306
- if (AS.isForwardingAliasSet ())
307
- continue ;
308
- if (llvm::find (AS.MemoryLocs , MemLoc) != AS.MemoryLocs .end ())
309
- return AS;
310
- }
308
+ // Take opportunity to remove refs to forwarding alias sets from UndefPointerSets.
309
+ llvm::erase_if (UndefPointerSetsVector, [this ](AliasSet *&AS) {
310
+ if (AS->Forward ) {
311
+ AliasSet *NewAS = AS->getForwardedTarget (*this );
312
+ UndefPointerSets.erase (AS);
313
+ AS->dropRef (*this );
314
+ // Replace earlier entry in UndefPointerSetsVector with forwarded
315
+ // target, but only if it is new.
316
+ if (UndefPointerSets.insert (NewAS).second ) {
317
+ NewAS->addRef ();
318
+ AS = NewAS;
319
+ return false ;
320
+ } else
321
+ return true ;
322
+ }
323
+ return false ;
324
+ });
325
+ // Scan UndefPointerSets for MemLoc.
326
+ for (AliasSet *AS : UndefPointerSetsVector)
327
+ if (llvm::find (AS->MemoryLocs , MemLoc) != AS->MemoryLocs .end ())
328
+ return *AS;
311
329
}
312
330
}
313
331
@@ -349,6 +367,11 @@ AliasSet &AliasSetTracker::getAliasSetFor(const MemoryLocation &MemLoc) {
349
367
AS->addRef ();
350
368
MapEntry = AS;
351
369
}
370
+ } else {
371
+ if (UndefPointerSets.insert (AS).second ) {
372
+ UndefPointerSetsVector.push_back (AS);
373
+ AS->addRef ();
374
+ }
352
375
}
353
376
return *AS;
354
377
}
0 commit comments