llvm.org GIT mirror llvm / 3d23882
[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 George Burgess IV 2 years ago
3 changed file(s) with 45 addition(s) and 3 deletion(s). Raw diff Collapse all Expand all
117117
118118 } // end namespace MSSAHelpers
119119
120 enum {
120 enum : unsigned {
121121 // Used to signify what the default invalid ID is for MemoryAccess's
122122 // getID()
123 INVALID_MEMORYACCESS_ID = 0
123 INVALID_MEMORYACCESS_ID = -1U
124124 };
125125
126126 template class memoryaccess_def_iterator_base;
10321032
10331033 MemorySSA::MemorySSA(Function &Func, AliasAnalysis *AA, DominatorTree *DT)
10341034 : AA(AA), DT(DT), F(Func), LiveOnEntryDef(nullptr), Walker(nullptr),
1035 NextID(INVALID_MEMORYACCESS_ID) {
1035 NextID(0) {
10361036 buildMemorySSA();
10371037 }
10381038
908908 Updater.insertUse(LoadAccess);
909909 MSSA.verifyMemorySSA();
910910 }
911
912 TEST_F(MemorySSATest, MoveToBeforeLiveOnEntryInvalidatesCache) {
913 // Create:
914 // %1 = alloca i8
915 // ; 1 = MemoryDef(liveOnEntry)
916 // store i8 0, i8* %1
917 // ; 2 = MemoryDef(1)
918 // store i8 0, i8* %1
919 //
920 // ...And be sure that MSSA's caching doesn't give us `1` for the clobber of
921 // `2` after `1` is removed.
922 IRBuilder<> B(C);
923 F = Function::Create(
924 FunctionType::get(B.getVoidTy(), {B.getInt8PtrTy()}, false),
925 GlobalValue::ExternalLinkage, "F", &M);
926
927 BasicBlock *Entry = BasicBlock::Create(C, "if", F);
928 B.SetInsertPoint(Entry);
929
930 Value *A = B.CreateAlloca(B.getInt8Ty());
931 StoreInst *StoreA = B.CreateStore(B.getInt8(0), A);
932 StoreInst *StoreB = B.CreateStore(B.getInt8(0), A);
933
934 setupAnalyses();
935
936 MemorySSA &MSSA = *Analyses->MSSA;
937
938 auto *DefA = cast(MSSA.getMemoryAccess(StoreA));
939 auto *DefB = cast(MSSA.getMemoryAccess(StoreB));
940
941 MemoryAccess *BClobber = MSSA.getWalker()->getClobberingMemoryAccess(DefB);
942 ASSERT_EQ(DefA, BClobber);
943
944 MemorySSAUpdater(&MSSA).removeMemoryAccess(DefA);
945 StoreA->eraseFromParent();
946
947 EXPECT_EQ(DefB->getDefiningAccess(), MSSA.getLiveOnEntryDef());
948
949 EXPECT_EQ(MSSA.getWalker()->getClobberingMemoryAccess(DefB),
950 MSSA.getLiveOnEntryDef())
951 << "(DefA = " << DefA << ")";
952 }