Index: include/llvm/Analysis/AliasSetTracker.h =================================================================== --- include/llvm/Analysis/AliasSetTracker.h +++ include/llvm/Analysis/AliasSetTracker.h @@ -212,7 +212,8 @@ bool isForwardingAliasSet() const { return Forward; } /// Merge the specified alias set into this alias set. - void mergeSetIn(AliasSet &AS, AliasSetTracker &AST); + void mergeSetIn(AliasSet &AS, AliasSetTracker &AST, AliasResult AR, + bool EntryUpdated = false); // Alias Set iteration - Allow access to all of the pointers which are part of // this alias set. @@ -438,7 +439,8 @@ AliasSet &addPointer(MemoryLocation Loc, AliasSet::AccessLattice E); AliasSet *mergeAliasSetsForPointer(const Value *Ptr, LocationSize Size, - const AAMDNodes &AAInfo); + const AAMDNodes &AAInfo, + bool EntryUpdated = false); /// Merge all alias sets into a single set that is considered to alias any /// pointer. Index: lib/Analysis/AliasSetTracker.cpp =================================================================== --- lib/Analysis/AliasSetTracker.cpp +++ lib/Analysis/AliasSetTracker.cpp @@ -47,7 +47,8 @@ /// mergeSetIn - Merge the specified alias set into this alias set. /// -void AliasSet::mergeSetIn(AliasSet &AS, AliasSetTracker &AST) { +void AliasSet::mergeSetIn(AliasSet &AS, AliasSetTracker &AST, AliasResult AR, + bool EntryUpdated) { assert(!AS.Forward && "Alias set is already forwarding!"); assert(!Forward && "This set is a forwarding set!!"); @@ -57,17 +58,20 @@ Alias |= AS.Alias; if (Alias == SetMustAlias) { - // Check that these two merged sets really are must aliases. Since both - // used to be must-alias sets, we can just check any pointer from each set - // for aliasing. - AliasAnalysis &AA = AST.getAliasAnalysis(); - PointerRec *L = getSomePointer(); - PointerRec *R = AS.getSomePointer(); - - // If the pointers are not a must-alias pair, this set becomes a may alias. - if (AA.alias(MemoryLocation(L->getValue(), L->getSize(), L->getAAInfo()), - MemoryLocation(R->getValue(), R->getSize(), R->getAAInfo())) != - MustAlias) + if (EntryUpdated) { + // Check that these two merged sets really are must aliases. Since both + // used to be must-alias sets, we can just check any pointer from each set + // for aliasing. + AliasAnalysis &AA = AST.getAliasAnalysis(); + PointerRec *L = getSomePointer(); + PointerRec *R = AS.getSomePointer(); + + // If the pointers are not a must-alias pair, this set becomes a may alias. + if (AA.alias(MemoryLocation(L->getValue(), L->getSize(), L->getAAInfo()), + MemoryLocation(R->getValue(), R->getSize(), R->getAAInfo())) != + MustAlias) + Alias = SetMayAlias; + } else if (AR != MustAlias) Alias = SetMayAlias; } @@ -295,18 +299,24 @@ /// the pointer was found. AliasSet *AliasSetTracker::mergeAliasSetsForPointer(const Value *Ptr, LocationSize Size, - const AAMDNodes &AAInfo) { + const AAMDNodes &AAInfo, + bool EntryUpdated) { AliasSet *FoundSet = nullptr; for (iterator I = begin(), E = end(); I != E;) { iterator Cur = I++; - if (Cur->Forward || !Cur->aliasesPointer(Ptr, Size, AAInfo, AA)) continue; + if (Cur->Forward) + continue; + + AliasResult AR = Cur->aliasesPointer(Ptr, Size, AAInfo, AA); + if (AR == NoAlias) + continue; if (!FoundSet) { // If this is the first alias set ptr can go into, remember it. FoundSet = &*Cur; } else { // Otherwise, we must merge the sets. - FoundSet->mergeSetIn(*Cur, *this); + FoundSet->mergeSetIn(*Cur, *this, AR, EntryUpdated); } } @@ -324,7 +334,7 @@ FoundSet = &*Cur; } else { // Otherwise, we must merge the sets. - FoundSet->mergeSetIn(*Cur, *this); + FoundSet->mergeSetIn(*Cur, *this, MayAlias); } } return FoundSet; @@ -362,7 +372,7 @@ // is NoAlias, mergeAliasSetsForPointer(undef, ...) will not find the // the right set for undef, even if it exists. if (Entry.updateSizeAndAAInfo(Size, AAInfo)) - mergeAliasSetsForPointer(Pointer, Size, AAInfo); + mergeAliasSetsForPointer(Pointer, Size, AAInfo, true); // Return the set! return *Entry.getAliasSet(*this)->getForwardedTarget(*this); } @@ -605,7 +615,7 @@ } // Otherwise, perform the actual merge. - AliasAnyAS->mergeSetIn(*Cur, *this); + AliasAnyAS->mergeSetIn(*Cur, *this, MayAlias); } return *AliasAnyAS;