Index: include/llvm/Transforms/Utils/MemorySSA.h =================================================================== --- include/llvm/Transforms/Utils/MemorySSA.h +++ include/llvm/Transforms/Utils/MemorySSA.h @@ -756,6 +756,9 @@ MemoryAccess *getClobberingMemoryAccess(MemoryAccess *, UpwardsMemoryQuery &); bool instructionClobbersQuery(const MemoryDef *, UpwardsMemoryQuery &, const MemoryLocation &Loc) const; +#ifdef XDEBUG + void verifyRemoved(MemoryAccess *); +#endif SmallDenseMap CachedUpwardsClobberingAccess; DenseMap CachedUpwardsClobberingCall; Index: lib/Transforms/Utils/MemorySSA.cpp =================================================================== --- lib/Transforms/Utils/MemorySSA.cpp +++ lib/Transforms/Utils/MemorySSA.cpp @@ -799,19 +799,16 @@ if (!Q.IsCall) Q.StartingLoc = MemoryLocation::get(I); doCacheRemove(MA, Q, Q.StartingLoc); - return; - } - // If it is not a use, the best we can do right now is destroy the cache. - bool IsCall = false; - - if (auto *MUD = dyn_cast(MA)) { - Instruction *I = MUD->getMemoryInst(); - IsCall = bool(ImmutableCallSite(I)); - } - if (IsCall) + } else { + // If it is not a use, the best we can do right now is destroy the cache. CachedUpwardsClobberingCall.clear(); - else CachedUpwardsClobberingAccess.clear(); + } + +#ifdef XDEBUG + // Run this only when expensive checks are enabled. + verifyRemoved(MA); +#endif } void CachingMemorySSAWalker::doCacheRemove(const MemoryAccess *M, @@ -1081,6 +1078,18 @@ return Result; } +#ifdef XDEBUG +// Verify that MA doesn't exist in any of the caches. +void CachingMemorySSAWalker::verifyRemoved(MemoryAccess *MA) { + for (auto &P : CachedUpwardsClobberingAccess) + assert(P.first.first != MA && P.second != MA && + "Found removed MemoryAccess in cache."); + for (auto &P : CachedUpwardsClobberingCall) + assert(P.first != MA && P.second != MA && + "Found removed MemoryAccess in cache."); +} +#endif // XDEBUG + MemoryAccess * DoNothingMemorySSAWalker::getClobberingMemoryAccess(const Instruction *I) { MemoryAccess *MA = MSSA->getMemoryAccess(I);