[PATCH] D66161: [SLC] Dereferenceable annonation - handle valid null pointers
Dávid Bolvanský via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Tue Aug 13 15:09:14 PDT 2019
xbolva00 updated this revision to Diff 214938.
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D66161/new/
https://reviews.llvm.org/D66161
Files:
lib/Transforms/Utils/SimplifyLibCalls.cpp
test/Transforms/InstCombine/mem-deref-bytes-addrspaces.ll
test/Transforms/InstCombine/mem-deref-bytes.ll
Index: test/Transforms/InstCombine/mem-deref-bytes.ll
===================================================================
--- test/Transforms/InstCombine/mem-deref-bytes.ll
+++ test/Transforms/InstCombine/mem-deref-bytes.ll
@@ -55,7 +55,7 @@
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]]
@@ -64,6 +64,15 @@
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) [[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_no_update_deref(i8* nocapture readonly %d, i8* nocapture readonly %s) {
; CHECK-LABEL: @memcmp_const_size_no_update_deref(
; CHECK-NEXT: [[CALL:%.*]] = tail call i32 @memcmp(i8* dereferenceable(40) [[D:%.*]], i8* dereferenceable(20) [[S:%.*]], i64 16)
Index: test/Transforms/InstCombine/mem-deref-bytes-addrspaces.ll
===================================================================
--- test/Transforms/InstCombine/mem-deref-bytes-addrspaces.ll
+++ test/Transforms/InstCombine/mem-deref-bytes-addrspaces.ll
@@ -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) "null-pointer-is-valid"="true" {
+; CHECK-LABEL: @memcmp_const_size_update_deref8(
+; CHECK-NEXT: [[CALL:%.*]] = tail call i32 @memcmp(i8 addrspace(1)* dereferenceable(16) [[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
+}
Index: lib/Transforms/Utils/SimplifyLibCalls.cpp
===================================================================
--- lib/Transforms/Utils/SimplifyLibCalls.cpp
+++ lib/Transforms/Utils/SimplifyLibCalls.cpp
@@ -189,10 +189,16 @@
static void annotateDereferenceableBytes(CallInst *CI,
ArrayRef<unsigned> ArgNos,
uint64_t DereferenceableBytes) {
+ 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 (AS == 0 && !F->nullPointerIsDefined())
+ DerefBytes = std::max(CI->getDereferenceableOrNullBytes(
+ ArgNo + AttributeList::FirstArgIndex),
+ DereferenceableBytes);
if (CI->getDereferenceableBytes(ArgNo + AttributeList::FirstArgIndex) <
DerefBytes) {
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D66161.214938.patch
Type: text/x-patch
Size: 3619 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20190813/93d5dc17/attachment.bin>
More information about the llvm-commits
mailing list