Index: include/llvm/Analysis/BasicAliasAnalysis.h =================================================================== --- include/llvm/Analysis/BasicAliasAnalysis.h +++ include/llvm/Analysis/BasicAliasAnalysis.h @@ -40,21 +40,23 @@ friend AAResultBase; const DataLayout &DL; + InvariantInfo &InvInfo; AssumptionCache ∾ DominatorTree *DT; LoopInfo *LI; public: BasicAAResult(const DataLayout &DL, const TargetLibraryInfo &TLI, - AssumptionCache &AC, DominatorTree *DT = nullptr, - LoopInfo *LI = nullptr) - : AAResultBase(TLI), DL(DL), AC(AC), DT(DT), LI(LI) {} + AssumptionCache &AC, InvariantInfo &InvInfo, + DominatorTree *DT = nullptr, LoopInfo *LI = nullptr) + : AAResultBase(TLI), DL(DL), InvInfo(InvInfo), AC(AC), DT(DT), LI(LI) {} BasicAAResult(const BasicAAResult &Arg) - : AAResultBase(Arg), DL(Arg.DL), AC(Arg.AC), DT(Arg.DT), LI(Arg.LI) {} + : AAResultBase(Arg), DL(Arg.DL), InvInfo(Arg.InvInfo), AC(Arg.AC), + DT(Arg.DT), LI(Arg.LI) {} BasicAAResult(BasicAAResult &&Arg) - : AAResultBase(std::move(Arg)), DL(Arg.DL), AC(Arg.AC), DT(Arg.DT), - LI(Arg.LI) {} + : AAResultBase(std::move(Arg)), DL(Arg.DL), InvInfo(Arg.InvInfo), + AC(Arg.AC), DT(Arg.DT), LI(Arg.LI) {} /// Handle invalidation events from the new pass manager. /// Index: lib/Analysis/BasicAliasAnalysis.cpp =================================================================== --- lib/Analysis/BasicAliasAnalysis.cpp +++ lib/Analysis/BasicAliasAnalysis.cpp @@ -488,12 +488,15 @@ if (OrLocal && isa(V)) continue; + if (const AllocaInst *AI = dyn_cast(V)) + if (InvInfo.GetStartInstruction(AI)) continue; + // A global constant counts as local memory for our purposes. if (const GlobalVariable *GV = dyn_cast(V)) { // Note: this doesn't require GV to be "ODR" because it isn't legal for a // global to be marked constant in some modules and non-constant in // others. GV may even be a declaration, not a definition. - if (!GV->isConstant()) { + if (!GV->isConstant() && !InvInfo.GetStartInstruction(GV)) { Visited.clear(); return AAResultBase::pointsToConstantMemory(Loc, OrLocal); } @@ -670,6 +673,12 @@ return Alias; } +static bool isInvariantIntrinsic(ImmutableCallSite CS) { + const IntrinsicInst *II = dyn_cast(CS.getInstruction()); + return II && (II->getIntrinsicID() == Intrinsic::invariant_start || + II->getIntrinsicID() == Intrinsic::invariant_end); +} + /// Checks to see if the specified callsite can clobber the specified memory /// object. /// @@ -731,6 +740,9 @@ if (isAssumeIntrinsic(CS)) return MRI_NoModRef; + // Invariant intrinsics follow the same pattern as assume intrinsic. + if (isInvariantIntrinsic(CS)) return MRI_NoModRef; + // The AAResultBase base class has some smarts, lets use them. return AAResultBase::getModRefInfo(CS, Loc); } @@ -743,6 +755,10 @@ if (isAssumeIntrinsic(CS1) || isAssumeIntrinsic(CS2)) return MRI_NoModRef; + // Invariant intrinsics follow the same pattern as assume intrinsic. + if (isInvariantIntrinsic(CS1) || isInvariantIntrinsic(CS2)) + return MRI_NoModRef; + // The AAResultBase base class has some smarts, lets use them. return AAResultBase::getModRefInfo(CS1, CS2); } @@ -1528,6 +1544,7 @@ return BasicAAResult(F.getParent()->getDataLayout(), AM->getResult(F), AM->getResult(F), + F.getParent()->getInvariantInfo(), AM->getCachedResult(F), AM->getCachedResult(F)); } @@ -1554,6 +1571,7 @@ Result.reset(new BasicAAResult(F.getParent()->getDataLayout(), TLIWP.getTLI(), ACT.getAssumptionCache(F), + F.getParent()->getInvariantInfo(), DTWP ? &DTWP->getDomTree() : nullptr, LIWP ? &LIWP->getLoopInfo() : nullptr)); @@ -1570,5 +1588,6 @@ return BasicAAResult( F.getParent()->getDataLayout(), P.getAnalysis().getTLI(), - P.getAnalysis().getAssumptionCache(F)); + P.getAnalysis().getAssumptionCache(F), + F.getParent()->getInvariantInfo()); } Index: unittests/Analysis/AliasAnalysisTest.cpp =================================================================== --- unittests/Analysis/AliasAnalysisTest.cpp +++ unittests/Analysis/AliasAnalysisTest.cpp @@ -39,7 +39,8 @@ // Build the various AA results and register them. AC.reset(new AssumptionCache(F)); - BAR.reset(new BasicAAResult(M.getDataLayout(), TLI, *AC)); + BAR.reset(new BasicAAResult(M.getDataLayout(), TLI, *AC, + M.getInvariantInfo())); AAR->addAAResult(*BAR); return *AAR;