[llvm] ddd0f08 - [BatchAA] Add test for incorrect phi cycle result (NFC)
Nikita Popov via llvm-commits
llvm-commits at lists.llvm.org
Mon Oct 19 12:05:17 PDT 2020
Author: Nikita Popov
Date: 2020-10-19T20:53:11+02:00
New Revision: ddd0f083184feb489684f87cf28d5eb10e0a244e
URL: https://github.com/llvm/llvm-project/commit/ddd0f083184feb489684f87cf28d5eb10e0a244e
DIFF: https://github.com/llvm/llvm-project/commit/ddd0f083184feb489684f87cf28d5eb10e0a244e.diff
LOG: [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.
Added:
Modified:
llvm/unittests/Analysis/AliasAnalysisTest.cpp
Removed:
################################################################################
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<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;
More information about the llvm-commits
mailing list