[llvm] r325971 - [MemorySSA] Fix a cache invalidation bug with removed accesses
George Burgess IV via llvm-commits
llvm-commits at lists.llvm.org
Fri Feb 23 15:07:18 PST 2018
Author: gbiv
Date: Fri Feb 23 15:07:18 2018
New Revision: 325971
URL: http://llvm.org/viewvc/llvm-project?rev=325971&view=rev
Log:
[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.
Modified:
llvm/trunk/include/llvm/Analysis/MemorySSA.h
llvm/trunk/lib/Analysis/MemorySSA.cpp
llvm/trunk/unittests/Analysis/MemorySSA.cpp
Modified: llvm/trunk/include/llvm/Analysis/MemorySSA.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Analysis/MemorySSA.h?rev=325971&r1=325970&r2=325971&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Analysis/MemorySSA.h (original)
+++ llvm/trunk/include/llvm/Analysis/MemorySSA.h Fri Feb 23 15:07:18 2018
@@ -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;
Modified: llvm/trunk/lib/Analysis/MemorySSA.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Analysis/MemorySSA.cpp?rev=325971&r1=325970&r2=325971&view=diff
==============================================================================
--- llvm/trunk/lib/Analysis/MemorySSA.cpp (original)
+++ llvm/trunk/lib/Analysis/MemorySSA.cpp Fri Feb 23 15:07:18 2018
@@ -1033,7 +1033,7 @@ void MemorySSA::markUnreachableAsLiveOnE
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();
}
Modified: llvm/trunk/unittests/Analysis/MemorySSA.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/unittests/Analysis/MemorySSA.cpp?rev=325971&r1=325970&r2=325971&view=diff
==============================================================================
--- llvm/trunk/unittests/Analysis/MemorySSA.cpp (original)
+++ llvm/trunk/unittests/Analysis/MemorySSA.cpp Fri Feb 23 15:07:18 2018
@@ -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 << ")";
+}
More information about the llvm-commits
mailing list