Index: include/llvm/Analysis/AliasSetTracker.h =================================================================== --- include/llvm/Analysis/AliasSetTracker.h +++ include/llvm/Analysis/AliasSetTracker.h @@ -213,7 +213,7 @@ 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); // Alias Set iteration - Allow access to all of the pointers which are part of // this alias set. @@ -310,10 +310,10 @@ } public: - /// Return true if the specified pointer "may" (or must) alias one of the - /// members in the set. - bool aliasesPointer(const Value *Ptr, LocationSize Size, - const AAMDNodes &AAInfo, AliasAnalysis &AA) const; + /// If the specified pointer "may" (or must) alias one of the members in the + /// set return the appropriate AliasResult. Otherwise return NoAlias. + AliasResult aliasesPointer(const Value *Ptr, LocationSize Size, + const AAMDNodes &AAInfo, AliasAnalysis &AA) const; bool aliasesUnknownInst(const Instruction *Inst, AliasAnalysis &AA) const; }; Index: lib/Analysis/AliasSetTracker.cpp =================================================================== --- lib/Analysis/AliasSetTracker.cpp +++ lib/Analysis/AliasSetTracker.cpp @@ -48,7 +48,7 @@ /// 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) { assert(!AS.Forward && "Alias set is already forwarding!"); assert(!Forward && "This set is a forwarding set!!"); @@ -57,20 +57,8 @@ Access |= AS.Access; 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) - Alias = SetMayAlias; - } + if (Alias == SetMustAlias && AR != MustAlias) + Alias = SetMayAlias; if (Alias == SetMayAlias) { if (WasMustAlias) @@ -184,14 +172,15 @@ Access = ModRefAccess; } -/// aliasesPointer - Return true if the specified pointer "may" (or must) -/// alias one of the members in the set. +/// aliasesPointer - If the specified pointer "may" (or must) alias one of the +/// members in the set return the appropriate AliasResult. Otherwise return +/// NoAlias. /// -bool AliasSet::aliasesPointer(const Value *Ptr, LocationSize Size, - const AAMDNodes &AAInfo, - AliasAnalysis &AA) const { +AliasResult AliasSet::aliasesPointer(const Value *Ptr, LocationSize Size, + const AAMDNodes &AAInfo, + AliasAnalysis &AA) const { if (AliasAny) - return true; + return MayAlias; if (Alias == SetMustAlias) { assert(UnknownInsts.empty() && "Illegal must alias set!"); @@ -208,9 +197,10 @@ // If this is a may-alias set, we have to check all of the pointers in the set // to be sure it doesn't alias the set... for (iterator I = begin(), E = end(); I != E; ++I) - if (AA.alias(MemoryLocation(Ptr, Size, AAInfo), - MemoryLocation(I.getPointer(), I.getSize(), I.getAAInfo()))) - return true; + if (AliasResult AR = AA.alias( + MemoryLocation(Ptr, Size, AAInfo), + MemoryLocation(I.getPointer(), I.getSize(), I.getAAInfo()))) + return AR; // Check the unknown instructions... if (!UnknownInsts.empty()) { @@ -218,10 +208,10 @@ if (auto *Inst = getUnknownInst(i)) if (isModOrRefSet( AA.getModRefInfo(Inst, MemoryLocation(Ptr, Size, AAInfo)))) - return true; + return MayAlias; } - return false; + return NoAlias; } bool AliasSet::aliasesUnknownInst(const Instruction *Inst, @@ -298,12 +288,17 @@ 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. FoundSet = &*Cur; // Remember it. } else { // Otherwise, we must merge the sets. - FoundSet->mergeSetIn(*Cur, *this); // Merge in contents. + FoundSet->mergeSetIn(*Cur, *this, AR); // Merge in contents. } } @@ -319,7 +314,7 @@ if (!FoundSet) // If this is the first alias set ptr can go into. FoundSet = &*Cur; // Remember it. else // Otherwise, we must merge the sets. - FoundSet->mergeSetIn(*Cur, *this); // Merge in contents. + FoundSet->mergeSetIn(*Cur, *this, MayAlias); // Merge in contents. } return FoundSet; } @@ -599,7 +594,7 @@ } // Otherwise, perform the actual merge. - AliasAnyAS->mergeSetIn(*Cur, *this); + AliasAnyAS->mergeSetIn(*Cur, *this, MayAlias); } return *AliasAnyAS;