@@ -214,23 +214,33 @@ void AliasSetTracker::clear() {
214
214
215
215
// / mergeAliasSetsForPointer - Given a pointer, merge all alias sets that may
216
216
// / alias the pointer. Return the unified set, or nullptr if no set that aliases
217
- // / the pointer was found. MustAliasAll is updated to true/false if the pointer
218
- // / is found to MustAlias all the sets it merged.
217
+ // / the pointer was found. A known existing alias set for the pointer value of
218
+ // / the memory location can be passed in (or nullptr if not available).
219
+ // / MustAliasAll is updated to true/false if the pointer is found to MustAlias
220
+ // / all the sets it merged.
219
221
AliasSet *
220
222
AliasSetTracker::mergeAliasSetsForPointer (const MemoryLocation &MemLoc,
221
- bool &MustAliasAll) {
223
+ AliasSet *PtrAS, bool &MustAliasAll) {
222
224
AliasSet *FoundSet = nullptr ;
223
225
MustAliasAll = true ;
224
226
for (AliasSet &AS : llvm::make_early_inc_range (*this )) {
225
227
if (AS.Forward )
226
228
continue ;
227
229
228
- AliasResult AR = AS.aliasesPointer (MemLoc, AA);
229
- if (AR == AliasResult::NoAlias)
230
- continue ;
231
-
232
- if (AR != AliasResult::MustAlias)
233
- MustAliasAll = false ;
230
+ // An alias set that already contains a memory location with the same
231
+ // pointer value is directly assumed to MustAlias; we bypass the AA query in
232
+ // this case.
233
+ // Note: it is not guaranteed that AA would always provide the same result;
234
+ // a known exception are undef pointer values, where alias(undef, undef) is
235
+ // NoAlias, while we treat it as MustAlias.
236
+ if (&AS != PtrAS) {
237
+ AliasResult AR = AS.aliasesPointer (MemLoc, AA);
238
+ if (AR == AliasResult::NoAlias)
239
+ continue ;
240
+
241
+ if (AR != AliasResult::MustAlias)
242
+ MustAliasAll = false ;
243
+ }
234
244
235
245
if (!FoundSet) {
236
246
// If this is the first alias set ptr can go into, remember it.
@@ -286,18 +296,12 @@ AliasSet &AliasSetTracker::getAliasSetFor(const MemoryLocation &MemLoc) {
286
296
// consistent.
287
297
// This, of course, means that we will never need a merge here.
288
298
AS = AliasAnyAS;
289
- } else if (AliasSet *AliasAS =
290
- mergeAliasSetsForPointer (MemLoc, MustAliasAll)) {
299
+ } else if (AliasSet *AliasAS = mergeAliasSetsForPointer (
300
+ MemLoc,
301
+ MapEntry ? MapEntry->getForwardedTarget (*this ) : nullptr ,
302
+ MustAliasAll)) {
291
303
// Add it to the alias set it aliases.
292
304
AS = AliasAS;
293
- } else if (MapEntry) {
294
- // Although we have an independent memory location, forgo creating a new
295
- // alias set to retain the implementation invariant that all memory
296
- // locations with the same pointer value are in the same alias set.
297
- // (This is only known to occur for undef pointer values, which AA treats as
298
- // noalias.)
299
- AS = MapEntry->getForwardedTarget (*this );
300
- AS->Alias = AliasSet::SetMayAlias;
301
305
} else {
302
306
// Otherwise create a new alias set to hold the loaded pointer.
303
307
AliasSets.push_back (AS = new AliasSet ());
0 commit comments