From: David Bolvansky Date: Tue, 13 Aug 2019 16:44:16 +0000 (+0000) Subject: [SLC] Improve dereferenceable bytes annotation X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=e2ecc33d0b261e8e8d7c43cbfefa8d066d5edf4b;p=llvm [SLC] Improve dereferenceable bytes annotation git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@368715 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Transforms/Utils/SimplifyLibCalls.cpp b/lib/Transforms/Utils/SimplifyLibCalls.cpp index 396690e1860..ef4cc227222 100644 --- a/lib/Transforms/Utils/SimplifyLibCalls.cpp +++ b/lib/Transforms/Utils/SimplifyLibCalls.cpp @@ -188,8 +188,12 @@ static bool canTransformToMemCmp(CallInst *CI, Value *Str, uint64_t Len, static void annotateDereferenceableBytes(CallInst *CI, ArrayRef ArgNos, - uint64_t DerefBytes) { + uint64_t DereferenceableBytes) { for (unsigned ArgNo : ArgNos) { + uint64_t DerefBytes = std::max( + CI->getDereferenceableOrNullBytes(ArgNo + AttributeList::FirstArgIndex), + DereferenceableBytes); + if (CI->getDereferenceableBytes(ArgNo + AttributeList::FirstArgIndex) < DerefBytes) { CI->removeParamAttr(ArgNo, Attribute::Dereferenceable); diff --git a/test/Transforms/InstCombine/mem-deref-bytes.ll b/test/Transforms/InstCombine/mem-deref-bytes.ll index a329f9dcdaa..87be8f57795 100644 --- a/test/Transforms/InstCombine/mem-deref-bytes.ll +++ b/test/Transforms/InstCombine/mem-deref-bytes.ll @@ -48,7 +48,7 @@ define i32 @memcmp_const_size_no_update_deref(i8* nocapture readonly %d, i8* noc define i32 @memcmp_const_size_no_update_deref2(i8* nocapture readonly %d, i8* nocapture readonly %s) { ; CHECK-LABEL: @memcmp_const_size_no_update_deref2( -; CHECK-NEXT: [[CALL:%.*]] = tail call i32 @memcmp(i8* dereferenceable(16) [[D:%.*]], i8* dereferenceable(16) [[S:%.*]], i64 16) +; 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)