[libc-commits] [libc] [llvm] [libc][x86] Enable memcpy NTA stores by default. (PR #216149)

Alexey Samsonov via libc-commits libc-commits at lists.llvm.org
Thu Aug 13 11:56:38 PDT 2026


https://github.com/vonosmas created https://github.com/llvm/llvm-project/pull/216149

Set `LIBC_COPT_MEMCPY_X86_USE_NTA_STORES` by default, which would enable NTA stores for `memcpy()` calls at some point when processing large buffers. We've ran some experiment down-stream that show that this change is performance-neutral on the majority of regular benchmarks / server applications and have positive impact on ML workloads that need to copy large tensors into shared memory.

Co-authored-by: Ilya Tokar <tokarip at google.com>

>From 2e8ed19cac317a7ea24d53091ada29d86440e41f Mon Sep 17 00:00:00 2001
From: Alexey Samsonov <vonosmas at gmail.com>
Date: Thu, 13 Aug 2026 18:49:21 +0000
Subject: [PATCH] [libc][x86] Enable memcpy NTA stores by default.

---
 libc/cmake/modules/LLVMLibCCompileOptionRules.cmake           | 2 +-
 libc/config/config.json                                       | 4 ++--
 libc/src/string/memory_utils/x86_64/inline_memcpy.h           | 2 +-
 .../llvm-project-overlay/libc/libc_configure_options.bzl      | 2 +-
 4 files changed, 5 insertions(+), 5 deletions(-)

diff --git a/libc/cmake/modules/LLVMLibCCompileOptionRules.cmake b/libc/cmake/modules/LLVMLibCCompileOptionRules.cmake
index 7e487662763f6..99defb24d249a 100644
--- a/libc/cmake/modules/LLVMLibCCompileOptionRules.cmake
+++ b/libc/cmake/modules/LLVMLibCCompileOptionRules.cmake
@@ -126,7 +126,7 @@ function(_get_compile_options_from_config output_var)
     libc_add_definition(config_options "LIBC_COPT_MEMSET_X86_USE_SOFTWARE_PREFETCHING")
   endif()
 
-  if(LIBC_CONF_COPT_MEMCPY_X86_USE_NTA_STORES)
+  if(LIBC_CONF_MEMCPY_X86_USE_NTA_STORES)
     libc_add_definition(config_options "LIBC_COPT_MEMCPY_X86_USE_NTA_STORES")
   endif()
 
diff --git a/libc/config/config.json b/libc/config/config.json
index 81673f3c8ef0a..fd7784d3d3e55 100644
--- a/libc/config/config.json
+++ b/libc/config/config.json
@@ -106,8 +106,8 @@
       "value": false,
       "doc": "Inserts prefetch for write instructions (PREFETCHW) for memset on x86 to recover performance when hardware prefetcher is disabled."
     },
-    "LIBC_CONF_COPT_MEMCPY_X86_USE_NTA_STORES": {
-      "value": false,
+    "LIBC_CONF_MEMCPY_X86_USE_NTA_STORES": {
+      "value": true,
       "doc": "Use Non-temporal stores in memcpy on x86 to improve performance of large copies."
     },
     "LIBC_CONF_USE_MEM_BUILTINS": {
diff --git a/libc/src/string/memory_utils/x86_64/inline_memcpy.h b/libc/src/string/memory_utils/x86_64/inline_memcpy.h
index ff6903b8d1a31..4198f22722d1b 100644
--- a/libc/src/string/memory_utils/x86_64/inline_memcpy.h
+++ b/libc/src/string/memory_utils/x86_64/inline_memcpy.h
@@ -37,7 +37,7 @@ LIBC_INLINE_VAR constexpr bool K_USE_SOFTWARE_PREFETCHING =
     LLVM_LIBC_IS_DEFINED(LIBC_COPT_MEMCPY_X86_USE_SOFTWARE_PREFETCHING);
 
 // Whether to use NTA stores and what threshold for switching to NTA
-#ifdef LIBC_COPT_MEMCPY_X86_USE_NTA_STORES
+#if defined(LIBC_COPT_MEMCPY_X86_USE_NTA_STORES) && defined(__AVX__)
 // Mostly based on empirical data. Theoretical justification:
 // upper bound of L2 size is 1MB on most x86 machines.
 LIBC_INLINE_VAR constexpr size_t K_NTA_THRESHOLD = 1 << 20;
diff --git a/utils/bazel/llvm-project-overlay/libc/libc_configure_options.bzl b/utils/bazel/llvm-project-overlay/libc/libc_configure_options.bzl
index a56db10ac2bd1..89eba49b7289a 100644
--- a/utils/bazel/llvm-project-overlay/libc/libc_configure_options.bzl
+++ b/utils/bazel/llvm-project-overlay/libc/libc_configure_options.bzl
@@ -24,7 +24,7 @@ LIBC_CONFIGURE_OPTIONS = [
     # Documentation in libc/src/string/memory_utils/...
     # "LIBC_COPT_MEMCPY_USE_EMBEDDED_TINY",
     # "LIBC_COPT_MEMCPY_X86_USE_REPMOVSB_FROM_SIZE",
-    # "LIBC_COPT_MEMCPY_X86_USE_NTA_STORES",
+    "LIBC_COPT_MEMCPY_X86_USE_NTA_STORES",
     "LIBC_COPT_MEMCPY_X86_USE_SOFTWARE_PREFETCHING",
     "LIBC_COPT_MEMSET_X86_USE_SOFTWARE_PREFETCHING",
 



More information about the libc-commits mailing list