]> granicus.if.org Git - llvm/commitdiff
[SLC] Improve dereferenceable bytes annotation
authorDavid Bolvansky <david.bolvansky@gmail.com>
Tue, 13 Aug 2019 16:44:16 +0000 (16:44 +0000)
committerDavid Bolvansky <david.bolvansky@gmail.com>
Tue, 13 Aug 2019 16:44:16 +0000 (16:44 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@368715 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Transforms/Utils/SimplifyLibCalls.cpp
test/Transforms/InstCombine/mem-deref-bytes.ll

index 396690e1860e414334ebe8bd1d071066a637e259..ef4cc227222b39ce2eb276a36bbbb2a58ed138de 100644 (file)
@@ -188,8 +188,12 @@ static bool canTransformToMemCmp(CallInst *CI, Value *Str, uint64_t Len,
 
 static void annotateDereferenceableBytes(CallInst *CI,
                                          ArrayRef<unsigned> 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);
index a329f9dcdaad2e4c7533e19c9feb00685134f3d7..87be8f57795f198b5c91e4d78925bf95582376c7 100644 (file)
@@ -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)