[compiler-rt] r226644 - tsan: don't unroll memory access loop in debug mode

Dmitry Vyukov dvyukov at google.com
Wed Jan 21 00:09:14 PST 2015


Author: dvyukov
Date: Wed Jan 21 02:09:13 2015
New Revision: 226644

URL: http://llvm.org/viewvc/llvm-project?rev=226644&view=rev
Log:
tsan: don't unroll memory access loop in debug mode

MemoryAccess function consumes ~4K of stack in debug mode,
in significant part due to the unrolled loop.
And gtest gives only 4K of stack to death test
threads, which causes stack overflows in debug mode.


Modified:
    compiler-rt/trunk/lib/tsan/rtl/tsan_rtl.cc

Modified: compiler-rt/trunk/lib/tsan/rtl/tsan_rtl.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/tsan/rtl/tsan_rtl.cc?rev=226644&r1=226643&r2=226644&view=diff
==============================================================================
--- compiler-rt/trunk/lib/tsan/rtl/tsan_rtl.cc (original)
+++ compiler-rt/trunk/lib/tsan/rtl/tsan_rtl.cc Wed Jan 21 02:09:13 2015
@@ -565,6 +565,16 @@ void MemoryAccessImpl1(ThreadState *thr,
 
   Shadow old(0);
 
+  // It release mode we manually unroll the loop,
+  // because empirically gcc generates better code this way.
+  // However, we can't afford unrolling in debug mode, because the function
+  // consumes almost 4K of stack. Gtest gives only 4K of stack to death test
+  // threads, which is not enough for the unrolled loop.
+#if SANITIZER_DEBUG
+  for (int idx = 0; idx < 4; idx++) {
+#include "tsan_update_shadow_word_inl.h"
+  }
+#else
   int idx = 0;
 #include "tsan_update_shadow_word_inl.h"
   idx = 1;
@@ -573,6 +583,7 @@ void MemoryAccessImpl1(ThreadState *thr,
 #include "tsan_update_shadow_word_inl.h"
   idx = 3;
 #include "tsan_update_shadow_word_inl.h"
+#endif
 
   // we did not find any races and had already stored
   // the current access info, so we are done





More information about the llvm-commits mailing list