[compiler-rt] r341420 - [sanitizer] optimize internal_memset for the most performance critical case (16-byte-aligned)

Kostya Serebryany via llvm-commits llvm-commits at lists.llvm.org
Tue Sep 4 15:43:30 PDT 2018


Author: kcc
Date: Tue Sep  4 15:43:30 2018
New Revision: 341420

URL: http://llvm.org/viewvc/llvm-project?rev=341420&view=rev
Log:
[sanitizer] optimize internal_memset for the most performance critical case (16-byte-aligned)

Modified:
    compiler-rt/trunk/lib/sanitizer_common/sanitizer_libc.cc

Modified: compiler-rt/trunk/lib/sanitizer_common/sanitizer_libc.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/sanitizer_libc.cc?rev=341420&r1=341419&r2=341420&view=diff
==============================================================================
--- compiler-rt/trunk/lib/sanitizer_common/sanitizer_libc.cc (original)
+++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_libc.cc Tue Sep  4 15:43:30 2018
@@ -73,6 +73,18 @@ void *internal_memmove(void *dest, const
 }
 
 void *internal_memset(void* s, int c, uptr n) {
+  // Optimize for the most performance-critical case:
+  if ((reinterpret_cast<uptr>(s) % 16) == 0 && (n % 16) == 0) {
+    u64 *p = reinterpret_cast<u64*>(s);
+    u64 *e = p + n / 8;
+    u64 v = c;
+    v |= v << 8;
+    v |= v << 16;
+    v |= v << 32;
+    for (; p < e; p += 2)
+      p[0] = p[1] = v;
+    return s;
+  }
   // The next line prevents Clang from making a call to memset() instead of the
   // loop below.
   // FIXME: building the runtime with -ffreestanding is a better idea. However




More information about the llvm-commits mailing list