@@ -228,8 +228,6 @@ AliasSet::PointerVector AliasSet::getPointers() const {
228
228
229
229
void AliasSetTracker::clear () {
230
230
PointerMap.clear ();
231
- UndefPointerSets.clear ();
232
- UndefPointerSetsVector.clear ();
233
231
AliasSets.clear ();
234
232
}
235
233
@@ -285,47 +283,16 @@ AliasSet &AliasSetTracker::getAliasSetFor(const MemoryLocation &MemLoc) {
285
283
// The alias sets are indexed with a map from the memory locations' pointer
286
284
// values. If the memory location is already registered, we can find it in the
287
285
// alias set associated with its pointer.
288
- //
289
- // The PointerMap structure requires that all memory locations for the same
290
- // value will be in the same alias set, which does not hold for undef values.
291
- // So we keep UndefValue pointers associated with the nullptr in the pointer
292
- // map, and instead keep a collection with the alias sets that contain memory
293
- // locations with undef pointer values.
294
- auto [It, Inserted] = PointerMap.insert ({MemLoc.Ptr , nullptr });
295
- AliasSet *&MapEntry = It->second ;
296
- if (!Inserted) {
297
- if (!isa<UndefValue>(MemLoc.Ptr )) {
298
- AliasSet *AS = MapEntry->getForwardedTarget (*this );
299
- if (llvm::find (AS->MemoryLocs , MemLoc) != AS->MemoryLocs .end ()) {
300
- if (AS != MapEntry) {
301
- AS->addRef ();
302
- MapEntry->dropRef (*this );
303
- MapEntry = AS;
304
- }
305
- return *AS;
286
+ AliasSet *&MapEntry = PointerMap[MemLoc.Ptr ];
287
+ if (MapEntry) {
288
+ AliasSet *AS = MapEntry->getForwardedTarget (*this );
289
+ if (llvm::is_contained (AS->MemoryLocs , MemLoc)) {
290
+ if (AS != MapEntry) {
291
+ AS->addRef ();
292
+ MapEntry->dropRef (*this );
293
+ MapEntry = AS;
306
294
}
307
- } else {
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;
295
+ return *AS;
329
296
}
330
297
}
331
298
@@ -342,6 +309,14 @@ AliasSet &AliasSetTracker::getAliasSetFor(const MemoryLocation &MemLoc) {
342
309
mergeAliasSetsForPointer (MemLoc, MustAliasAll)) {
343
310
// Add it to the alias set it aliases.
344
311
AS = AliasAS;
312
+ } else if (MapEntry) {
313
+ // Although we have an independent memory location, forgo creating a new
314
+ // alias set to retain the implementation invariant that all memory
315
+ // locations with the same pointer value are in the same alias set.
316
+ // (This is only known to occur for undef pointer values, which AA treats as
317
+ // noalias.)
318
+ AS = MapEntry->getForwardedTarget (*this );
319
+ AS->Alias = AliasSet::SetMayAlias;
345
320
} else {
346
321
// Otherwise create a new alias set to hold the loaded pointer.
347
322
AliasSets.push_back (AS = new AliasSet ());
@@ -352,26 +327,18 @@ AliasSet &AliasSetTracker::getAliasSetFor(const MemoryLocation &MemLoc) {
352
327
AS->addPointer (*this , MemLoc, MustAliasAll);
353
328
// Register selected alias set in pointer map (or ensure it is consistent with
354
329
// earlier map entry after taking into account new merging).
355
- if (!isa<UndefValue>(MemLoc.Ptr )) {
356
- if (MapEntry) {
357
- if (MapEntry->Forward ) {
358
- AliasSet *NewAS = MapEntry->getForwardedTarget (*this );
359
- NewAS->addRef ();
360
- MapEntry->dropRef (*this );
361
- MapEntry = NewAS;
362
- }
363
- assert (MapEntry == AS &&
364
- " Memory locations with same pointer value cannot "
365
- " be in different alias sets" );
366
- } else {
367
- AS->addRef ();
368
- MapEntry = AS;
330
+ if (MapEntry) {
331
+ if (MapEntry->Forward ) {
332
+ AliasSet *NewAS = MapEntry->getForwardedTarget (*this );
333
+ NewAS->addRef ();
334
+ MapEntry->dropRef (*this );
335
+ MapEntry = NewAS;
369
336
}
337
+ assert (MapEntry == AS && " Memory locations with same pointer value cannot "
338
+ " be in different alias sets" );
370
339
} else {
371
- if (UndefPointerSets.insert (AS).second ) {
372
- UndefPointerSetsVector.push_back (AS);
373
- AS->addRef ();
374
- }
340
+ AS->addRef ();
341
+ MapEntry = AS;
375
342
}
376
343
return *AS;
377
344
}
0 commit comments