diff options
| author | Daniel Berlin <dberlin@dberlin.org> | 2016-07-31 21:08:20 +0000 |
|---|---|---|
| committer | Daniel Berlin <dberlin@dberlin.org> | 2016-07-31 21:08:20 +0000 |
| commit | 5130cc831a761450036ea88a888d20978213ca9a (patch) | |
| tree | 0b3b764ae4b9236f4323dc94c43af951fbc8e3f3 /llvm/unittests/Transforms/Utils/MemorySSA.cpp | |
| parent | cdda3ce478effa19f323035b3eb1f303c6a5609d (diff) | |
| download | bcm5719-llvm-5130cc831a761450036ea88a888d20978213ca9a.tar.gz bcm5719-llvm-5130cc831a761450036ea88a888d20978213ca9a.zip | |
Fix the MemorySSA updating API to enable people to create memory accesses before removing old ones
llvm-svn: 277309
Diffstat (limited to 'llvm/unittests/Transforms/Utils/MemorySSA.cpp')
| -rw-r--r-- | llvm/unittests/Transforms/Utils/MemorySSA.cpp | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/llvm/unittests/Transforms/Utils/MemorySSA.cpp b/llvm/unittests/Transforms/Utils/MemorySSA.cpp index 6916ff536bc..93bda62f75e 100644 --- a/llvm/unittests/Transforms/Utils/MemorySSA.cpp +++ b/llvm/unittests/Transforms/Utils/MemorySSA.cpp @@ -106,6 +106,42 @@ TEST_F(MemorySSATest, CreateALoadAndPhi) { MSSA.verifyMemorySSA(); } +TEST_F(MemorySSATest, MoveAStore) { + // We create a diamond where there is a in the entry, a store on one side, and + // a load at the end. After building MemorySSA, we test updating by moving + // the store from the side block to the entry block. + F = Function::Create( + FunctionType::get(B.getVoidTy(), {B.getInt8PtrTy()}, false), + GlobalValue::ExternalLinkage, "F", &M); + BasicBlock *Entry(BasicBlock::Create(C, "", F)); + BasicBlock *Left(BasicBlock::Create(C, "", F)); + BasicBlock *Right(BasicBlock::Create(C, "", F)); + BasicBlock *Merge(BasicBlock::Create(C, "", F)); + B.SetInsertPoint(Entry); + Argument *PointerArg = &*F->arg_begin(); + StoreInst *EntryStore = B.CreateStore(B.getInt8(16), PointerArg); + B.CreateCondBr(B.getTrue(), Left, Right); + B.SetInsertPoint(Left); + StoreInst *SideStore = B.CreateStore(B.getInt8(16), PointerArg); + BranchInst::Create(Merge, Left); + BranchInst::Create(Merge, Right); + B.SetInsertPoint(Merge); + B.CreateLoad(PointerArg); + setupAnalyses(); + MemorySSA &MSSA = Analyses->MSSA; + + // Move the store + SideStore->moveBefore(Entry->getTerminator()); + MemoryAccess *EntryStoreAccess = MSSA.getMemoryAccess(EntryStore); + MemoryAccess *SideStoreAccess = MSSA.getMemoryAccess(SideStore); + MemoryAccess *NewStoreAccess = MSSA.createMemoryAccessAfter(SideStore, + EntryStoreAccess, + EntryStoreAccess); + EntryStoreAccess->replaceAllUsesWith(NewStoreAccess); + MSSA.removeMemoryAccess(SideStoreAccess); + MSSA.verifyMemorySSA(); +} + TEST_F(MemorySSATest, RemoveAPhi) { // We create a diamond where there is a store on one side, and then a load // after the merge point. This enables us to test a bunch of different |

