Skip to content

Commit ddd0f08

Browse files
committed
[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.
1 parent 6be9c7d commit ddd0f08

File tree

1 file changed

+42
-0
lines changed

1 file changed

+42
-0
lines changed

llvm/unittests/Analysis/AliasAnalysisTest.cpp

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,48 @@ TEST_F(AliasAnalysisTest, getModRefInfo) {
207207
EXPECT_EQ(AA.getModRefInfo(AtomicRMW, None), ModRefInfo::ModRef);
208208
}
209209

210+
static Instruction *getInstructionByName(Function &F, StringRef Name) {
211+
for (auto &I : instructions(F))
212+
if (I.getName() == Name)
213+
return &I;
214+
llvm_unreachable("Expected to find instruction!");
215+
}
216+
217+
TEST_F(AliasAnalysisTest, BatchAAPhiCycles) {
218+
LLVMContext C;
219+
SMDiagnostic Err;
220+
std::unique_ptr<Module> M = parseAssemblyString(R"(
221+
define void @f(i8* noalias %a) {
222+
entry:
223+
br label %loop
224+
225+
loop:
226+
%phi = phi i8* [ null, %entry ], [ %a2, %loop ]
227+
%offset1 = phi i64 [ 0, %entry ], [ %offset2, %loop]
228+
%offset2 = add i64 %offset1, 1
229+
%a1 = getelementptr i8, i8* %a, i64 %offset1
230+
%a2 = getelementptr i8, i8* %a, i64 %offset2
231+
br label %loop
232+
}
233+
)", Err, C);
234+
235+
Function *F = M->getFunction("f");
236+
Instruction *Phi = getInstructionByName(*F, "phi");
237+
Instruction *A1 = getInstructionByName(*F, "a1");
238+
Instruction *A2 = getInstructionByName(*F, "a2");
239+
MemoryLocation PhiLoc(Phi, LocationSize::precise(1));
240+
MemoryLocation A1Loc(A1, LocationSize::precise(1));
241+
MemoryLocation A2Loc(A2, LocationSize::precise(1));
242+
243+
auto &AA = getAAResults(*F);
244+
EXPECT_EQ(NoAlias, AA.alias(A1Loc, A2Loc));
245+
EXPECT_EQ(MayAlias, AA.alias(PhiLoc, A1Loc));
246+
247+
BatchAAResults BatchAA(AA);
248+
EXPECT_EQ(NoAlias, BatchAA.alias(A1Loc, A2Loc));
249+
EXPECT_EQ(NoAlias, BatchAA.alias(PhiLoc, A1Loc)); // TODO: This is wrong.
250+
}
251+
210252
class AAPassInfraTest : public testing::Test {
211253
protected:
212254
LLVMContext C;

0 commit comments

Comments
 (0)