Skip to content

Commit 7b73f53

Browse files
committed
[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
1 parent 6c89c53 commit 7b73f53

File tree

3 files changed

+3
-11
lines changed

3 files changed

+3
-11
lines changed

libc/src/string/CMakeLists.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -279,7 +279,6 @@ function(add_implementation name impl_name)
279279
${ARGN})
280280

281281
if("${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang")
282-
list(APPEND ADD_IMPL_MLLVM_COMPILE_OPTIONS "-combiner-global-alias-analysis")
283282
# Note that '-mllvm' needs to be prefixed with 'SHELL:' to prevent CMake flag deduplication.
284283
foreach(opt IN LISTS ADD_IMPL_MLLVM_COMPILE_OPTIONS)
285284
list(APPEND ADD_IMPL_COMPILE_OPTIONS "SHELL:-mllvm ${opt}")

libc/src/string/memory_utils/memcpy_implementations.h

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -39,11 +39,11 @@ namespace __llvm_libc {
3939

4040
static inline void inline_memcpy(char *__restrict dst,
4141
const char *__restrict src, size_t count) {
42+
using namespace __llvm_libc::builtin;
4243
#if defined(LLVM_LIBC_ARCH_X86)
4344
/////////////////////////////////////////////////////////////////////////////
4445
// LLVM_LIBC_ARCH_X86
4546
/////////////////////////////////////////////////////////////////////////////
46-
using namespace __llvm_libc::x86;
4747

4848
// Whether to use only rep;movsb.
4949
constexpr bool USE_ONLY_REP_MOVSB =
@@ -69,7 +69,7 @@ static inline void inline_memcpy(char *__restrict dst,
6969
#endif
7070

7171
if (USE_ONLY_REP_MOVSB)
72-
return copy<Accelerator>(dst, src, count);
72+
return copy<x86::Accelerator>(dst, src, count);
7373

7474
if (count == 0)
7575
return;
@@ -96,12 +96,11 @@ static inline void inline_memcpy(char *__restrict dst,
9696
if (count <= REP_MOVS_B_SIZE)
9797
return copy<Align<_32, Arg::Dst>::Then<Loop<LoopBlockSize>>>(dst, src,
9898
count);
99-
return copy<Accelerator>(dst, src, count);
99+
return copy<x86::Accelerator>(dst, src, count);
100100
#elif defined(LLVM_LIBC_ARCH_AARCH64)
101101
/////////////////////////////////////////////////////////////////////////////
102102
// LLVM_LIBC_ARCH_AARCH64
103103
/////////////////////////////////////////////////////////////////////////////
104-
using namespace __llvm_libc::scalar;
105104
if (count == 0)
106105
return;
107106
if (count == 1)
@@ -127,7 +126,6 @@ static inline void inline_memcpy(char *__restrict dst,
127126
/////////////////////////////////////////////////////////////////////////////
128127
// Default
129128
/////////////////////////////////////////////////////////////////////////////
130-
using namespace __llvm_libc::scalar;
131129
if (count == 0)
132130
return;
133131
if (count == 1)

utils/bazel/llvm-project-overlay/libc/BUILD.bazel

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -829,7 +829,6 @@ libc_function(
829829
copts = [
830830
"-fno-builtin-memcpy",
831831
"-fno-builtin-memmove",
832-
"-mllvm -combiner-global-alias-analysis",
833832
"-mllvm --tail-merge-threshold=0",
834833
],
835834
features = no_sanitize_features,
@@ -845,7 +844,6 @@ libc_function(
845844
hdrs = ["src/string/memset.h"],
846845
copts = [
847846
"-fno-builtin-memset",
848-
"-mllvm -combiner-global-alias-analysis",
849847
],
850848
features = no_sanitize_features,
851849
deps = [
@@ -860,7 +858,6 @@ libc_function(
860858
hdrs = ["src/string/memmove.h"],
861859
copts = [
862860
"-fno-builtin-memmove",
863-
"-mllvm -combiner-global-alias-analysis",
864861
],
865862
features = no_sanitize_features,
866863
deps = [
@@ -876,7 +873,6 @@ libc_function(
876873
hdrs = ["src/string/memcmp.h"],
877874
copts = [
878875
"-fno-builtin-memcmp",
879-
"-mllvm -combiner-global-alias-analysis",
880876
],
881877
features = no_sanitize_features,
882878
deps = [
@@ -908,7 +904,6 @@ libc_function(
908904
copts = [
909905
"-fno-builtin-bzero",
910906
"-fno-builtin-memset",
911-
"-mllvm -combiner-global-alias-analysis",
912907
],
913908
features = no_sanitize_features,
914909
deps = [

0 commit comments

Comments
 (0)