Index: llvm/unittests/Analysis/AliasAnalysisTest.cpp =================================================================== --- llvm/unittests/Analysis/AliasAnalysisTest.cpp +++ llvm/unittests/Analysis/AliasAnalysisTest.cpp @@ -162,56 +162,55 @@ } }; +static Instruction *getInstructionByName(Function &F, StringRef Name) { + for (auto &I : instructions(F)) + if (I.getName() == Name) + return &I; + llvm_unreachable("Expected to find instruction!"); +} + TEST_F(AliasAnalysisTest, getModRefInfo) { // Setup function. - FunctionType *FTy = - FunctionType::get(Type::getVoidTy(C), std::vector(), false); - auto *F = Function::Create(FTy, Function::ExternalLinkage, "f", M); - auto *BB = BasicBlock::Create(C, "entry", F); - auto IntType = Type::getInt32Ty(C); - auto PtrType = Type::getInt32PtrTy(C); - auto *Value = ConstantInt::get(IntType, 42); - auto *Addr = ConstantPointerNull::get(PtrType); - auto Alignment = Align(IntType->getBitWidth() / 8); - - auto *Store1 = new StoreInst(Value, Addr, BB); - auto *Load1 = new LoadInst(IntType, Addr, "load", BB); - auto *Add1 = BinaryOperator::CreateAdd(Value, Value, "add", BB); - auto *VAArg1 = new VAArgInst(Addr, PtrType, "vaarg", BB); - auto *CmpXChg1 = new AtomicCmpXchgInst( - Addr, ConstantInt::get(IntType, 0), ConstantInt::get(IntType, 1), - Alignment, AtomicOrdering::Monotonic, AtomicOrdering::Monotonic, - SyncScope::System, BB); - auto *AtomicRMW = new AtomicRMWInst( - AtomicRMWInst::Xchg, Addr, ConstantInt::get(IntType, 1), Alignment, - AtomicOrdering::Monotonic, SyncScope::System, BB); - - ReturnInst::Create(C, nullptr, BB); + LLVMContext C; + SMDiagnostic Err; + std::unique_ptr M = parseAssemblyString(R"( + define void @f() { + entry: + store i32 42, ptr null, align 4 + %load = load i32, ptr null, align 4 + %add = add i32 42, 42 + %vaarg = va_arg ptr null, ptr + %cmpxchg = cmpxchg ptr null, i32 0, i32 1 monotonic monotonic, align 4 + %atomicrmw = atomicrmw xchg ptr null, i32 1 monotonic, align 4 + ret void + } + )", + Err, C); + Function *F = M->getFunction("f"); + Instruction *Store = &*inst_begin(F); + Instruction *Load = getInstructionByName(*F, "load"); + Instruction *Add = getInstructionByName(*F, "add"); + Instruction *VAArg = getInstructionByName(*F, "vaarg"); + Instruction *CmpXChg = getInstructionByName(*F, "cmpxchg"); + Instruction *AtomicRMW = getInstructionByName(*F, "atomicrmw"); auto &AA = getAAResults(*F); // Check basic results - EXPECT_EQ(AA.getModRefInfo(Store1, MemoryLocation()), ModRefInfo::Mod); - EXPECT_EQ(AA.getModRefInfo(Store1, std::nullopt), ModRefInfo::Mod); - EXPECT_EQ(AA.getModRefInfo(Load1, MemoryLocation()), ModRefInfo::Ref); - EXPECT_EQ(AA.getModRefInfo(Load1, std::nullopt), ModRefInfo::Ref); - EXPECT_EQ(AA.getModRefInfo(Add1, MemoryLocation()), ModRefInfo::NoModRef); - EXPECT_EQ(AA.getModRefInfo(Add1, std::nullopt), ModRefInfo::NoModRef); - EXPECT_EQ(AA.getModRefInfo(VAArg1, MemoryLocation()), ModRefInfo::ModRef); - EXPECT_EQ(AA.getModRefInfo(VAArg1, std::nullopt), ModRefInfo::ModRef); - EXPECT_EQ(AA.getModRefInfo(CmpXChg1, MemoryLocation()), ModRefInfo::ModRef); - EXPECT_EQ(AA.getModRefInfo(CmpXChg1, std::nullopt), ModRefInfo::ModRef); + EXPECT_EQ(AA.getModRefInfo(Store, MemoryLocation()), ModRefInfo::Mod); + EXPECT_EQ(AA.getModRefInfo(Store, std::nullopt), ModRefInfo::Mod); + EXPECT_EQ(AA.getModRefInfo(Load, MemoryLocation()), ModRefInfo::Ref); + EXPECT_EQ(AA.getModRefInfo(Load, std::nullopt), ModRefInfo::Ref); + EXPECT_EQ(AA.getModRefInfo(Add, MemoryLocation()), ModRefInfo::NoModRef); + EXPECT_EQ(AA.getModRefInfo(Add, std::nullopt), ModRefInfo::NoModRef); + EXPECT_EQ(AA.getModRefInfo(VAArg, MemoryLocation()), ModRefInfo::ModRef); + EXPECT_EQ(AA.getModRefInfo(VAArg, std::nullopt), ModRefInfo::ModRef); + EXPECT_EQ(AA.getModRefInfo(CmpXChg, MemoryLocation()), ModRefInfo::ModRef); + EXPECT_EQ(AA.getModRefInfo(CmpXChg, std::nullopt), ModRefInfo::ModRef); EXPECT_EQ(AA.getModRefInfo(AtomicRMW, MemoryLocation()), ModRefInfo::ModRef); EXPECT_EQ(AA.getModRefInfo(AtomicRMW, std::nullopt), ModRefInfo::ModRef); } -static Instruction *getInstructionByName(Function &F, StringRef Name) { - for (auto &I : instructions(F)) - if (I.getName() == Name) - return &I; - llvm_unreachable("Expected to find instruction!"); -} - TEST_F(AliasAnalysisTest, BatchAAPhiCycles) { LLVMContext C; SMDiagnostic Err;