[MSAN RT] Use __sanitizer::mem_is_zero in __msan_test_shadow

The former function is particularly optimized for exactly the
use case we're interested in: an all-zero buffer.

This reduces the overhead of calling this function some 80% or
more. This is particularly for instrumenting code heavy with
string processing functions, like grep. An invocation of grep
with the pattern '[aeiou]k[aeiou]' has its runtime reduced by
~75% with this patch

Differential Revision: https://reviews.llvm.org/D84961
This commit is contained in:
Gui Andrade 2020-08-10 19:03:40 +00:00
parent ab6a517ea4
commit c0b5000bd8
1 changed files with 3 additions and 0 deletions

View File

@ -527,6 +527,9 @@ void __msan_dump_shadow(const void *x, uptr size) {
sptr __msan_test_shadow(const void *x, uptr size) {
if (!MEM_IS_APP(x)) return -1;
unsigned char *s = (unsigned char *)MEM_TO_SHADOW((uptr)x);
if (__sanitizer::mem_is_zero((const char *)s, size))
return -1;
// Slow path: loop through again to find the location.
for (uptr i = 0; i < size; ++i)
if (s[i])
return i;