Skip to content

Commit 90a30fd

Browse files
committedAug 13, 2019
[SLC] Improve dereferenceable bytes annotation
llvm-svn: 368715
1 parent 28215ca commit 90a30fd

File tree

2 files changed

+6
-2
lines changed

2 files changed

+6
-2
lines changed
 

‎llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp

+5-1
Original file line numberDiff line numberDiff line change
@@ -188,8 +188,12 @@ static bool canTransformToMemCmp(CallInst *CI, Value *Str, uint64_t Len,
188188

189189
static void annotateDereferenceableBytes(CallInst *CI,
190190
ArrayRef<unsigned> ArgNos,
191-
uint64_t DerefBytes) {
191+
uint64_t DereferenceableBytes) {
192192
for (unsigned ArgNo : ArgNos) {
193+
uint64_t DerefBytes = std::max(
194+
CI->getDereferenceableOrNullBytes(ArgNo + AttributeList::FirstArgIndex),
195+
DereferenceableBytes);
196+
193197
if (CI->getDereferenceableBytes(ArgNo + AttributeList::FirstArgIndex) <
194198
DerefBytes) {
195199
CI->removeParamAttr(ArgNo, Attribute::Dereferenceable);

‎llvm/test/Transforms/InstCombine/mem-deref-bytes.ll

+1-1
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ define i32 @memcmp_const_size_no_update_deref(i8* nocapture readonly %d, i8* noc
4848

4949
define i32 @memcmp_const_size_no_update_deref2(i8* nocapture readonly %d, i8* nocapture readonly %s) {
5050
; CHECK-LABEL: @memcmp_const_size_no_update_deref2(
51-
; CHECK-NEXT: [[CALL:%.*]] = tail call i32 @memcmp(i8* dereferenceable(16) [[D:%.*]], i8* dereferenceable(16) [[S:%.*]], i64 16)
51+
; CHECK-NEXT: [[CALL:%.*]] = tail call i32 @memcmp(i8* dereferenceable(40) [[D:%.*]], i8* dereferenceable(16) [[S:%.*]], i64 16)
5252
; CHECK-NEXT: ret i32 [[CALL]]
5353
;
5454
%call = tail call i32 @memcmp(i8* dereferenceable_or_null(40) %d, i8* %s, i64 16)

0 commit comments

Comments
 (0)
Please sign in to comment.