[BatchAA] Add test for incorrect phi cycle result (NFC)

AA computes the correct result for phi/a1 aliasing, while BatchAA
produces an incorrect result depening on which queries have been
performed beforehand.
This commit is contained in:
Nikita Popov 2020-10-19 20:51:37 +02:00
parent 6be9c7d2dc
commit ddd0f08318
1 changed files with 42 additions and 0 deletions

View File

@ -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<Module> 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;