summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGeorge Burgess IV <george.burgess.iv@gmail.com>2018-02-23 23:07:18 +0000
committerGeorge Burgess IV <george.burgess.iv@gmail.com>2018-02-23 23:07:18 +0000
commit3d238821f125366a4142f79f441db29b800a6b93 (patch)
tree6dd08d24073f68fdf598b3c692105f42293d6821
parent5e4b515c4bb332df9c3a063e888f9124a1cd0965 (diff)
[MemorySSA] Fix a cache invalidation bug with removed accesses
I suspect there's a deeper issue here, but we probably shouldn't be using INVALID_MEMORYSSA_ID as liveOnEntry's ID anyway. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@325971 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--include/llvm/Analysis/MemorySSA.h4
-rw-r--r--lib/Analysis/MemorySSA.cpp2
-rw-r--r--unittests/Analysis/MemorySSA.cpp42
3 files changed, 45 insertions, 3 deletions
diff --git a/include/llvm/Analysis/MemorySSA.h b/include/llvm/Analysis/MemorySSA.h
index b382e9a5d18..cace882f60e 100644
--- a/include/llvm/Analysis/MemorySSA.h
+++ b/include/llvm/Analysis/MemorySSA.h
@@ -118,10 +118,10 @@ struct DefsOnlyTag {};
} // end namespace MSSAHelpers
-enum {
+enum : unsigned {
// Used to signify what the default invalid ID is for MemoryAccess's
// getID()
- INVALID_MEMORYACCESS_ID = 0
+ INVALID_MEMORYACCESS_ID = -1U
};
template <class T> class memoryaccess_def_iterator_base;
diff --git a/lib/Analysis/MemorySSA.cpp b/lib/Analysis/MemorySSA.cpp
index 6e9368c49d6..081344b41e2 100644
--- a/lib/Analysis/MemorySSA.cpp
+++ b/lib/Analysis/MemorySSA.cpp
@@ -1033,7 +1033,7 @@ void MemorySSA::markUnreachableAsLiveOnEntry(BasicBlock *BB) {
MemorySSA::MemorySSA(Function &Func, AliasAnalysis *AA, DominatorTree *DT)
: AA(AA), DT(DT), F(Func), LiveOnEntryDef(nullptr), Walker(nullptr),
- NextID(INVALID_MEMORYACCESS_ID) {
+ NextID(0) {
buildMemorySSA();
}
diff --git a/unittests/Analysis/MemorySSA.cpp b/unittests/Analysis/MemorySSA.cpp
index affa0e71820..326a62efb44 100644
--- a/unittests/Analysis/MemorySSA.cpp
+++ b/unittests/Analysis/MemorySSA.cpp
@@ -909,3 +909,45 @@ TEST_F(MemorySSATest, Irreducible) {
Updater.insertUse(LoadAccess);
MSSA.verifyMemorySSA();
}
+
+TEST_F(MemorySSATest, MoveToBeforeLiveOnEntryInvalidatesCache) {
+ // Create:
+ // %1 = alloca i8
+ // ; 1 = MemoryDef(liveOnEntry)
+ // store i8 0, i8* %1
+ // ; 2 = MemoryDef(1)
+ // store i8 0, i8* %1
+ //
+ // ...And be sure that MSSA's caching doesn't give us `1` for the clobber of
+ // `2` after `1` is removed.
+ IRBuilder<> B(C);
+ F = Function::Create(
+ FunctionType::get(B.getVoidTy(), {B.getInt8PtrTy()}, false),
+ GlobalValue::ExternalLinkage, "F", &M);
+
+ BasicBlock *Entry = BasicBlock::Create(C, "if", F);
+ B.SetInsertPoint(Entry);
+
+ Value *A = B.CreateAlloca(B.getInt8Ty());
+ StoreInst *StoreA = B.CreateStore(B.getInt8(0), A);
+ StoreInst *StoreB = B.CreateStore(B.getInt8(0), A);
+
+ setupAnalyses();
+
+ MemorySSA &MSSA = *Analyses->MSSA;
+
+ auto *DefA = cast<MemoryDef>(MSSA.getMemoryAccess(StoreA));
+ auto *DefB = cast<MemoryDef>(MSSA.getMemoryAccess(StoreB));
+
+ MemoryAccess *BClobber = MSSA.getWalker()->getClobberingMemoryAccess(DefB);
+ ASSERT_EQ(DefA, BClobber);
+
+ MemorySSAUpdater(&MSSA).removeMemoryAccess(DefA);
+ StoreA->eraseFromParent();
+
+ EXPECT_EQ(DefB->getDefiningAccess(), MSSA.getLiveOnEntryDef());
+
+ EXPECT_EQ(MSSA.getWalker()->getClobberingMemoryAccess(DefB),
+ MSSA.getLiveOnEntryDef())
+ << "(DefA = " << DefA << ")";
+}