Skip to content

Commit 9fe26e6

Browse files
committedApr 22, 2016
[MemorySSA] Fix bug in CachingMemorySSAWalker::invalidateInfo
Summary: CachingMemorySSAWalker::invalidateInfo was using IsCall to determine which cache map needed to be cleared of entries referring to the invalidated MemoryAccess, but there could also be entries referring to it in the other cache map (value entries, not key entries). This change just clears both tables to be conservatively correct. Also add a verifyRemoved() function, called when expensive checks (i.e. XDEBUG) are enabled to verify that the invalidated MemoryAccess object is not referenced in any of the caches. Reviewers: dberlin, george.burgess.iv Subscribers: mcrosier, llvm-commits Differential Revision: http://reviews.llvm.org/D19388 llvm-svn: 267157
1 parent ee34680 commit 9fe26e6

File tree

2 files changed

+21
-11
lines changed

2 files changed

+21
-11
lines changed
 

‎llvm/include/llvm/Transforms/Utils/MemorySSA.h

+1
Original file line numberDiff line numberDiff line change
@@ -756,6 +756,7 @@ class CachingMemorySSAWalker final : public MemorySSAWalker {
756756
MemoryAccess *getClobberingMemoryAccess(MemoryAccess *, UpwardsMemoryQuery &);
757757
bool instructionClobbersQuery(const MemoryDef *, UpwardsMemoryQuery &,
758758
const MemoryLocation &Loc) const;
759+
void verifyRemoved(MemoryAccess *);
759760
SmallDenseMap<ConstMemoryAccessPair, MemoryAccess *>
760761
CachedUpwardsClobberingAccess;
761762
DenseMap<const MemoryAccess *, MemoryAccess *> CachedUpwardsClobberingCall;

‎llvm/lib/Transforms/Utils/MemorySSA.cpp

+20-11
Original file line numberDiff line numberDiff line change
@@ -799,19 +799,16 @@ void CachingMemorySSAWalker::invalidateInfo(MemoryAccess *MA) {
799799
if (!Q.IsCall)
800800
Q.StartingLoc = MemoryLocation::get(I);
801801
doCacheRemove(MA, Q, Q.StartingLoc);
802-
return;
803-
}
804-
// If it is not a use, the best we can do right now is destroy the cache.
805-
bool IsCall = false;
806-
807-
if (auto *MUD = dyn_cast<MemoryUseOrDef>(MA)) {
808-
Instruction *I = MUD->getMemoryInst();
809-
IsCall = bool(ImmutableCallSite(I));
810-
}
811-
if (IsCall)
802+
} else {
803+
// If it is not a use, the best we can do right now is destroy the cache.
812804
CachedUpwardsClobberingCall.clear();
813-
else
814805
CachedUpwardsClobberingAccess.clear();
806+
}
807+
808+
#ifdef XDEBUG
809+
// Run this only when expensive checks are enabled.
810+
verifyRemoved(MA);
811+
#endif
815812
}
816813

817814
void CachingMemorySSAWalker::doCacheRemove(const MemoryAccess *M,
@@ -1081,6 +1078,18 @@ CachingMemorySSAWalker::getClobberingMemoryAccess(const Instruction *I) {
10811078
return Result;
10821079
}
10831080

1081+
// Verify that MA doesn't exist in any of the caches.
1082+
void CachingMemorySSAWalker::verifyRemoved(MemoryAccess *MA) {
1083+
#ifndef NDEBUG
1084+
for (auto &P : CachedUpwardsClobberingAccess)
1085+
assert(P.first.first != MA && P.second != MA &&
1086+
"Found removed MemoryAccess in cache.");
1087+
for (auto &P : CachedUpwardsClobberingCall)
1088+
assert(P.first != MA && P.second != MA &&
1089+
"Found removed MemoryAccess in cache.");
1090+
#endif // !NDEBUG
1091+
}
1092+
10841093
MemoryAccess *
10851094
DoNothingMemorySSAWalker::getClobberingMemoryAccess(const Instruction *I) {
10861095
MemoryAccess *MA = MSSA->getMemoryAccess(I);

0 commit comments

Comments
 (0)
Please sign in to comment.