[PATCH] D42916: [sanitizer] SizeClassMap minor improvement/correctness changes
Kostya Kortchinsky via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Mon Feb 5 10:20:11 PST 2018
cryptoad created this revision.
cryptoad added a reviewer: alekseyshl.
Herald added subscribers: Sanitizers, delcypher, kubamracek.
In `ClassID`, make sure we use an unsigned as based for the `lbits` shift.
The previous code resulted in spurious sign extensions like for x64:
add esi, 0FFFFFFFFh
movsxd rcx, esi
and rcx, r15
The code with the `U` added is:
add esi, 0FFFFFFFFh
and rsi, r15
And for `MaxCachedHint`, use a 32-bit division instead of `64-bit`, which is
faster (https://lemire.me/blog/2017/11/16/fast-exact-integer-divisions-using-floating-point-operations/)
and already used in other parts of the code (64-bit `GetChunkIdx`, 32-bit
`GetMetaData` enforce 32-bit divisions)
Not major performance gains by any mean, but they don't hurt.
Repository:
rCRT Compiler Runtime
https://reviews.llvm.org/D42916
Files:
lib/sanitizer_common/sanitizer_allocator_size_class_map.h
Index: lib/sanitizer_common/sanitizer_allocator_size_class_map.h
===================================================================
--- lib/sanitizer_common/sanitizer_allocator_size_class_map.h
+++ lib/sanitizer_common/sanitizer_allocator_size_class_map.h
@@ -163,7 +163,7 @@
return (size + kMinSize - 1) >> kMinSizeLog;
uptr l = MostSignificantSetBitIndex(size);
uptr hbits = (size >> (l - S)) & M;
- uptr lbits = size & ((1 << (l - S)) - 1);
+ uptr lbits = size & ((1U << (l - S)) - 1);
uptr l1 = l - kMidSizeLog;
return kMidClass + (l1 << S) + hbits + (lbits > 0);
}
@@ -176,7 +176,8 @@
return 16;
if (UNLIKELY(class_id == 0))
return 0;
- uptr n = (1UL << kMaxBytesCachedLog) / Size(class_id);
+ const uptr n =
+ (1U << kMaxBytesCachedLog) / static_cast<u32>(Size(class_id));
return Max<uptr>(1, Min(kMaxNumCachedHint, n));
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D42916.132856.patch
Type: text/x-patch
Size: 908 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180205/4c854991/attachment.bin>
More information about the llvm-commits
mailing list