<div dir="ltr">are there benchmarks?</div><div class="gmail_extra"><br><br><div class="gmail_quote">On Wed, May 14, 2014 at 6:03 PM, Kostya Serebryany <span dir="ltr"><<a href="mailto:kcc@google.com" target="_blank">kcc@google.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Author: kcc<br>
Date: Wed May 14 09:03:31 2014<br>
New Revision: 208776<br>
<br>
URL: <a href="http://llvm.org/viewvc/llvm-project?rev=208776&view=rev" target="_blank">http://llvm.org/viewvc/llvm-project?rev=208776&view=rev</a><br>
Log:<br>
[asan] use some LIKELY/UNLIKELY<br>
<br>
Modified:<br>
    compiler-rt/trunk/lib/asan/asan_allocator2.cc<br>
    compiler-rt/trunk/lib/asan/asan_interceptors.cc<br>
    compiler-rt/trunk/lib/asan/asan_interceptors.h<br>
    compiler-rt/trunk/lib/asan/asan_malloc_linux.cc<br>
    compiler-rt/trunk/lib/asan/asan_malloc_mac.cc<br>
    compiler-rt/trunk/lib/asan/asan_rtl.cc<br>
    compiler-rt/trunk/lib/asan/asan_stack.h<br>
    compiler-rt/trunk/lib/sanitizer_common/sanitizer_internal_defs.h<br>
<br>
Modified: compiler-rt/trunk/lib/asan/asan_allocator2.cc<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/asan/asan_allocator2.cc?rev=208776&r1=208775&r2=208776&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/asan/asan_allocator2.cc?rev=208776&r1=208775&r2=208776&view=diff</a><br>

==============================================================================<br>
--- compiler-rt/trunk/lib/asan/asan_allocator2.cc (original)<br>
+++ compiler-rt/trunk/lib/asan/asan_allocator2.cc Wed May 14 09:03:31 2014<br>
@@ -281,7 +281,7 @@ void ReInitializeAllocator() {<br>
<br>
 static void *Allocate(uptr size, uptr alignment, StackTrace *stack,<br>
                       AllocType alloc_type, bool can_fill) {<br>
-  if (!asan_inited)<br>
+  if (UNLIKELY(!asan_inited))<br>
     AsanInitFromRtl();<br>
   Flags &fl = *flags();<br>
   CHECK(stack);<br>
<br>
Modified: compiler-rt/trunk/lib/asan/asan_interceptors.cc<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/asan/asan_interceptors.cc?rev=208776&r1=208775&r2=208776&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/asan/asan_interceptors.cc?rev=208776&r1=208775&r2=208776&view=diff</a><br>

==============================================================================<br>
--- compiler-rt/trunk/lib/asan/asan_interceptors.cc (original)<br>
+++ compiler-rt/trunk/lib/asan/asan_interceptors.cc Wed May 14 09:03:31 2014<br>
@@ -117,13 +117,15 @@ DECLARE_REAL_AND_INTERCEPTOR(void, free,<br>
 #define COMMON_INTERCEPTOR_WRITE_RANGE(ctx, ptr, size) \<br>
   ASAN_WRITE_RANGE(ptr, size)<br>
 #define COMMON_INTERCEPTOR_READ_RANGE(ctx, ptr, size) ASAN_READ_RANGE(ptr, size)<br>
-#define COMMON_INTERCEPTOR_ENTER(ctx, func, ...)                       \<br>
-  do {                                                                 \<br>
-    if (asan_init_is_running) return REAL(func)(__VA_ARGS__);          \<br>
-    ctx = 0;                                                           \<br>
-    (void) ctx;                                                        \<br>
-    if (SANITIZER_MAC && !asan_inited) return REAL(func)(__VA_ARGS__); \<br>
-    ENSURE_ASAN_INITED();                                              \<br>
+#define COMMON_INTERCEPTOR_ENTER(ctx, func, ...)                               \<br>
+  do {                                                                         \<br>
+    if (asan_init_is_running)                                                  \<br>
+      return REAL(func)(__VA_ARGS__);                                          \<br>
+    ctx = 0;                                                                   \<br>
+    (void) ctx;                                                                \<br>
+    if (SANITIZER_MAC && UNLIKELY(!asan_inited))                               \<br>
+      return REAL(func)(__VA_ARGS__);                                          \<br>
+    ENSURE_ASAN_INITED();                                                      \<br>
   } while (false)<br>
 #define COMMON_INTERCEPTOR_FD_ACQUIRE(ctx, fd) \<br>
   do {                                         \<br>
@@ -328,7 +330,7 @@ static inline int CharCmp(unsigned char<br>
 }<br>
<br>
 INTERCEPTOR(int, memcmp, const void *a1, const void *a2, uptr size) {<br>
-  if (!asan_inited) return internal_memcmp(a1, a2, size);<br>
+  if (UNLIKELY(!asan_inited)) return internal_memcmp(a1, a2, size);<br>
   ENSURE_ASAN_INITED();<br>
   if (flags()->replace_intrin) {<br>
     if (flags()->strict_memcmp) {<br>
@@ -356,7 +358,7 @@ INTERCEPTOR(int, memcmp, const void *a1,<br>
 }<br>
<br>
 void *__asan_memcpy(void *to, const void *from, uptr size) {<br>
-  if (!asan_inited) return internal_memcpy(to, from, size);<br>
+  if (UNLIKELY(!asan_inited)) return internal_memcpy(to, from, size);<br>
   // memcpy is called during __asan_init() from the internals<br>
   // of printf(...).<br>
   if (asan_init_is_running) {<br>
@@ -376,7 +378,7 @@ void *__asan_memcpy(void *to, const void<br>
 }<br>
<br>
 void *__asan_memset(void *block, int c, uptr size) {<br>
-  if (!asan_inited) return internal_memset(block, c, size);<br>
+  if (UNLIKELY(!asan_inited)) return internal_memset(block, c, size);<br>
   // memset is called inside Printf.<br>
   if (asan_init_is_running) {<br>
     return REAL(memset)(block, c, size);<br>
@@ -389,7 +391,7 @@ void *__asan_memset(void *block, int c,<br>
 }<br>
<br>
 void *__asan_memmove(void *to, const void *from, uptr size) {<br>
-  if (!asan_inited)<br>
+  if (UNLIKELY(!asan_inited))<br>
     return internal_memmove(to, from, size);<br>
   ENSURE_ASAN_INITED();<br>
   if (flags()->replace_intrin) {<br>
@@ -422,7 +424,7 @@ INTERCEPTOR(void*, memset, void *block,<br>
 }<br>
<br>
 INTERCEPTOR(char*, strchr, const char *str, int c) {<br>
-  if (!asan_inited) return internal_strchr(str, c);<br>
+  if (UNLIKELY(!asan_inited)) return internal_strchr(str, c);<br>
   // strchr is called inside create_purgeable_zone() when MallocGuardEdges=1 is<br>
   // used.<br>
   if (asan_init_is_running) {<br>
@@ -491,7 +493,7 @@ INTERCEPTOR(char*, strncat, char *to, co<br>
<br>
 INTERCEPTOR(char*, strcpy, char *to, const char *from) {  // NOLINT<br>
 #if SANITIZER_MAC<br>
-  if (!asan_inited) return REAL(strcpy)(to, from);  // NOLINT<br>
+  if (UNLIKELY(!asan_inited)) return REAL(strcpy)(to, from);  // NOLINT<br>
 #endif<br>
   // strcpy is called from malloc_default_purgeable_zone()<br>
   // in __asan::ReplaceSystemAlloc() on Mac.<br>
@@ -510,7 +512,7 @@ INTERCEPTOR(char*, strcpy, char *to, con<br>
<br>
 #if ASAN_INTERCEPT_STRDUP<br>
 INTERCEPTOR(char*, strdup, const char *s) {<br>
-  if (!asan_inited) return internal_strdup(s);<br>
+  if (UNLIKELY(!asan_inited)) return internal_strdup(s);<br>
   ENSURE_ASAN_INITED();<br>
   uptr length = REAL(strlen)(s);<br>
   if (flags()->replace_str) {<br>
@@ -524,7 +526,7 @@ INTERCEPTOR(char*, strdup, const char *s<br>
 #endif<br>
<br>
 INTERCEPTOR(uptr, strlen, const char *s) {<br>
-  if (!asan_inited) return internal_strlen(s);<br>
+  if (UNLIKELY(!asan_inited)) return internal_strlen(s);<br>
   // strlen is called from malloc_default_purgeable_zone()<br>
   // in __asan::ReplaceSystemAlloc() on Mac.<br>
   if (asan_init_is_running) {<br>
@@ -606,7 +608,7 @@ INTERCEPTOR(long, strtol, const char *np<br>
<br>
 INTERCEPTOR(int, atoi, const char *nptr) {<br>
 #if SANITIZER_MAC<br>
-  if (!asan_inited) return REAL(atoi)(nptr);<br>
+  if (UNLIKELY(!asan_inited)) return REAL(atoi)(nptr);<br>
 #endif<br>
   ENSURE_ASAN_INITED();<br>
   if (!flags()->replace_str) {<br>
@@ -625,7 +627,7 @@ INTERCEPTOR(int, atoi, const char *nptr)<br>
<br>
 INTERCEPTOR(long, atol, const char *nptr) {  // NOLINT<br>
 #if SANITIZER_MAC<br>
-  if (!asan_inited) return REAL(atol)(nptr);<br>
+  if (UNLIKELY(!asan_inited)) return REAL(atol)(nptr);<br>
 #endif<br>
   ENSURE_ASAN_INITED();<br>
   if (!flags()->replace_str) {<br>
@@ -682,7 +684,7 @@ static void AtCxaAtexit(void *unused) {<br>
 INTERCEPTOR(int, __cxa_atexit, void (*func)(void *), void *arg,<br>
             void *dso_handle) {<br>
 #if SANITIZER_MAC<br>
-  if (!asan_inited) return REAL(__cxa_atexit)(func, arg, dso_handle);<br>
+  if (UNLIKELY(!asan_inited)) return REAL(__cxa_atexit)(func, arg, dso_handle);<br>
 #endif<br>
   ENSURE_ASAN_INITED();<br>
   int res = REAL(__cxa_atexit)(func, arg, dso_handle);<br>
<br>
Modified: compiler-rt/trunk/lib/asan/asan_interceptors.h<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/asan/asan_interceptors.h?rev=208776&r1=208775&r2=208776&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/asan/asan_interceptors.h?rev=208776&r1=208775&r2=208776&view=diff</a><br>

==============================================================================<br>
--- compiler-rt/trunk/lib/asan/asan_interceptors.h (original)<br>
+++ compiler-rt/trunk/lib/asan/asan_interceptors.h Wed May 14 09:03:31 2014<br>
@@ -96,7 +96,7 @@ void InitializeAsanInterceptors();<br>
<br>
 #define ENSURE_ASAN_INITED() do { \<br>
   CHECK(!asan_init_is_running); \<br>
-  if (!asan_inited) { \<br>
+  if (UNLIKELY(!asan_inited)) { \<br>
     AsanInitFromRtl(); \<br>
   } \<br>
 } while (0)<br>
<br>
Modified: compiler-rt/trunk/lib/asan/asan_malloc_linux.cc<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/asan/asan_malloc_linux.cc?rev=208776&r1=208775&r2=208776&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/asan/asan_malloc_linux.cc?rev=208776&r1=208775&r2=208776&view=diff</a><br>

==============================================================================<br>
--- compiler-rt/trunk/lib/asan/asan_malloc_linux.cc (original)<br>
+++ compiler-rt/trunk/lib/asan/asan_malloc_linux.cc Wed May 14 09:03:31 2014<br>
@@ -77,7 +77,7 @@ INTERCEPTOR(void*, malloc, uptr size) {<br>
 }<br>
<br>
 INTERCEPTOR(void*, calloc, uptr nmemb, uptr size) {<br>
-  if (!asan_inited) {<br>
+  if (UNLIKELY(!asan_inited)) {<br>
     // Hack: dlsym calls calloc before REAL(calloc) is retrieved from dlsym.<br>
     const uptr kCallocPoolSize = 1024;<br>
     static uptr calloc_memory_for_dlsym[kCallocPoolSize];<br>
<br>
Modified: compiler-rt/trunk/lib/asan/asan_malloc_mac.cc<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/asan/asan_malloc_mac.cc?rev=208776&r1=208775&r2=208776&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/asan/asan_malloc_mac.cc?rev=208776&r1=208775&r2=208776&view=diff</a><br>

==============================================================================<br>
--- compiler-rt/trunk/lib/asan/asan_malloc_mac.cc (original)<br>
+++ compiler-rt/trunk/lib/asan/asan_malloc_mac.cc Wed May 14 09:03:31 2014<br>
@@ -159,7 +159,7 @@ size_t mz_size(malloc_zone_t* zone, cons<br>
 }<br>
<br>
 void *mz_malloc(malloc_zone_t *zone, size_t size) {<br>
-  if (!asan_inited) {<br>
+  if (UNLIKELY(!asan_inited)) {<br>
     CHECK(system_malloc_zone);<br>
     return malloc_zone_malloc(system_malloc_zone, size);<br>
   }<br>
@@ -168,7 +168,7 @@ void *mz_malloc(malloc_zone_t *zone, siz<br>
 }<br>
<br>
 void *mz_calloc(malloc_zone_t *zone, size_t nmemb, size_t size) {<br>
-  if (!asan_inited) {<br>
+  if (UNLIKELY(!asan_inited)) {<br>
     // Hack: dlsym calls calloc before REAL(calloc) is retrieved from dlsym.<br>
     const size_t kCallocPoolSize = 1024;<br>
     static uptr calloc_memory_for_dlsym[kCallocPoolSize];<br>
@@ -184,7 +184,7 @@ void *mz_calloc(malloc_zone_t *zone, siz<br>
 }<br>
<br>
 void *mz_valloc(malloc_zone_t *zone, size_t size) {<br>
-  if (!asan_inited) {<br>
+  if (UNLIKELY(!asan_inited)) {<br>
     CHECK(system_malloc_zone);<br>
     return malloc_zone_valloc(system_malloc_zone, size);<br>
   }<br>
@@ -242,7 +242,7 @@ void mz_destroy(malloc_zone_t* zone) {<br>
 #if defined(MAC_OS_X_VERSION_10_6) && \<br>
     MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_6<br>
 void *mz_memalign(malloc_zone_t *zone, size_t align, size_t size) {<br>
-  if (!asan_inited) {<br>
+  if (UNLIKELY(!asan_inited)) {<br>
     CHECK(system_malloc_zone);<br>
     return malloc_zone_memalign(system_malloc_zone, align, size);<br>
   }<br>
<br>
Modified: compiler-rt/trunk/lib/asan/asan_rtl.cc<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/asan/asan_rtl.cc?rev=208776&r1=208775&r2=208776&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/asan/asan_rtl.cc?rev=208776&r1=208775&r2=208776&view=diff</a><br>

==============================================================================<br>
--- compiler-rt/trunk/lib/asan/asan_rtl.cc (original)<br>
+++ compiler-rt/trunk/lib/asan/asan_rtl.cc Wed May 14 09:03:31 2014<br>
@@ -552,7 +552,7 @@ static void PrintAddressSpaceLayout() {<br>
 }<br>
<br>
 static void AsanInitInternal() {<br>
-  if (asan_inited) return;<br>
+  if (LIKELY(asan_inited)) return;<br>
   SanitizerToolName = "AddressSanitizer";<br>
   CHECK(!asan_init_is_running && "ASan init calls itself!");<br>
   asan_init_is_running = true;<br>
@@ -708,7 +708,7 @@ public:  // NOLINT<br>
   AsanInitializer() {<br>
     AsanCheckIncompatibleRT();<br>
     AsanCheckDynamicRTPrereqs();<br>
-    if (!asan_inited)<br>
+    if (UNLIKELY(!asan_inited))<br>
       __asan_init();<br>
   }<br>
 };<br>
<br>
Modified: compiler-rt/trunk/lib/asan/asan_stack.h<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/asan/asan_stack.h?rev=208776&r1=208775&r2=208776&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/asan/asan_stack.h?rev=208776&r1=208775&r2=208776&view=diff</a><br>

==============================================================================<br>
--- compiler-rt/trunk/lib/asan/asan_stack.h (original)<br>
+++ compiler-rt/trunk/lib/asan/asan_stack.h Wed May 14 09:03:31 2014<br>
@@ -32,7 +32,7 @@ void GetStackTraceWithPcBpAndContext(Sta<br>
 #else<br>
   AsanThread *t;<br>
   stack->size = 0;<br>
-  if (asan_inited) {<br>
+  if (LIKELY(asan_inited)) {<br>
     if ((t = GetCurrentThread()) && !t->isUnwinding()) {<br>
       uptr stack_top = t->stack_top();<br>
       uptr stack_bottom = t->stack_bottom();<br>
<br>
Modified: compiler-rt/trunk/lib/sanitizer_common/sanitizer_internal_defs.h<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/sanitizer_internal_defs.h?rev=208776&r1=208775&r2=208776&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/sanitizer_internal_defs.h?rev=208776&r1=208775&r2=208776&view=diff</a><br>

==============================================================================<br>
--- compiler-rt/trunk/lib/sanitizer_common/sanitizer_internal_defs.h (original)<br>
+++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_internal_defs.h Wed May 14 09:03:31 2014<br>
@@ -199,7 +199,7 @@ void NORETURN CheckFailed(const char *fi<br>
<br>
 // Check macro<br>
 #define RAW_CHECK_MSG(expr, msg) do { \<br>
-  if (!(expr)) { \<br>
+  if (UNLIKELY(!(expr))) { \<br>
     RawWrite(msg); \<br>
     Die(); \<br>
   } \<br>
@@ -211,7 +211,7 @@ void NORETURN CheckFailed(const char *fi<br>
   do { \<br>
     __sanitizer::u64 v1 = (u64)(c1); \<br>
     __sanitizer::u64 v2 = (u64)(c2); \<br>
-    if (!(v1 op v2)) \<br>
+    if (UNLIKELY(!(v1 op v2))) \<br>
       __sanitizer::CheckFailed(__FILE__, __LINE__, \<br>
         "(" #c1 ") " #op " (" #c2 ")", v1, v2); \<br>
   } while (false) \<br>
<br>
<br>
_______________________________________________<br>
llvm-commits mailing list<br>
<a href="mailto:llvm-commits@cs.uiuc.edu">llvm-commits@cs.uiuc.edu</a><br>
<a href="http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits" target="_blank">http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits</a><br>
</blockquote></div><br></div>