[llvm] r368884 - [SLC] Dereferenceable annonation - handle valid null pointers
David Bolvansky via llvm-commits
llvm-commits at lists.llvm.org
Wed Aug 14 10:15:21 PDT 2019
Author: xbolva00
Date: Wed Aug 14 10:15:20 2019
New Revision: 368884
URL: http://llvm.org/viewvc/llvm-project?rev=368884&view=rev
Log:
[SLC] Dereferenceable annonation - handle valid null pointers
Reviewers: jdoerfert, reames
Reviewed By: jdoerfert
Subscribers: llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D66161
Added:
llvm/trunk/test/Transforms/InstCombine/mem-deref-bytes-addrspaces.ll
Modified:
llvm/trunk/lib/Transforms/Utils/SimplifyLibCalls.cpp
llvm/trunk/test/Transforms/InstCombine/mem-deref-bytes.ll
Modified: llvm/trunk/lib/Transforms/Utils/SimplifyLibCalls.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Utils/SimplifyLibCalls.cpp?rev=368884&r1=368883&r2=368884&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/Utils/SimplifyLibCalls.cpp (original)
+++ llvm/trunk/lib/Transforms/Utils/SimplifyLibCalls.cpp Wed Aug 14 10:15:20 2019
@@ -189,15 +189,22 @@ static bool canTransformToMemCmp(CallIns
static void annotateDereferenceableBytes(CallInst *CI,
ArrayRef<unsigned> ArgNos,
uint64_t DereferenceableBytes) {
+ const Function *F = CI->getFunction();
+ if (!F)
+ return;
for (unsigned ArgNo : ArgNos) {
- uint64_t DerefBytes = std::max(
- CI->getDereferenceableOrNullBytes(ArgNo + AttributeList::FirstArgIndex),
- DereferenceableBytes);
+ uint64_t DerefBytes = DereferenceableBytes;
+ unsigned AS = CI->getArgOperand(ArgNo)->getType()->getPointerAddressSpace();
+ if (!llvm::NullPointerIsDefined(F, AS))
+ DerefBytes = std::max(CI->getDereferenceableOrNullBytes(
+ ArgNo + AttributeList::FirstArgIndex),
+ DereferenceableBytes);
if (CI->getDereferenceableBytes(ArgNo + AttributeList::FirstArgIndex) <
DerefBytes) {
CI->removeParamAttr(ArgNo, Attribute::Dereferenceable);
- CI->removeParamAttr(ArgNo, Attribute::DereferenceableOrNull);
+ if (!llvm::NullPointerIsDefined(F, AS))
+ CI->removeParamAttr(ArgNo, Attribute::DereferenceableOrNull);
CI->addParamAttr(ArgNo, Attribute::getWithDereferenceableBytes(
CI->getContext(), DerefBytes));
}
Added: llvm/trunk/test/Transforms/InstCombine/mem-deref-bytes-addrspaces.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/InstCombine/mem-deref-bytes-addrspaces.ll?rev=368884&view=auto
==============================================================================
--- llvm/trunk/test/Transforms/InstCombine/mem-deref-bytes-addrspaces.ll (added)
+++ llvm/trunk/test/Transforms/InstCombine/mem-deref-bytes-addrspaces.ll Wed Aug 14 10:15:20 2019
@@ -0,0 +1,13 @@
+; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
+; RUN: opt -instcombine -S < %s | FileCheck %s
+
+declare i32 @memcmp(i8 addrspace(1)* nocapture, i8* nocapture, i64)
+
+define i32 @memcmp_const_size_update_deref8(i8 addrspace(1)* nocapture readonly %d, i8* nocapture readonly %s) {
+; CHECK-LABEL: @memcmp_const_size_update_deref8(
+; CHECK-NEXT: [[CALL:%.*]] = tail call i32 @memcmp(i8 addrspace(1)* dereferenceable(16) dereferenceable_or_null(40) [[D:%.*]], i8* dereferenceable(16) [[S:%.*]], i64 16)
+; CHECK-NEXT: ret i32 [[CALL]]
+;
+ %call = tail call i32 @memcmp(i8 addrspace(1)* dereferenceable_or_null(40) %d, i8* %s, i64 16)
+ ret i32 %call
+}
Modified: llvm/trunk/test/Transforms/InstCombine/mem-deref-bytes.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/InstCombine/mem-deref-bytes.ll?rev=368884&r1=368883&r2=368884&view=diff
==============================================================================
--- llvm/trunk/test/Transforms/InstCombine/mem-deref-bytes.ll (original)
+++ llvm/trunk/test/Transforms/InstCombine/mem-deref-bytes.ll Wed Aug 14 10:15:20 2019
@@ -55,12 +55,21 @@ define i32 @memcmp_const_size_update_der
ret i32 %call
}
-define i32 @memcmp_const_size_update_deref5(i8* nocapture readonly %d, i8* nocapture readonly %s) {
+define i32 @memcmp_const_size_update_deref5(i8* nocapture readonly %d, i8* nocapture readonly %s) "null-pointer-is-valid"="false" {
; CHECK-LABEL: @memcmp_const_size_update_deref5(
; CHECK-NEXT: [[CALL:%.*]] = tail call i32 @memcmp(i8* dereferenceable(40) [[D:%.*]], i8* dereferenceable(16) [[S:%.*]], i64 16)
; CHECK-NEXT: ret i32 [[CALL]]
;
%call = tail call i32 @memcmp(i8* dereferenceable_or_null(40) %d, i8* %s, i64 16)
+ ret i32 %call
+}
+
+define i32 @memcmp_const_size_update_deref6(i8* nocapture readonly %d, i8* nocapture readonly %s) "null-pointer-is-valid"="true" {
+; CHECK-LABEL: @memcmp_const_size_update_deref6(
+; CHECK-NEXT: [[CALL:%.*]] = tail call i32 @memcmp(i8* dereferenceable(16) dereferenceable_or_null(40) [[D:%.*]], i8* dereferenceable(16) [[S:%.*]], i64 16)
+; CHECK-NEXT: ret i32 [[CALL]]
+;
+ %call = tail call i32 @memcmp(i8* dereferenceable_or_null(40) %d, i8* %s, i64 16)
ret i32 %call
}
More information about the llvm-commits
mailing list