[PATCH] D115927: [AA] Correctly maintain the sign of PartiaAlias offset
Momchil Velikov via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Fri Dec 17 02:24:38 PST 2021
chill created this revision.
chill added reviewers: dfukalov, nikic.
Herald added subscribers: jeroen.dobbelaere, hiraditya.
chill requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.
Preserve the invariant that offset reported in the case of a
`PartialAlias` between `Loc1` and `Loc2`, is such that `Loc1 + Offset = Loc2`, where
`Loc1` and `Loc2` are the first and the second argument, respectively, in alias queries.
https://reviews.llvm.org/D115927
Files:
llvm/lib/Analysis/BasicAliasAnalysis.cpp
llvm/unittests/Analysis/AliasAnalysisTest.cpp
Index: llvm/unittests/Analysis/AliasAnalysisTest.cpp
===================================================================
--- llvm/unittests/Analysis/AliasAnalysisTest.cpp
+++ llvm/unittests/Analysis/AliasAnalysisTest.cpp
@@ -333,6 +333,38 @@
EXPECT_EQ(4, AR.getOffset());
}
+// Check that swapping the order of parameters to `AA.alias()` changes offset
+// sign and that the sign is such that FirstLoc + Offset == SecondLoc.
+TEST_F(AliasAnalysisTest, PartialAliasOffsetSign) {
+ LLVMContext C;
+ SMDiagnostic Err;
+ std::unique_ptr<Module> M = parseAssemblyString(R"(
+ define void @f(i64* %p) {
+ %L1 = load i64, i64* %p
+ %p.i8 = bitcast i64* %p to i8*
+ %q = getelementptr i8, i8* %p.i8, i32 1
+ %L2 = load i8, i8* %q
+ ret void
+ }
+ )", Err, C);
+
+ if (!M)
+ Err.print("PartialAliasOffsetSign", errs());
+
+ Function *F = M->getFunction("f");
+ const auto Loc1 = MemoryLocation::get(getInstructionByName(*F, "L1"));
+ const auto Loc2 = MemoryLocation::get(getInstructionByName(*F, "L2"));
+
+ auto &AA = getAAResults(*F);
+
+ auto AR = AA.alias(Loc1, Loc2);
+ EXPECT_EQ(AR, AliasResult::PartialAlias);
+ EXPECT_EQ(1, AR.getOffset());
+
+ AR = AA.alias(Loc2, Loc1);
+ EXPECT_EQ(AR, AliasResult::PartialAlias);
+ EXPECT_EQ(-1, AR.getOffset());
+}
class AAPassInfraTest : public testing::Test {
protected:
LLVMContext C;
Index: llvm/lib/Analysis/BasicAliasAnalysis.cpp
===================================================================
--- llvm/lib/Analysis/BasicAliasAnalysis.cpp
+++ llvm/lib/Analysis/BasicAliasAnalysis.cpp
@@ -1699,6 +1699,7 @@
return Result;
} else if (const GEPOperator *GV2 = dyn_cast<GEPOperator>(V2)) {
AliasResult Result = aliasGEP(GV2, V2Size, V1, V1Size, O2, O1, AAQI);
+ Result.swap();
if (Result != AliasResult::MayAlias)
return Result;
}
@@ -1709,6 +1710,7 @@
return Result;
} else if (const PHINode *PN = dyn_cast<PHINode>(V2)) {
AliasResult Result = aliasPHI(PN, V2Size, V1, V1Size, AAQI);
+ Result.swap();
if (Result != AliasResult::MayAlias)
return Result;
}
@@ -1719,6 +1721,7 @@
return Result;
} else if (const SelectInst *S2 = dyn_cast<SelectInst>(V2)) {
AliasResult Result = aliasSelect(S2, V2Size, V1, V1Size, AAQI);
+ Result.swap();
if (Result != AliasResult::MayAlias)
return Result;
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D115927.395078.patch
Type: text/x-patch
Size: 2393 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20211217/0c82b68a/attachment.bin>
More information about the llvm-commits
mailing list