[llvm] 60f3e8f - [BasicAA] Clarify entry values of GetLinearExpression() (NFC)
Nikita Popov via llvm-commits
llvm-commits at lists.llvm.org
Sat Mar 27 07:22:24 PDT 2021
Author: Nikita Popov
Date: 2021-03-27T14:50:09+01:00
New Revision: 60f3e8fbe44f12ea28760c2771f8bf48dc08abe8
URL: https://github.com/llvm/llvm-project/commit/60f3e8fbe44f12ea28760c2771f8bf48dc08abe8
DIFF: https://github.com/llvm/llvm-project/commit/60f3e8fbe44f12ea28760c2771f8bf48dc08abe8.diff
LOG: [BasicAA] Clarify entry values of GetLinearExpression() (NFC)
A number of variables need to be correctly initialized on entry
to GetLinearExpression() for the implementation to behave reasonably.
The fact that SExtBits can currenlty be non-zero on entry is a bug,
as demonstrated by the added test: For implicit sexts by the GEP,
we do currently skip legality checks.
Added:
Modified:
llvm/lib/Analysis/BasicAliasAnalysis.cpp
llvm/test/Analysis/BasicAA/zext.ll
Removed:
################################################################################
diff --git a/llvm/lib/Analysis/BasicAliasAnalysis.cpp b/llvm/lib/Analysis/BasicAliasAnalysis.cpp
index ab0d180a99e1..6a6ddd65d5d5 100644
--- a/llvm/lib/Analysis/BasicAliasAnalysis.cpp
+++ b/llvm/lib/Analysis/BasicAliasAnalysis.cpp
@@ -237,6 +237,9 @@ static bool isObjectSize(const Value *V, uint64_t Size, const DataLayout &DL,
unsigned &SExtBits, const DataLayout &DL, unsigned Depth,
AssumptionCache *AC, DominatorTree *DT, bool &NSW, bool &NUW) {
assert(V->getType()->isIntegerTy() && "Not an integer value");
+ // TODO: SExtBits can be non-zero on entry.
+ assert(Scale == 0 && Offset == 0 && ZExtBits == 0 && NSW == true &&
+ NUW == true && "Incorrect default values");
// Limit our recursion depth.
if (Depth == 6) {
@@ -251,7 +254,7 @@ static bool isObjectSize(const Value *V, uint64_t Size, const DataLayout &DL,
// than the constant's (the Offset's always as wide as the outermost call),
// so we'll zext here and process any extension in the isa<SExtInst> &
// isa<ZExtInst> cases below.
- Offset += Const->getValue().zextOrSelf(Offset.getBitWidth());
+ Offset = Const->getValue().zextOrSelf(Offset.getBitWidth());
assert(Scale == 0 && "Constant values don't have a scale");
return V;
}
diff --git a/llvm/test/Analysis/BasicAA/zext.ll b/llvm/test/Analysis/BasicAA/zext.ll
index 2e25734be775..050e9d3b0724 100644
--- a/llvm/test/Analysis/BasicAA/zext.ll
+++ b/llvm/test/Analysis/BasicAA/zext.ll
@@ -264,5 +264,17 @@ define void @test_shl_nsw_sext(i8* %p, i32 %x) {
ret void
}
+; CHECK-LABEL: Function: test_implicit_sext
+; CHECK: MustAlias: i8* %p.1, i8* %p.2
+; TODO: Should be MayAlias.
+define void @test_implicit_sext(i8* %p, i32 %x) {
+ %add = add i32 %x, 1
+ %ext = sext i32 %x to i64
+ %ext.add = add i64 %ext, 1
+ %p.1 = getelementptr i8, i8* %p, i32 %add
+ %p.2 = getelementptr i8, i8* %p, i64 %ext.add
+ ret void
+}
+
; Function Attrs: nounwind
declare noalias i8* @malloc(i64)
More information about the llvm-commits
mailing list