llvm.org GIT mirror llvm / cbd8b04
[MemorySSA] Invalidate def caches on deletion The only cases I can come up with where this invalidation needs to happen is when there's a deletion somewhere. If we find more creative test-cases, we can probably go with another approach mentioned on PR36529. Fixes PR36529. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@326177 91177308-0d34-0410-b5e6-96231b3b80d8 George Burgess IV 2 years ago
2 changed file(s) with 52 addition(s) and 2 deletion(s). Raw diff Collapse all Expand all
380380 OptimizedID = getDefiningAccess()->getID();
381381 }
382382
383 MemoryAccess *getOptimized() const { return Optimized; }
383 MemoryAccess *getOptimized() const {
384 return cast_or_null(Optimized);
385 }
384386
385387 bool isOptimized() const {
386388 return getOptimized() && getDefiningAccess() &&
400402
401403 const unsigned ID;
402404 unsigned OptimizedID = INVALID_MEMORYACCESS_ID;
403 MemoryAccess *Optimized = nullptr;
405 WeakVH Optimized;
404406 };
405407
406408 template <>
950950 MSSA.getLiveOnEntryDef())
951951 << "(DefA = " << DefA << ")";
952952 }
953
954 TEST_F(MemorySSATest, RemovingDefInvalidatesCache) {
955 // Create:
956 // %x = alloca i8
957 // %y = alloca i8
958 // ; 1 = MemoryDef(liveOnEntry)
959 // store i8 0, i8* %x
960 // ; 2 = MemoryDef(1)
961 // store i8 0, i8* %y
962 // ; 3 = MemoryDef(2)
963 // store i8 0, i8* %x
964 //
965 // And be sure that MSSA's caching handles the removal of def `1`
966 // appropriately.
967 IRBuilder<> B(C);
968 F = Function::Create(
969 FunctionType::get(B.getVoidTy(), {B.getInt8PtrTy()}, false),
970 GlobalValue::ExternalLinkage, "F", &M);
971
972 BasicBlock *Entry = BasicBlock::Create(C, "if", F);
973 B.SetInsertPoint(Entry);
974
975 Value *X = B.CreateAlloca(B.getInt8Ty());
976 Value *Y = B.CreateAlloca(B.getInt8Ty());
977 StoreInst *StoreX1 = B.CreateStore(B.getInt8(0), X);
978 StoreInst *StoreY = B.CreateStore(B.getInt8(0), Y);
979 StoreInst *StoreX2 = B.CreateStore(B.getInt8(0), X);
980
981 setupAnalyses();
982
983 MemorySSA &MSSA = *Analyses->MSSA;
984
985 auto *DefX1 = cast(MSSA.getMemoryAccess(StoreX1));
986 auto *DefY = cast(MSSA.getMemoryAccess(StoreY));
987 auto *DefX2 = cast(MSSA.getMemoryAccess(StoreX2));
988
989 EXPECT_EQ(DefX2->getDefiningAccess(), DefY);
990 MemoryAccess *X2Clobber = MSSA.getWalker()->getClobberingMemoryAccess(DefX2);
991 ASSERT_EQ(DefX1, X2Clobber);
992
993 MemorySSAUpdater(&MSSA).removeMemoryAccess(DefX1);
994 StoreX1->eraseFromParent();
995
996 EXPECT_EQ(DefX2->getDefiningAccess(), DefY);
997 EXPECT_EQ(MSSA.getWalker()->getClobberingMemoryAccess(DefX2),
998 MSSA.getLiveOnEntryDef())
999 << "(DefX1 = " << DefX1 << ")";
1000 }