[llvm] 0f4383f - [Attributor] Handle special case when offset equals zero in nonnull deduction
Hideto Ueno via llvm-commits
llvm-commits at lists.llvm.org
Wed Nov 27 06:49:13 PST 2019
Author: Hideto Ueno
Date: 2019-11-27T14:45:16Z
New Revision: 0f4383faa75fdeaeebe0c5156f927e9f88d61d53
URL: https://github.com/llvm/llvm-project/commit/0f4383faa75fdeaeebe0c5156f927e9f88d61d53
DIFF: https://github.com/llvm/llvm-project/commit/0f4383faa75fdeaeebe0c5156f927e9f88d61d53.diff
LOG: [Attributor] Handle special case when offset equals zero in nonnull deduction
Added:
Modified:
llvm/lib/Transforms/IPO/Attributor.cpp
llvm/test/Transforms/FunctionAttrs/align.ll
Removed:
################################################################################
diff --git a/llvm/lib/Transforms/IPO/Attributor.cpp b/llvm/lib/Transforms/IPO/Attributor.cpp
index 366c347daeb1..faf0cdfd08ed 100644
--- a/llvm/lib/Transforms/IPO/Attributor.cpp
+++ b/llvm/lib/Transforms/IPO/Attributor.cpp
@@ -308,15 +308,16 @@ static const Value *getPointerOperand(const Instruction *I) {
return nullptr;
}
-static const Value *getBasePointerOfAccessPointerOperand(const Instruction *I,
- int64_t &BytesOffset,
- const DataLayout &DL) {
+static const Value *
+getBasePointerOfAccessPointerOperand(const Instruction *I, int64_t &BytesOffset,
+ const DataLayout &DL,
+ bool AllowNonInbounds = false) {
const Value *Ptr = getPointerOperand(I);
if (!Ptr)
return nullptr;
return GetPointerBaseWithConstantOffset(Ptr, BytesOffset, DL,
- /*AllowNonInbounds*/ false);
+ AllowNonInbounds);
}
ChangeStatus AbstractAttribute::update(Attributor &A) {
@@ -1702,8 +1703,7 @@ static int64_t getKnownNonNullAndDerefBytesForUse(
return 0;
}
if (auto *GEP = dyn_cast<GetElementPtrInst>(I))
- if (GEP->hasAllZeroIndices() ||
- (GEP->isInBounds() && GEP->hasAllConstantIndices())) {
+ if (GEP->hasAllConstantIndices()) {
TrackUse = true;
return 0;
}
@@ -1718,6 +1718,18 @@ static int64_t getKnownNonNullAndDerefBytesForUse(
return std::max(int64_t(0), DerefBytes);
}
}
+
+ /// Corner case when an offset is 0.
+ if (const Value *Base = getBasePointerOfAccessPointerOperand(
+ I, Offset, DL, /*AllowNonInbounds*/ true)) {
+ if (Offset == 0 && Base == &AssociatedValue &&
+ getPointerOperand(I) == UseV) {
+ int64_t DerefBytes =
+ (int64_t)DL.getTypeStoreSize(PtrTy->getPointerElementType());
+ IsNonNull |= !NullPointerIsDefined;
+ return std::max(int64_t(0), DerefBytes);
+ }
+ }
if (const Value *Base =
GetPointerBaseWithConstantOffset(UseV, Offset, DL,
/*AllowNonInbounds*/ false)) {
diff --git a/llvm/test/Transforms/FunctionAttrs/align.ll b/llvm/test/Transforms/FunctionAttrs/align.ll
index b8817a44fce7..a5bf91915baf 100644
--- a/llvm/test/Transforms/FunctionAttrs/align.ll
+++ b/llvm/test/Transforms/FunctionAttrs/align.ll
@@ -351,8 +351,7 @@ define i64 @test12-1(i32* align 4 %p) {
ret i64 %ret
}
-; FXIME: %p should have nonnull
-; ATTRIBUTOR: define i64 @test12-2(i32* nocapture nofree readonly align 16 %p)
+; ATTRIBUTOR: define i64 @test12-2(i32* nocapture nofree nonnull readonly align 16 dereferenceable(8) %p)
define i64 @test12-2(i32* align 4 %p) {
%p-cast = bitcast i32* %p to i64*
%arrayidx0 = getelementptr i64, i64* %p-cast, i64 0
@@ -370,8 +369,7 @@ define void @test12-3(i32* align 4 %p) {
ret void
}
-; FXIME: %p should have nonnull
-; ATTRIBUTOR: define void @test12-4(i32* nocapture nofree writeonly align 16 %p)
+; ATTRIBUTOR: define void @test12-4(i32* nocapture nofree nonnull writeonly align 16 dereferenceable(8) %p)
define void @test12-4(i32* align 4 %p) {
%p-cast = bitcast i32* %p to i64*
%arrayidx0 = getelementptr i64, i64* %p-cast, i64 0
More information about the llvm-commits
mailing list