[compiler-rt] c0b5000 - [MSAN RT] Use __sanitizer::mem_is_zero in __msan_test_shadow
Gui Andrade via llvm-commits
llvm-commits at lists.llvm.org
Mon Aug 10 12:22:50 PDT 2020
Author: Gui Andrade
Date: 2020-08-10T19:22:27Z
New Revision: c0b5000bd848303320c03f80fbf84d71e74518c9
URL: https://github.com/llvm/llvm-project/commit/c0b5000bd848303320c03f80fbf84d71e74518c9
DIFF: https://github.com/llvm/llvm-project/commit/c0b5000bd848303320c03f80fbf84d71e74518c9.diff
LOG: [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
Added:
Modified:
compiler-rt/lib/msan/msan.cpp
Removed:
################################################################################
diff --git a/compiler-rt/lib/msan/msan.cpp b/compiler-rt/lib/msan/msan.cpp
index 9afc7b026a8e..a1ad5c4f1abc 100644
--- a/compiler-rt/lib/msan/msan.cpp
+++ b/compiler-rt/lib/msan/msan.cpp
@@ -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;
More information about the llvm-commits
mailing list