Daniel Berlin | 83fc77b | 2016-03-01 18:46:54 +0000 | [diff] [blame] | 1 | //===- MemorySSA.cpp - Unit tests for MemorySSA ---------------------------===// |
| 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
| 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
| 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
Daniel Berlin | 83fc77b | 2016-03-01 18:46:54 +0000 | [diff] [blame] | 9 | #include "llvm/Transforms/Utils/MemorySSA.h" |
| 10 | #include "llvm/Analysis/AliasAnalysis.h" |
| 11 | #include "llvm/Analysis/BasicAliasAnalysis.h" |
| 12 | #include "llvm/IR/BasicBlock.h" |
Daniel Berlin | 1430026 | 2016-06-21 18:39:20 +0000 | [diff] [blame] | 13 | #include "llvm/IR/DataLayout.h" |
Daniel Berlin | 83fc77b | 2016-03-01 18:46:54 +0000 | [diff] [blame] | 14 | #include "llvm/IR/Dominators.h" |
| 15 | #include "llvm/IR/IRBuilder.h" |
| 16 | #include "llvm/IR/Instructions.h" |
| 17 | #include "llvm/IR/LLVMContext.h" |
| 18 | #include "gtest/gtest.h" |
| 19 | |
| 20 | using namespace llvm; |
| 21 | |
George Burgess IV | 1b1fef3 | 2016-04-29 18:42:55 +0000 | [diff] [blame] | 22 | const static char DLString[] = "e-i64:64-f80:128-n8:16:32:64-S128"; |
Daniel Berlin | 83fc77b | 2016-03-01 18:46:54 +0000 | [diff] [blame] | 23 | |
George Burgess IV | 1b1fef3 | 2016-04-29 18:42:55 +0000 | [diff] [blame] | 24 | /// There's a lot of common setup between these tests. This fixture helps reduce |
| 25 | /// that. Tests should mock up a function, store it in F, and then call |
| 26 | /// setupAnalyses(). |
| 27 | class MemorySSATest : public testing::Test { |
| 28 | protected: |
| 29 | // N.B. Many of these members depend on each other (e.g. the Module depends on |
| 30 | // the Context, etc.). So, order matters here (and in TestAnalyses). |
| 31 | LLVMContext C; |
| 32 | Module M; |
| 33 | IRBuilder<> B; |
| 34 | DataLayout DL; |
| 35 | TargetLibraryInfoImpl TLII; |
| 36 | TargetLibraryInfo TLI; |
| 37 | Function *F; |
| 38 | |
| 39 | // Things that we need to build after the function is created. |
| 40 | struct TestAnalyses { |
| 41 | DominatorTree DT; |
| 42 | AssumptionCache AC; |
| 43 | AAResults AA; |
| 44 | BasicAAResult BAA; |
| 45 | MemorySSA MSSA; |
Geoff Berry | b96d3b2 | 2016-06-01 21:30:40 +0000 | [diff] [blame] | 46 | MemorySSAWalker *Walker; |
George Burgess IV | 1b1fef3 | 2016-04-29 18:42:55 +0000 | [diff] [blame] | 47 | |
| 48 | TestAnalyses(MemorySSATest &Test) |
| 49 | : DT(*Test.F), AC(*Test.F), AA(Test.TLI), |
Geoff Berry | b96d3b2 | 2016-06-01 21:30:40 +0000 | [diff] [blame] | 50 | BAA(Test.DL, Test.TLI, AC, &DT), MSSA(*Test.F, &AA, &DT) { |
George Burgess IV | 1b1fef3 | 2016-04-29 18:42:55 +0000 | [diff] [blame] | 51 | AA.addAAResult(BAA); |
Geoff Berry | b96d3b2 | 2016-06-01 21:30:40 +0000 | [diff] [blame] | 52 | Walker = MSSA.getWalker(); |
George Burgess IV | 1b1fef3 | 2016-04-29 18:42:55 +0000 | [diff] [blame] | 53 | } |
| 54 | }; |
| 55 | |
| 56 | std::unique_ptr<TestAnalyses> Analyses; |
| 57 | |
| 58 | void setupAnalyses() { |
| 59 | assert(F); |
| 60 | Analyses.reset(new TestAnalyses(*this)); |
| 61 | } |
| 62 | |
| 63 | public: |
| 64 | MemorySSATest() |
| 65 | : M("MemorySSATest", C), B(C), DL(DLString), TLI(TLII), F(nullptr) {} |
| 66 | }; |
| 67 | |
Daniel Berlin | 1430026 | 2016-06-21 18:39:20 +0000 | [diff] [blame] | 68 | TEST_F(MemorySSATest, CreateALoadAndPhi) { |
| 69 | // We create a diamond where there is a store on one side, and then after |
Daniel Berlin | cdda3ce | 2016-07-31 21:08:10 +0000 | [diff] [blame] | 70 | // building MemorySSA, create a load after the merge point, and use it to test |
Daniel Berlin | 1430026 | 2016-06-21 18:39:20 +0000 | [diff] [blame] | 71 | // updating by creating an access for the load and a memoryphi. |
| 72 | F = Function::Create( |
| 73 | FunctionType::get(B.getVoidTy(), {B.getInt8PtrTy()}, false), |
| 74 | GlobalValue::ExternalLinkage, "F", &M); |
| 75 | BasicBlock *Entry(BasicBlock::Create(C, "", F)); |
| 76 | BasicBlock *Left(BasicBlock::Create(C, "", F)); |
| 77 | BasicBlock *Right(BasicBlock::Create(C, "", F)); |
| 78 | BasicBlock *Merge(BasicBlock::Create(C, "", F)); |
| 79 | B.SetInsertPoint(Entry); |
| 80 | B.CreateCondBr(B.getTrue(), Left, Right); |
| 81 | B.SetInsertPoint(Left); |
| 82 | Argument *PointerArg = &*F->arg_begin(); |
| 83 | StoreInst *StoreInst = B.CreateStore(B.getInt8(16), PointerArg); |
| 84 | BranchInst::Create(Merge, Left); |
| 85 | BranchInst::Create(Merge, Right); |
| 86 | |
| 87 | setupAnalyses(); |
| 88 | MemorySSA &MSSA = Analyses->MSSA; |
| 89 | // Add the load |
| 90 | B.SetInsertPoint(Merge); |
| 91 | LoadInst *LoadInst = B.CreateLoad(PointerArg); |
| 92 | // Should be no phi to start |
| 93 | EXPECT_EQ(MSSA.getMemoryAccess(Merge), nullptr); |
| 94 | |
| 95 | // Create the phi |
| 96 | MemoryPhi *MP = MSSA.createMemoryPhi(Merge); |
| 97 | MemoryDef *StoreAccess = cast<MemoryDef>(MSSA.getMemoryAccess(StoreInst)); |
| 98 | MP->addIncoming(StoreAccess, Left); |
| 99 | MP->addIncoming(MSSA.getLiveOnEntryDef(), Right); |
| 100 | |
| 101 | // Create the load memory acccess |
| 102 | MemoryUse *LoadAccess = cast<MemoryUse>( |
| 103 | MSSA.createMemoryAccessInBB(LoadInst, MP, Merge, MemorySSA::Beginning)); |
| 104 | MemoryAccess *DefiningAccess = LoadAccess->getDefiningAccess(); |
| 105 | EXPECT_TRUE(isa<MemoryPhi>(DefiningAccess)); |
| 106 | MSSA.verifyMemorySSA(); |
| 107 | } |
| 108 | |
Daniel Berlin | 5130cc8 | 2016-07-31 21:08:20 +0000 | [diff] [blame] | 109 | TEST_F(MemorySSATest, MoveAStore) { |
| 110 | // We create a diamond where there is a in the entry, a store on one side, and |
| 111 | // a load at the end. After building MemorySSA, we test updating by moving |
| 112 | // the store from the side block to the entry block. |
| 113 | F = Function::Create( |
| 114 | FunctionType::get(B.getVoidTy(), {B.getInt8PtrTy()}, false), |
| 115 | GlobalValue::ExternalLinkage, "F", &M); |
| 116 | BasicBlock *Entry(BasicBlock::Create(C, "", F)); |
| 117 | BasicBlock *Left(BasicBlock::Create(C, "", F)); |
| 118 | BasicBlock *Right(BasicBlock::Create(C, "", F)); |
| 119 | BasicBlock *Merge(BasicBlock::Create(C, "", F)); |
| 120 | B.SetInsertPoint(Entry); |
| 121 | Argument *PointerArg = &*F->arg_begin(); |
| 122 | StoreInst *EntryStore = B.CreateStore(B.getInt8(16), PointerArg); |
| 123 | B.CreateCondBr(B.getTrue(), Left, Right); |
| 124 | B.SetInsertPoint(Left); |
| 125 | StoreInst *SideStore = B.CreateStore(B.getInt8(16), PointerArg); |
| 126 | BranchInst::Create(Merge, Left); |
| 127 | BranchInst::Create(Merge, Right); |
| 128 | B.SetInsertPoint(Merge); |
| 129 | B.CreateLoad(PointerArg); |
| 130 | setupAnalyses(); |
| 131 | MemorySSA &MSSA = Analyses->MSSA; |
| 132 | |
| 133 | // Move the store |
| 134 | SideStore->moveBefore(Entry->getTerminator()); |
| 135 | MemoryAccess *EntryStoreAccess = MSSA.getMemoryAccess(EntryStore); |
| 136 | MemoryAccess *SideStoreAccess = MSSA.getMemoryAccess(SideStore); |
| 137 | MemoryAccess *NewStoreAccess = MSSA.createMemoryAccessAfter(SideStore, |
| 138 | EntryStoreAccess, |
| 139 | EntryStoreAccess); |
| 140 | EntryStoreAccess->replaceAllUsesWith(NewStoreAccess); |
| 141 | MSSA.removeMemoryAccess(SideStoreAccess); |
| 142 | MSSA.verifyMemorySSA(); |
| 143 | } |
| 144 | |
Daniel Berlin | 1430026 | 2016-06-21 18:39:20 +0000 | [diff] [blame] | 145 | TEST_F(MemorySSATest, RemoveAPhi) { |
| 146 | // We create a diamond where there is a store on one side, and then a load |
| 147 | // after the merge point. This enables us to test a bunch of different |
| 148 | // removal cases. |
| 149 | F = Function::Create( |
| 150 | FunctionType::get(B.getVoidTy(), {B.getInt8PtrTy()}, false), |
| 151 | GlobalValue::ExternalLinkage, "F", &M); |
| 152 | BasicBlock *Entry(BasicBlock::Create(C, "", F)); |
| 153 | BasicBlock *Left(BasicBlock::Create(C, "", F)); |
| 154 | BasicBlock *Right(BasicBlock::Create(C, "", F)); |
| 155 | BasicBlock *Merge(BasicBlock::Create(C, "", F)); |
| 156 | B.SetInsertPoint(Entry); |
| 157 | B.CreateCondBr(B.getTrue(), Left, Right); |
| 158 | B.SetInsertPoint(Left); |
| 159 | Argument *PointerArg = &*F->arg_begin(); |
| 160 | StoreInst *StoreInst = B.CreateStore(B.getInt8(16), PointerArg); |
| 161 | BranchInst::Create(Merge, Left); |
| 162 | BranchInst::Create(Merge, Right); |
| 163 | B.SetInsertPoint(Merge); |
| 164 | LoadInst *LoadInst = B.CreateLoad(PointerArg); |
| 165 | |
| 166 | setupAnalyses(); |
| 167 | MemorySSA &MSSA = Analyses->MSSA; |
| 168 | // Before, the load will be a use of a phi<store, liveonentry>. |
| 169 | MemoryUse *LoadAccess = cast<MemoryUse>(MSSA.getMemoryAccess(LoadInst)); |
| 170 | MemoryDef *StoreAccess = cast<MemoryDef>(MSSA.getMemoryAccess(StoreInst)); |
| 171 | MemoryAccess *DefiningAccess = LoadAccess->getDefiningAccess(); |
| 172 | EXPECT_TRUE(isa<MemoryPhi>(DefiningAccess)); |
| 173 | // Kill the store |
| 174 | MSSA.removeMemoryAccess(StoreAccess); |
| 175 | MemoryPhi *MP = cast<MemoryPhi>(DefiningAccess); |
| 176 | // Verify the phi ended up as liveonentry, liveonentry |
| 177 | for (auto &Op : MP->incoming_values()) |
| 178 | EXPECT_TRUE(MSSA.isLiveOnEntryDef(cast<MemoryAccess>(Op.get()))); |
| 179 | // Replace the phi uses with the live on entry def |
| 180 | MP->replaceAllUsesWith(MSSA.getLiveOnEntryDef()); |
| 181 | // Verify the load is now defined by liveOnEntryDef |
| 182 | EXPECT_TRUE(MSSA.isLiveOnEntryDef(LoadAccess->getDefiningAccess())); |
| 183 | // Remove the PHI |
| 184 | MSSA.removeMemoryAccess(MP); |
| 185 | MSSA.verifyMemorySSA(); |
| 186 | } |
| 187 | |
George Burgess IV | 1b1fef3 | 2016-04-29 18:42:55 +0000 | [diff] [blame] | 188 | TEST_F(MemorySSATest, RemoveMemoryAccess) { |
Daniel Berlin | 83fc77b | 2016-03-01 18:46:54 +0000 | [diff] [blame] | 189 | // We create a diamond where there is a store on one side, and then a load |
| 190 | // after the merge point. This enables us to test a bunch of different |
| 191 | // removal cases. |
George Burgess IV | 1b1fef3 | 2016-04-29 18:42:55 +0000 | [diff] [blame] | 192 | F = Function::Create( |
Daniel Berlin | 83fc77b | 2016-03-01 18:46:54 +0000 | [diff] [blame] | 193 | FunctionType::get(B.getVoidTy(), {B.getInt8PtrTy()}, false), |
George Burgess IV | 1b1fef3 | 2016-04-29 18:42:55 +0000 | [diff] [blame] | 194 | GlobalValue::ExternalLinkage, "F", &M); |
Daniel Berlin | 6412002 | 2016-03-02 21:16:28 +0000 | [diff] [blame] | 195 | BasicBlock *Entry(BasicBlock::Create(C, "", F)); |
| 196 | BasicBlock *Left(BasicBlock::Create(C, "", F)); |
| 197 | BasicBlock *Right(BasicBlock::Create(C, "", F)); |
| 198 | BasicBlock *Merge(BasicBlock::Create(C, "", F)); |
Daniel Berlin | 83fc77b | 2016-03-01 18:46:54 +0000 | [diff] [blame] | 199 | B.SetInsertPoint(Entry); |
| 200 | B.CreateCondBr(B.getTrue(), Left, Right); |
| 201 | B.SetInsertPoint(Left); |
| 202 | Argument *PointerArg = &*F->arg_begin(); |
| 203 | StoreInst *StoreInst = B.CreateStore(B.getInt8(16), PointerArg); |
| 204 | BranchInst::Create(Merge, Left); |
| 205 | BranchInst::Create(Merge, Right); |
| 206 | B.SetInsertPoint(Merge); |
| 207 | LoadInst *LoadInst = B.CreateLoad(PointerArg); |
| 208 | |
George Burgess IV | 1b1fef3 | 2016-04-29 18:42:55 +0000 | [diff] [blame] | 209 | setupAnalyses(); |
| 210 | MemorySSA &MSSA = Analyses->MSSA; |
George Burgess IV | d8cdc36 | 2016-06-20 19:13:07 +0000 | [diff] [blame] | 211 | MemorySSAWalker *Walker = Analyses->Walker; |
George Burgess IV | 1b1fef3 | 2016-04-29 18:42:55 +0000 | [diff] [blame] | 212 | |
Daniel Berlin | 83fc77b | 2016-03-01 18:46:54 +0000 | [diff] [blame] | 213 | // Before, the load will be a use of a phi<store, liveonentry>. It should be |
| 214 | // the same after. |
George Burgess IV | 1b1fef3 | 2016-04-29 18:42:55 +0000 | [diff] [blame] | 215 | MemoryUse *LoadAccess = cast<MemoryUse>(MSSA.getMemoryAccess(LoadInst)); |
| 216 | MemoryDef *StoreAccess = cast<MemoryDef>(MSSA.getMemoryAccess(StoreInst)); |
Daniel Berlin | 83fc77b | 2016-03-01 18:46:54 +0000 | [diff] [blame] | 217 | MemoryAccess *DefiningAccess = LoadAccess->getDefiningAccess(); |
| 218 | EXPECT_TRUE(isa<MemoryPhi>(DefiningAccess)); |
| 219 | // The load is currently clobbered by one of the phi arguments, so the walker |
| 220 | // should determine the clobbering access as the phi. |
| 221 | EXPECT_EQ(DefiningAccess, Walker->getClobberingMemoryAccess(LoadInst)); |
George Burgess IV | 1b1fef3 | 2016-04-29 18:42:55 +0000 | [diff] [blame] | 222 | MSSA.removeMemoryAccess(StoreAccess); |
| 223 | MSSA.verifyMemorySSA(); |
Daniel Berlin | 83fc77b | 2016-03-01 18:46:54 +0000 | [diff] [blame] | 224 | // After the removeaccess, let's see if we got the right accesses |
| 225 | // The load should still point to the phi ... |
| 226 | EXPECT_EQ(DefiningAccess, LoadAccess->getDefiningAccess()); |
| 227 | // but we should now get live on entry for the clobbering definition of the |
| 228 | // load, since it will walk past the phi node since every argument is the |
| 229 | // same. |
| 230 | EXPECT_TRUE( |
George Burgess IV | 1b1fef3 | 2016-04-29 18:42:55 +0000 | [diff] [blame] | 231 | MSSA.isLiveOnEntryDef(Walker->getClobberingMemoryAccess(LoadInst))); |
Daniel Berlin | 83fc77b | 2016-03-01 18:46:54 +0000 | [diff] [blame] | 232 | |
| 233 | // The phi should now be a two entry phi with two live on entry defs. |
| 234 | for (const auto &Op : DefiningAccess->operands()) { |
| 235 | MemoryAccess *Operand = cast<MemoryAccess>(&*Op); |
George Burgess IV | 1b1fef3 | 2016-04-29 18:42:55 +0000 | [diff] [blame] | 236 | EXPECT_TRUE(MSSA.isLiveOnEntryDef(Operand)); |
Daniel Berlin | 83fc77b | 2016-03-01 18:46:54 +0000 | [diff] [blame] | 237 | } |
| 238 | |
| 239 | // Now we try to remove the single valued phi |
George Burgess IV | 1b1fef3 | 2016-04-29 18:42:55 +0000 | [diff] [blame] | 240 | MSSA.removeMemoryAccess(DefiningAccess); |
| 241 | MSSA.verifyMemorySSA(); |
Daniel Berlin | 83fc77b | 2016-03-01 18:46:54 +0000 | [diff] [blame] | 242 | // Now the load should be a load of live on entry. |
George Burgess IV | 1b1fef3 | 2016-04-29 18:42:55 +0000 | [diff] [blame] | 243 | EXPECT_TRUE(MSSA.isLiveOnEntryDef(LoadAccess->getDefiningAccess())); |
| 244 | } |
| 245 | |
| 246 | // We had a bug with caching where the walker would report MemoryDef#3's clobber |
| 247 | // (below) was MemoryDef#1. |
| 248 | // |
| 249 | // define void @F(i8*) { |
| 250 | // %A = alloca i8, i8 1 |
| 251 | // ; 1 = MemoryDef(liveOnEntry) |
| 252 | // store i8 0, i8* %A |
| 253 | // ; 2 = MemoryDef(1) |
| 254 | // store i8 1, i8* %A |
| 255 | // ; 3 = MemoryDef(2) |
| 256 | // store i8 2, i8* %A |
| 257 | // } |
| 258 | TEST_F(MemorySSATest, TestTripleStore) { |
Daniel Berlin | 1430026 | 2016-06-21 18:39:20 +0000 | [diff] [blame] | 259 | F = Function::Create(FunctionType::get(B.getVoidTy(), {}, false), |
| 260 | GlobalValue::ExternalLinkage, "F", &M); |
George Burgess IV | 1b1fef3 | 2016-04-29 18:42:55 +0000 | [diff] [blame] | 261 | B.SetInsertPoint(BasicBlock::Create(C, "", F)); |
| 262 | Type *Int8 = Type::getInt8Ty(C); |
| 263 | Value *Alloca = B.CreateAlloca(Int8, ConstantInt::get(Int8, 1), "A"); |
| 264 | StoreInst *S1 = B.CreateStore(ConstantInt::get(Int8, 0), Alloca); |
| 265 | StoreInst *S2 = B.CreateStore(ConstantInt::get(Int8, 1), Alloca); |
| 266 | StoreInst *S3 = B.CreateStore(ConstantInt::get(Int8, 2), Alloca); |
| 267 | |
| 268 | setupAnalyses(); |
| 269 | MemorySSA &MSSA = Analyses->MSSA; |
George Burgess IV | d8cdc36 | 2016-06-20 19:13:07 +0000 | [diff] [blame] | 270 | MemorySSAWalker *Walker = Analyses->Walker; |
George Burgess IV | 1b1fef3 | 2016-04-29 18:42:55 +0000 | [diff] [blame] | 271 | |
| 272 | unsigned I = 0; |
| 273 | for (StoreInst *V : {S1, S2, S3}) { |
| 274 | // Everything should be clobbered by its defining access |
| 275 | MemoryAccess *DefiningAccess = |
| 276 | cast<MemoryUseOrDef>(MSSA.getMemoryAccess(V))->getDefiningAccess(); |
| 277 | MemoryAccess *WalkerClobber = Walker->getClobberingMemoryAccess(V); |
| 278 | EXPECT_EQ(DefiningAccess, WalkerClobber) |
| 279 | << "Store " << I << " doesn't have the correct clobbering access"; |
| 280 | // EXPECT_EQ expands such that if we increment I above, it won't get |
| 281 | // incremented except when we try to print the error message. |
| 282 | ++I; |
| 283 | } |
| 284 | } |
| 285 | |
| 286 | // ...And fixing the above bug made it obvious that, when walking, MemorySSA's |
| 287 | // walker was caching the initial node it walked. This was fine (albeit |
| 288 | // mostly redundant) unless the initial node being walked is a clobber for the |
| 289 | // query. In that case, we'd cache that the node clobbered itself. |
| 290 | TEST_F(MemorySSATest, TestStoreAndLoad) { |
Daniel Berlin | 1430026 | 2016-06-21 18:39:20 +0000 | [diff] [blame] | 291 | F = Function::Create(FunctionType::get(B.getVoidTy(), {}, false), |
| 292 | GlobalValue::ExternalLinkage, "F", &M); |
George Burgess IV | 1b1fef3 | 2016-04-29 18:42:55 +0000 | [diff] [blame] | 293 | B.SetInsertPoint(BasicBlock::Create(C, "", F)); |
| 294 | Type *Int8 = Type::getInt8Ty(C); |
| 295 | Value *Alloca = B.CreateAlloca(Int8, ConstantInt::get(Int8, 1), "A"); |
| 296 | Instruction *SI = B.CreateStore(ConstantInt::get(Int8, 0), Alloca); |
| 297 | Instruction *LI = B.CreateLoad(Alloca); |
| 298 | |
| 299 | setupAnalyses(); |
| 300 | MemorySSA &MSSA = Analyses->MSSA; |
George Burgess IV | d8cdc36 | 2016-06-20 19:13:07 +0000 | [diff] [blame] | 301 | MemorySSAWalker *Walker = Analyses->Walker; |
George Burgess IV | 1b1fef3 | 2016-04-29 18:42:55 +0000 | [diff] [blame] | 302 | |
| 303 | MemoryAccess *LoadClobber = Walker->getClobberingMemoryAccess(LI); |
| 304 | EXPECT_EQ(LoadClobber, MSSA.getMemoryAccess(SI)); |
| 305 | EXPECT_TRUE(MSSA.isLiveOnEntryDef(Walker->getClobberingMemoryAccess(SI))); |
| 306 | } |
| 307 | |
| 308 | // Another bug (related to the above two fixes): It was noted that, given the |
| 309 | // following code: |
| 310 | // ; 1 = MemoryDef(liveOnEntry) |
| 311 | // store i8 0, i8* %1 |
| 312 | // |
| 313 | // ...A query to getClobberingMemoryAccess(MemoryAccess*, MemoryLocation) would |
| 314 | // hand back the store (correctly). A later call to |
| 315 | // getClobberingMemoryAccess(const Instruction*) would also hand back the store |
| 316 | // (incorrectly; it should return liveOnEntry). |
| 317 | // |
| 318 | // This test checks that repeated calls to either function returns what they're |
| 319 | // meant to. |
| 320 | TEST_F(MemorySSATest, TestStoreDoubleQuery) { |
Daniel Berlin | 1430026 | 2016-06-21 18:39:20 +0000 | [diff] [blame] | 321 | F = Function::Create(FunctionType::get(B.getVoidTy(), {}, false), |
| 322 | GlobalValue::ExternalLinkage, "F", &M); |
George Burgess IV | 1b1fef3 | 2016-04-29 18:42:55 +0000 | [diff] [blame] | 323 | B.SetInsertPoint(BasicBlock::Create(C, "", F)); |
| 324 | Type *Int8 = Type::getInt8Ty(C); |
| 325 | Value *Alloca = B.CreateAlloca(Int8, ConstantInt::get(Int8, 1), "A"); |
| 326 | StoreInst *SI = B.CreateStore(ConstantInt::get(Int8, 0), Alloca); |
| 327 | |
| 328 | setupAnalyses(); |
| 329 | MemorySSA &MSSA = Analyses->MSSA; |
George Burgess IV | d8cdc36 | 2016-06-20 19:13:07 +0000 | [diff] [blame] | 330 | MemorySSAWalker *Walker = Analyses->Walker; |
George Burgess IV | 1b1fef3 | 2016-04-29 18:42:55 +0000 | [diff] [blame] | 331 | |
| 332 | MemoryAccess *StoreAccess = MSSA.getMemoryAccess(SI); |
| 333 | MemoryLocation StoreLoc = MemoryLocation::get(SI); |
Daniel Berlin | 1430026 | 2016-06-21 18:39:20 +0000 | [diff] [blame] | 334 | MemoryAccess *Clobber = |
| 335 | Walker->getClobberingMemoryAccess(StoreAccess, StoreLoc); |
George Burgess IV | 1b1fef3 | 2016-04-29 18:42:55 +0000 | [diff] [blame] | 336 | MemoryAccess *LiveOnEntry = Walker->getClobberingMemoryAccess(SI); |
| 337 | |
| 338 | EXPECT_EQ(Clobber, StoreAccess); |
| 339 | EXPECT_TRUE(MSSA.isLiveOnEntryDef(LiveOnEntry)); |
| 340 | |
| 341 | // Try again (with entries in the cache already) for good measure... |
| 342 | Clobber = Walker->getClobberingMemoryAccess(StoreAccess, StoreLoc); |
| 343 | LiveOnEntry = Walker->getClobberingMemoryAccess(SI); |
| 344 | EXPECT_EQ(Clobber, StoreAccess); |
| 345 | EXPECT_TRUE(MSSA.isLiveOnEntryDef(LiveOnEntry)); |
Daniel Berlin | 83fc77b | 2016-03-01 18:46:54 +0000 | [diff] [blame] | 346 | } |