[llvm] 782a93c - [BasicAA] Add test for incorrect BatchAA result (NFC)

Nikita Popov via llvm-commits llvm-commits at lists.llvm.org
Wed Nov 11 10:06:54 PST 2020


Author: Nikita Popov
Date: 2020-11-11T19:06:42+01:00
New Revision: 782a93cc9abeee9bd90f7be92db4eb3895e15384

URL: https://github.com/llvm/llvm-project/commit/782a93cc9abeee9bd90f7be92db4eb3895e15384
DIFF: https://github.com/llvm/llvm-project/commit/782a93cc9abeee9bd90f7be92db4eb3895e15384.diff

LOG: [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.

Added: 
    

Modified: 
    llvm/unittests/Analysis/AliasAnalysisTest.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/unittests/Analysis/AliasAnalysisTest.cpp b/llvm/unittests/Analysis/AliasAnalysisTest.cpp
index 805ce1c0e0d5..bb2765940889 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<Module> 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;


        


More information about the llvm-commits mailing list