Index: include/llvm/Analysis/AliasAnalysis.h =================================================================== --- include/llvm/Analysis/AliasAnalysis.h +++ include/llvm/Analysis/AliasAnalysis.h @@ -91,6 +91,25 @@ MustAlias, }; +/// << operator for AliasResult. +inline raw_ostream &operator<<(raw_ostream &OS, AliasResult AR) { + switch (AR) { + case NoAlias: + OS << "NoAlias"; + break; + case MustAlias: + OS << "MustAlias"; + break; + case MayAlias: + OS << "MayAlias"; + break; + case PartialAlias: + OS << "PartialAlias"; + break; + } + return OS; +} + /// Flags indicating whether a memory access modifies or references memory. /// /// This is no access at all, a modification, a reference, or both Index: lib/Analysis/AliasAnalysisEvaluator.cpp =================================================================== --- lib/Analysis/AliasAnalysisEvaluator.cpp +++ lib/Analysis/AliasAnalysisEvaluator.cpp @@ -41,7 +41,7 @@ static cl::opt EvalAAMD("evaluate-aa-metadata", cl::ReallyHidden); -static void PrintResults(const char *Msg, bool P, const Value *V1, +static void PrintResults(AliasResult AR, bool P, const Value *V1, const Value *V2, const Module *M) { if (PrintAll || P) { std::string o1, o2; @@ -50,18 +50,15 @@ V1->printAsOperand(os1, true, M); V2->printAsOperand(os2, true, M); } - + if (o2 < o1) std::swap(o1, o2); - errs() << " " << Msg << ":\t" - << o1 << ", " - << o2 << "\n"; + errs() << " " << AR << ":\t" << o1 << ", " << o2 << "\n"; } } -static inline void -PrintModRefResults(const char *Msg, bool P, Instruction *I, Value *Ptr, - Module *M) { +static inline void PrintModRefResults(const char *Msg, bool P, Instruction *I, + Value *Ptr, Module *M) { if (PrintAll || P) { errs() << " " << Msg << ": Ptr: "; Ptr->printAsOperand(errs(), true, M); @@ -69,21 +66,19 @@ } } -static inline void -PrintModRefResults(const char *Msg, bool P, CallSite CSA, CallSite CSB, - Module *M) { +static inline void PrintModRefResults(const char *Msg, bool P, CallSite CSA, + CallSite CSB, Module *M) { if (PrintAll || P) { - errs() << " " << Msg << ": " << *CSA.getInstruction() - << " <-> " << *CSB.getInstruction() << '\n'; + errs() << " " << Msg << ": " << *CSA.getInstruction() << " <-> " + << *CSB.getInstruction() << '\n'; } } -static inline void -PrintLoadStoreResults(const char *Msg, bool P, const Value *V1, - const Value *V2, const Module *M) { +static inline void PrintLoadStoreResults(AliasResult AR, bool P, + const Value *V1, const Value *V2, + const Module *M) { if (PrintAll || P) { - errs() << " " << Msg << ": " << *V1 - << " <-> " << *V2 << '\n'; + errs() << " " << AR << ": " << *V1 << " <-> " << *V2 << '\n'; } } @@ -155,22 +150,22 @@ Type *I2ElTy =cast((*I2)->getType())->getElementType(); if (I2ElTy->isSized()) I2Size = DL.getTypeStoreSize(I2ElTy); - switch (AA.alias(*I1, I1Size, *I2, I2Size)) { + AliasResult AR = AA.alias(*I1, I1Size, *I2, I2Size); + switch (AR) { case NoAlias: - PrintResults("NoAlias", PrintNoAlias, *I1, *I2, F.getParent()); + PrintResults(AR, PrintNoAlias, *I1, *I2, F.getParent()); ++NoAliasCount; break; case MayAlias: - PrintResults("MayAlias", PrintMayAlias, *I1, *I2, F.getParent()); + PrintResults(AR, PrintMayAlias, *I1, *I2, F.getParent()); ++MayAliasCount; break; case PartialAlias: - PrintResults("PartialAlias", PrintPartialAlias, *I1, *I2, - F.getParent()); + PrintResults(AR, PrintPartialAlias, *I1, *I2, F.getParent()); ++PartialAliasCount; break; case MustAlias: - PrintResults("MustAlias", PrintMustAlias, *I1, *I2, F.getParent()); + PrintResults(AR, PrintMustAlias, *I1, *I2, F.getParent()); ++MustAliasCount; break; } @@ -181,26 +176,23 @@ // iterate over all pairs of load, store for (Value *Load : Loads) { for (Value *Store : Stores) { - switch (AA.alias(MemoryLocation::get(cast(Load)), - MemoryLocation::get(cast(Store)))) { + AliasResult AR = AA.alias(MemoryLocation::get(cast(Load)), + MemoryLocation::get(cast(Store))); + switch (AR) { case NoAlias: - PrintLoadStoreResults("NoAlias", PrintNoAlias, Load, Store, - F.getParent()); + PrintLoadStoreResults(AR, PrintNoAlias, Load, Store, F.getParent()); ++NoAliasCount; break; case MayAlias: - PrintLoadStoreResults("MayAlias", PrintMayAlias, Load, Store, - F.getParent()); + PrintLoadStoreResults(AR, PrintMayAlias, Load, Store, F.getParent()); ++MayAliasCount; break; case PartialAlias: - PrintLoadStoreResults("PartialAlias", PrintPartialAlias, Load, Store, - F.getParent()); + PrintLoadStoreResults(AR, PrintPartialAlias, Load, Store, F.getParent()); ++PartialAliasCount; break; case MustAlias: - PrintLoadStoreResults("MustAlias", PrintMustAlias, Load, Store, - F.getParent()); + PrintLoadStoreResults(AR, PrintMustAlias, Load, Store, F.getParent()); ++MustAliasCount; break; } @@ -211,26 +203,23 @@ for (SetVector::iterator I1 = Stores.begin(), E = Stores.end(); I1 != E; ++I1) { for (SetVector::iterator I2 = Stores.begin(); I2 != I1; ++I2) { - switch (AA.alias(MemoryLocation::get(cast(*I1)), - MemoryLocation::get(cast(*I2)))) { + AliasResult AR = AA.alias(MemoryLocation::get(cast(*I1)), + MemoryLocation::get(cast(*I2))); + switch (AR) { case NoAlias: - PrintLoadStoreResults("NoAlias", PrintNoAlias, *I1, *I2, - F.getParent()); + PrintLoadStoreResults(AR, PrintNoAlias, *I1, *I2, F.getParent()); ++NoAliasCount; break; case MayAlias: - PrintLoadStoreResults("MayAlias", PrintMayAlias, *I1, *I2, - F.getParent()); + PrintLoadStoreResults(AR, PrintMayAlias, *I1, *I2, F.getParent()); ++MayAliasCount; break; case PartialAlias: - PrintLoadStoreResults("PartialAlias", PrintPartialAlias, *I1, *I2, - F.getParent()); + PrintLoadStoreResults(AR, PrintPartialAlias, *I1, *I2, F.getParent()); ++PartialAliasCount; break; case MustAlias: - PrintLoadStoreResults("MustAlias", PrintMustAlias, *I1, *I2, - F.getParent()); + PrintLoadStoreResults(AR, PrintMustAlias, *I1, *I2, F.getParent()); ++MustAliasCount; break; } Index: lib/Analysis/MemorySSA.cpp =================================================================== --- lib/Analysis/MemorySSA.cpp +++ lib/Analysis/MemorySSA.cpp @@ -1857,12 +1857,25 @@ void MemoryDef::print(raw_ostream &OS) const { MemoryAccess *UO = getDefiningAccess(); + auto printID = [&OS](MemoryAccess *A) { + if (A && A->getID()) + OS << A->getID(); + else + OS << LiveOnEntryStr; + }; + OS << getID() << " = MemoryDef("; - if (UO && UO->getID()) - OS << UO->getID(); - else - OS << LiveOnEntryStr; - OS << ')'; + printID(UO); + + if (isOptimized()) { + OS << "->"; + printID(getOptimized()); + + if (Optional AR = getOptimizedAccessType()) + OS << " " << *AR; + } + + OS << ")"; } void MemoryPhi::print(raw_ostream &OS) const { @@ -1899,6 +1912,9 @@ else OS << LiveOnEntryStr; OS << ')'; + + if (Optional AR = getOptimizedAccessType()) + OS << " " << *AR; } void MemoryAccess::dump() const { Index: test/Analysis/MemorySSA/optimize-use.ll =================================================================== --- test/Analysis/MemorySSA/optimize-use.ll +++ test/Analysis/MemorySSA/optimize-use.ll @@ -18,16 +18,16 @@ ; CHECK: 4 = MemoryDef(3) ; CHECK-NEXT: store i32 7, i32* %1, align 4 store i32 7, i32* %1, align 4 -; CHECK: MemoryUse(3) +; CHECK: MemoryUse(3) MustAlias ; CHECK-NEXT: %2 = load i32, i32* %0, align 4 %2 = load i32, i32* %0, align 4 -; CHECK: MemoryUse(4) +; CHECK: MemoryUse(4) MustAlias ; CHECK-NEXT: %3 = load i32, i32* %1, align 4 %3 = load i32, i32* %1, align 4 -; CHECK: MemoryUse(3) +; CHECK: MemoryUse(3) MustAlias ; CHECK-NEXT: %4 = load i32, i32* %0, align 4 %4 = load i32, i32* %0, align 4 -; CHECK: MemoryUse(4) +; CHECK: MemoryUse(4) MustAlias ; CHECK-NEXT: %5 = load i32, i32* %1, align 4 %5 = load i32, i32* %1, align 4 %add = add nsw i32 %3, %5