From 782a93cc9abeee9bd90f7be92db4eb3895e15384 Mon Sep 17 00:00:00 2001 From: Nikita Popov Date: Wed, 11 Nov 2020 18:37:06 +0100 Subject: [PATCH] [BasicAA] Add test for incorrect BatchAA result (NFC) BatchAA produces an incorrect result, because a result based on a temporary phi noalias assumption is cached. --- llvm/unittests/Analysis/AliasAnalysisTest.cpp | 37 +++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/llvm/unittests/Analysis/AliasAnalysisTest.cpp b/llvm/unittests/Analysis/AliasAnalysisTest.cpp index 805ce1c..bb276594088 100644 --- a/llvm/unittests/Analysis/AliasAnalysisTest.cpp +++ b/llvm/unittests/Analysis/AliasAnalysisTest.cpp @@ -262,6 +262,43 @@ TEST_F(AliasAnalysisTest, BatchAAPhiCycles) { EXPECT_EQ(MayAlias, BatchAA2.alias(PhiLoc, A1Loc)); } +TEST_F(AliasAnalysisTest, BatchAAPhiAssumption) { + LLVMContext C; + SMDiagnostic Err; + std::unique_ptr M = parseAssemblyString(R"( + define void @f(i8* %a.base, i8* %b.base, i1 %c) { + entry: + br label %loop + + loop: + %a = phi i8* [ %a.next, %loop ], [ %a.base, %entry ] + %b = phi i8* [ %b.next, %loop ], [ %b.base, %entry ] + %a.next = getelementptr i8, i8* %a, i64 1 + %b.next = getelementptr i8, i8* %b, i64 1 + br label %loop + } + )", Err, C); + + Function *F = M->getFunction("f"); + Instruction *A = getInstructionByName(*F, "a"); + Instruction *B = getInstructionByName(*F, "b"); + Instruction *ANext = getInstructionByName(*F, "a.next"); + Instruction *BNext = getInstructionByName(*F, "b.next"); + MemoryLocation ALoc(A, LocationSize::precise(1)); + MemoryLocation BLoc(B, LocationSize::precise(1)); + MemoryLocation ANextLoc(ANext, LocationSize::precise(1)); + MemoryLocation BNextLoc(BNext, LocationSize::precise(1)); + + auto &AA = getAAResults(*F); + EXPECT_EQ(MayAlias, AA.alias(ALoc, BLoc)); + EXPECT_EQ(MayAlias, AA.alias(ANextLoc, BNextLoc)); + + BatchAAResults BatchAA(AA); + EXPECT_EQ(MayAlias, BatchAA.alias(ALoc, BLoc)); + // TODO: This is incorrect. + EXPECT_EQ(NoAlias, BatchAA.alias(ANextLoc, BNextLoc)); +} + class AAPassInfraTest : public testing::Test { protected: LLVMContext C; -- 2.7.4