diff --git a/llvm/unittests/Analysis/AliasAnalysisTest.cpp b/llvm/unittests/Analysis/AliasAnalysisTest.cpp index 6f0f6f5f6326..fcb73d519493 100644 --- a/llvm/unittests/Analysis/AliasAnalysisTest.cpp +++ b/llvm/unittests/Analysis/AliasAnalysisTest.cpp @@ -207,6 +207,48 @@ TEST_F(AliasAnalysisTest, getModRefInfo) { EXPECT_EQ(AA.getModRefInfo(AtomicRMW, None), 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; + std::unique_ptr M = parseAssemblyString(R"( + define void @f(i8* noalias %a) { + entry: + br label %loop + + loop: + %phi = phi i8* [ null, %entry ], [ %a2, %loop ] + %offset1 = phi i64 [ 0, %entry ], [ %offset2, %loop] + %offset2 = add i64 %offset1, 1 + %a1 = getelementptr i8, i8* %a, i64 %offset1 + %a2 = getelementptr i8, i8* %a, i64 %offset2 + br label %loop + } + )", Err, C); + + Function *F = M->getFunction("f"); + Instruction *Phi = getInstructionByName(*F, "phi"); + Instruction *A1 = getInstructionByName(*F, "a1"); + Instruction *A2 = getInstructionByName(*F, "a2"); + MemoryLocation PhiLoc(Phi, LocationSize::precise(1)); + MemoryLocation A1Loc(A1, LocationSize::precise(1)); + MemoryLocation A2Loc(A2, LocationSize::precise(1)); + + auto &AA = getAAResults(*F); + EXPECT_EQ(NoAlias, AA.alias(A1Loc, A2Loc)); + EXPECT_EQ(MayAlias, AA.alias(PhiLoc, A1Loc)); + + BatchAAResults BatchAA(AA); + EXPECT_EQ(NoAlias, BatchAA.alias(A1Loc, A2Loc)); + EXPECT_EQ(NoAlias, BatchAA.alias(PhiLoc, A1Loc)); // TODO: This is wrong. +} + class AAPassInfraTest : public testing::Test { protected: LLVMContext C;