[libc-commits] [libc] 7b73f53 - [libc] Rely on __builtin_memcpy_inline for memcpy implementation
Guillaume Chatelet via libc-commits
libc-commits at lists.llvm.org
Fri Jun 17 07:22:43 PDT 2022
Author: Guillaume Chatelet
Date: 2022-06-17T14:22:26Z
New Revision: 7b73f53790f3db9ee589dc26a05a481a5e9e6915
URL: https://github.com/llvm/llvm-project/commit/7b73f53790f3db9ee589dc26a05a481a5e9e6915
DIFF: https://github.com/llvm/llvm-project/commit/7b73f53790f3db9ee589dc26a05a481a5e9e6915.diff
LOG: [libc] Rely on __builtin_memcpy_inline for memcpy implementation
This patch removes usage of `-mllvm -combiner-global-alias-analysis`
and relies on compiler builtin to implement `memcpy`.
Note that `-mllvm -combiner-global-alias-analysis` is actually only useful for
functions where buffers can alias (namely `memcpy` and `memmove`). The other
memory functions where not benefiting from the flag anyways.
The upside is that the memory functions can now be compiled from source with
thinlto (thinlto would not be able to carry on the flag when doing inlining).
The downside is that for compilers other than clang (i.e. not providing
`__builtin_memcpy_inline`) the codegen may be worse.
Differential Revision: https://reviews.llvm.org/D128051
Added:
Modified:
libc/src/string/CMakeLists.txt
libc/src/string/memory_utils/memcpy_implementations.h
utils/bazel/llvm-project-overlay/libc/BUILD.bazel
Removed:
################################################################################
diff --git a/libc/src/string/CMakeLists.txt b/libc/src/string/CMakeLists.txt
index c4f45e6331184..a2d89ae48b97d 100644
--- a/libc/src/string/CMakeLists.txt
+++ b/libc/src/string/CMakeLists.txt
@@ -279,7 +279,6 @@ function(add_implementation name impl_name)
${ARGN})
if("${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang")
- list(APPEND ADD_IMPL_MLLVM_COMPILE_OPTIONS "-combiner-global-alias-analysis")
# Note that '-mllvm' needs to be prefixed with 'SHELL:' to prevent CMake flag deduplication.
foreach(opt IN LISTS ADD_IMPL_MLLVM_COMPILE_OPTIONS)
list(APPEND ADD_IMPL_COMPILE_OPTIONS "SHELL:-mllvm ${opt}")
diff --git a/libc/src/string/memory_utils/memcpy_implementations.h b/libc/src/string/memory_utils/memcpy_implementations.h
index 8da4085de9aac..3385d40fbc56b 100644
--- a/libc/src/string/memory_utils/memcpy_implementations.h
+++ b/libc/src/string/memory_utils/memcpy_implementations.h
@@ -39,11 +39,11 @@ namespace __llvm_libc {
static inline void inline_memcpy(char *__restrict dst,
const char *__restrict src, size_t count) {
+ using namespace __llvm_libc::builtin;
#if defined(LLVM_LIBC_ARCH_X86)
/////////////////////////////////////////////////////////////////////////////
// LLVM_LIBC_ARCH_X86
/////////////////////////////////////////////////////////////////////////////
- using namespace __llvm_libc::x86;
// Whether to use only rep;movsb.
constexpr bool USE_ONLY_REP_MOVSB =
@@ -69,7 +69,7 @@ static inline void inline_memcpy(char *__restrict dst,
#endif
if (USE_ONLY_REP_MOVSB)
- return copy<Accelerator>(dst, src, count);
+ return copy<x86::Accelerator>(dst, src, count);
if (count == 0)
return;
@@ -96,12 +96,11 @@ static inline void inline_memcpy(char *__restrict dst,
if (count <= REP_MOVS_B_SIZE)
return copy<Align<_32, Arg::Dst>::Then<Loop<LoopBlockSize>>>(dst, src,
count);
- return copy<Accelerator>(dst, src, count);
+ return copy<x86::Accelerator>(dst, src, count);
#elif defined(LLVM_LIBC_ARCH_AARCH64)
/////////////////////////////////////////////////////////////////////////////
// LLVM_LIBC_ARCH_AARCH64
/////////////////////////////////////////////////////////////////////////////
- using namespace __llvm_libc::scalar;
if (count == 0)
return;
if (count == 1)
@@ -127,7 +126,6 @@ static inline void inline_memcpy(char *__restrict dst,
/////////////////////////////////////////////////////////////////////////////
// Default
/////////////////////////////////////////////////////////////////////////////
- using namespace __llvm_libc::scalar;
if (count == 0)
return;
if (count == 1)
diff --git a/utils/bazel/llvm-project-overlay/libc/BUILD.bazel b/utils/bazel/llvm-project-overlay/libc/BUILD.bazel
index f40b67139012b..a0d423a0d40fb 100644
--- a/utils/bazel/llvm-project-overlay/libc/BUILD.bazel
+++ b/utils/bazel/llvm-project-overlay/libc/BUILD.bazel
@@ -829,7 +829,6 @@ libc_function(
copts = [
"-fno-builtin-memcpy",
"-fno-builtin-memmove",
- "-mllvm -combiner-global-alias-analysis",
"-mllvm --tail-merge-threshold=0",
],
features = no_sanitize_features,
@@ -845,7 +844,6 @@ libc_function(
hdrs = ["src/string/memset.h"],
copts = [
"-fno-builtin-memset",
- "-mllvm -combiner-global-alias-analysis",
],
features = no_sanitize_features,
deps = [
@@ -860,7 +858,6 @@ libc_function(
hdrs = ["src/string/memmove.h"],
copts = [
"-fno-builtin-memmove",
- "-mllvm -combiner-global-alias-analysis",
],
features = no_sanitize_features,
deps = [
@@ -876,7 +873,6 @@ libc_function(
hdrs = ["src/string/memcmp.h"],
copts = [
"-fno-builtin-memcmp",
- "-mllvm -combiner-global-alias-analysis",
],
features = no_sanitize_features,
deps = [
@@ -908,7 +904,6 @@ libc_function(
copts = [
"-fno-builtin-bzero",
"-fno-builtin-memset",
- "-mllvm -combiner-global-alias-analysis",
],
features = no_sanitize_features,
deps = [
More information about the libc-commits
mailing list