Index: include/llvm/Analysis/AliasSetTracker.h =================================================================== --- include/llvm/Analysis/AliasSetTracker.h +++ include/llvm/Analysis/AliasSetTracker.h @@ -297,7 +297,7 @@ void addPointer(AliasSetTracker &AST, PointerRec &Entry, LocationSize Size, const AAMDNodes &AAInfo, bool KnownMustAlias = false, bool SkipSizeUpdate = false); - void addUnknownInst(Instruction *I, AliasAnalysis &AA); + void addUnknownInst(Instruction *I, BatchAAResults &AA); void removeUnknownInst(AliasSetTracker &AST, Instruction *I) { bool WasEmpty = UnknownInsts.empty(); @@ -315,8 +315,8 @@ /// 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; + const AAMDNodes &AAInfo, BatchAAResults &AA) const; + bool aliasesUnknownInst(const Instruction *Inst, BatchAAResults &AA) const; }; inline raw_ostream& operator<<(raw_ostream &OS, const AliasSet &AS) { @@ -342,7 +342,7 @@ /// handle. struct ASTCallbackVHDenseMapInfo : public DenseMapInfo {}; - AliasAnalysis &AA; + std::unique_ptr AA; MemorySSA *MSSA; Loop *L; ilist AliasSets; @@ -356,9 +356,13 @@ public: /// Create an empty collection of AliasSets, and use the specified alias /// analysis object to disambiguate load and store addresses. - explicit AliasSetTracker(AliasAnalysis &aa) : AA(aa) {} + explicit AliasSetTracker(AliasAnalysis &aa) { + AA = make_unique(aa); + } explicit AliasSetTracker(AliasAnalysis &aa, MemorySSA *mssa, Loop *l) - : AA(aa), MSSA(mssa), L(l) {} + : MSSA(mssa), L(l) { + AA = make_unique(aa); + } ~AliasSetTracker() { clear(); } /// These methods are used to add different types of instructions to the alias @@ -397,7 +401,10 @@ AliasSet &getAliasSetFor(const MemoryLocation &MemLoc); /// Return the underlying alias analysis object used by this tracker. - AliasAnalysis &getAliasAnalysis() const { return AA; } + BatchAAResults &getAliasAnalysis() const { return *AA.get(); } + void setAliasAnalysis(AliasAnalysis &AA) { + this->AA = make_unique(AA); + } /// This method is used to remove a pointer value from the AliasSetTracker /// entirely. It should be used when an instruction is deleted from the Index: lib/Analysis/AliasSetTracker.cpp =================================================================== --- lib/Analysis/AliasSetTracker.cpp +++ lib/Analysis/AliasSetTracker.cpp @@ -62,7 +62,7 @@ // 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(); + BatchAAResults &AA = AST.getAliasAnalysis(); PointerRec *L = getSomePointer(); PointerRec *R = AS.getSomePointer(); @@ -135,7 +135,7 @@ if (isMustAlias()) if (PointerRec *P = getSomePointer()) { if (!KnownMustAlias) { - AliasAnalysis &AA = AST.getAliasAnalysis(); + BatchAAResults &AA = AST.getAliasAnalysis(); AliasResult Result = AA.alias( MemoryLocation(P->getValue(), P->getSize(), P->getAAInfo()), MemoryLocation(Entry.getValue(), Size, AAInfo)); @@ -164,7 +164,7 @@ AST.TotalMayAliasSetSize++; } -void AliasSet::addUnknownInst(Instruction *I, AliasAnalysis &AA) { +void AliasSet::addUnknownInst(Instruction *I, BatchAAResults &AA) { if (UnknownInsts.empty()) addRef(); UnknownInsts.emplace_back(I); @@ -191,7 +191,7 @@ /// AliasResult AliasSet::aliasesPointer(const Value *Ptr, LocationSize Size, const AAMDNodes &AAInfo, - AliasAnalysis &AA) const { + BatchAAResults &AA) const { if (AliasAny) return MayAlias; @@ -228,7 +228,7 @@ } bool AliasSet::aliasesUnknownInst(const Instruction *Inst, - AliasAnalysis &AA) const { + BatchAAResults &AA) const { if (AliasAny) return true; @@ -306,7 +306,7 @@ if (Cur->Forward) continue; - AliasResult AR = Cur->aliasesPointer(Ptr, Size, AAInfo, AA); + AliasResult AR = Cur->aliasesPointer(Ptr, Size, AAInfo, *AA); if (AR == NoAlias) continue; @@ -330,7 +330,7 @@ AliasSet *FoundSet = nullptr; for (iterator I = begin(), E = end(); I != E;) { iterator Cur = I++; - if (Cur->Forward || !Cur->aliasesUnknownInst(Inst, AA)) + if (Cur->Forward || !Cur->aliasesUnknownInst(Inst, *AA)) continue; if (!FoundSet) { // If this is the first alias set ptr can go into, remember it. @@ -444,11 +444,11 @@ return; // doesn't alias anything if (AliasSet *AS = findAliasSetForUnknownInst(Inst)) { - AS->addUnknownInst(Inst, AA); + AS->addUnknownInst(Inst, *AA); return; } AliasSets.push_back(new AliasSet()); - AliasSets.back().addUnknownInst(Inst, AA); + AliasSets.back().addUnknownInst(Inst, *AA); } void AliasSetTracker::add(Instruction *I) { @@ -478,7 +478,7 @@ return AliasSet::NoAccess; }; - ModRefInfo CallMask = createModRefInfo(AA.getModRefBehavior(Call)); + ModRefInfo CallMask = createModRefInfo(AA->getModRefBehavior(Call)); // Some intrinsics are marked as modifying memory for control flow // modelling purposes, but don't actually modify any specific memory @@ -495,7 +495,7 @@ continue; MemoryLocation ArgLoc = MemoryLocation::getForArgument(Call, ArgIdx, nullptr); - ModRefInfo ArgMask = AA.getArgModRefInfo(Call, ArgIdx); + ModRefInfo ArgMask = AA->getArgModRefInfo(Call, ArgIdx); ArgMask = intersectModRef(CallMask, ArgMask); if (!isNoModRef(ArgMask)) addPointer(ArgLoc, getAccessFromModRef(ArgMask)); @@ -512,9 +512,6 @@ } void AliasSetTracker::add(const AliasSetTracker &AST) { - assert(&AA == &AST.AA && - "Merging AliasSetTracker objects with different Alias Analyses!"); - // Loop over all of the alias sets in AST, adding the pointers contained // therein into the current alias sets. This can cause alias sets to be // merged together in the current AST. Index: lib/Transforms/Scalar/LICM.cpp =================================================================== --- lib/Transforms/Scalar/LICM.cpp +++ lib/Transforms/Scalar/LICM.cpp @@ -2108,6 +2108,7 @@ AliasAnalysis *AA) { std::unique_ptr CurAST; SmallVector RecomputeLoops; + for (Loop *InnerL : L->getSubLoops()) { auto MapI = LoopToAliasSetMap.find(InnerL); // If the AST for this inner loop is missing it may have been merged into @@ -2126,6 +2127,7 @@ CurAST->add(*InnerAST); } else { CurAST = std::move(InnerAST); + CurAST->setAliasAnalysis(*AA); } LoopToAliasSetMap.erase(MapI); } Index: lib/Transforms/Scalar/LoopRerollPass.cpp =================================================================== --- lib/Transforms/Scalar/LoopRerollPass.cpp +++ lib/Transforms/Scalar/LoopRerollPass.cpp @@ -1309,7 +1309,7 @@ // can't reroll. if (RootInst->mayReadFromMemory()) for (auto &K : AST) { - if (K.aliasesUnknownInst(RootInst, *AA)) { + if (K.aliasesUnknownInst(RootInst, AST.getAliasAnalysis())) { LLVM_DEBUG(dbgs() << "LRR: iteration root match failed at " << *BaseInst << " vs. " << *RootInst << " (depends on future store)\n");