Successfully identified regression in *llvm* in CI configuration tcwg_bmk_llvm_tk1/llvm-master-arm-spec2k6-O2. So far, this commit has regressed CI configurations: - tcwg_bmk_llvm_tk1/llvm-master-arm-spec2k6-O2
Culprit: <cut> commit 87065c0d242d955e6f3fddf5cbc790d025c3521c Author: Guillaume Chatelet gchatelet@google.com Date: Wed Jun 23 14:19:40 2021 +0000
[libc] add benchmarks for memcmp and bzero
Differential Revision: https://reviews.llvm.org/D104511 </cut>
Results regressed to (for first_bad == 87065c0d242d955e6f3fddf5cbc790d025c3521c) # reset_artifacts: -10 # build_abe binutils: -9 # build_abe stage1 -- --set gcc_override_configure=--with-mode=arm --set gcc_override_configure=--disable-libsanitizer: -8 # build_abe linux: -7 # build_abe glibc: -6 # build_abe stage2 -- --set gcc_override_configure=--with-mode=arm --set gcc_override_configure=--disable-libsanitizer: -5 # build_llvm true: -3 # true: 0 # benchmark -O2_marm -- artifacts/build-87065c0d242d955e6f3fddf5cbc790d025c3521c/results_id: 1 # 400.perlbench,perlbench_base.default regressed by 103
from (for last_good == c125af82a5ff5dbbbcb8ebc5cde156d41e6ac281) # reset_artifacts: -10 # build_abe binutils: -9 # build_abe stage1 -- --set gcc_override_configure=--with-mode=arm --set gcc_override_configure=--disable-libsanitizer: -8 # build_abe linux: -7 # build_abe glibc: -6 # build_abe stage2 -- --set gcc_override_configure=--with-mode=arm --set gcc_override_configure=--disable-libsanitizer: -5 # build_llvm true: -3 # true: 0 # benchmark -O2_marm -- artifacts/build-c125af82a5ff5dbbbcb8ebc5cde156d41e6ac281/results_id: 1
Artifacts of last_good build: https://ci.linaro.org/job/tcwg_bmk_ci_llvm-bisect-tcwg_bmk_tk1-llvm-master-a... Results ID of last_good: tk1_32/tcwg_bmk_llvm_tk1/bisect-llvm-master-arm-spec2k6-O2/1292 Artifacts of first_bad build: https://ci.linaro.org/job/tcwg_bmk_ci_llvm-bisect-tcwg_bmk_tk1-llvm-master-a... Results ID of first_bad: tk1_32/tcwg_bmk_llvm_tk1/bisect-llvm-master-arm-spec2k6-O2/1297 Build top page/logs: https://ci.linaro.org/job/tcwg_bmk_ci_llvm-bisect-tcwg_bmk_tk1-llvm-master-a...
Configuration details:
Reproduce builds: <cut> mkdir investigate-llvm-87065c0d242d955e6f3fddf5cbc790d025c3521c cd investigate-llvm-87065c0d242d955e6f3fddf5cbc790d025c3521c
git clone https://git.linaro.org/toolchain/jenkins-scripts
mkdir -p artifacts/manifests curl -o artifacts/manifests/build-baseline.sh https://ci.linaro.org/job/tcwg_bmk_ci_llvm-bisect-tcwg_bmk_tk1-llvm-master-a... --fail curl -o artifacts/manifests/build-parameters.sh https://ci.linaro.org/job/tcwg_bmk_ci_llvm-bisect-tcwg_bmk_tk1-llvm-master-a... --fail curl -o artifacts/test.sh https://ci.linaro.org/job/tcwg_bmk_ci_llvm-bisect-tcwg_bmk_tk1-llvm-master-a... --fail chmod +x artifacts/test.sh
# Reproduce the baseline build (build all pre-requisites) ./jenkins-scripts/tcwg_bmk-build.sh @@ artifacts/manifests/build-baseline.sh
cd llvm
# Reproduce first_bad build git checkout --detach 87065c0d242d955e6f3fddf5cbc790d025c3521c ../artifacts/test.sh
# Reproduce last_good build git checkout --detach c125af82a5ff5dbbbcb8ebc5cde156d41e6ac281 ../artifacts/test.sh
cd .. </cut>
History of pending regressions and results: https://git.linaro.org/toolchain/ci/base-artifacts.git/log/?h=linaro-local/c...
Artifacts: https://ci.linaro.org/job/tcwg_bmk_ci_llvm-bisect-tcwg_bmk_tk1-llvm-master-a... Build log: https://ci.linaro.org/job/tcwg_bmk_ci_llvm-bisect-tcwg_bmk_tk1-llvm-master-a...
Full commit (up to 1000 lines): <cut> commit 87065c0d242d955e6f3fddf5cbc790d025c3521c Author: Guillaume Chatelet gchatelet@google.com Date: Wed Jun 23 14:19:40 2021 +0000
[libc] add benchmarks for memcmp and bzero
Differential Revision: https://reviews.llvm.org/D104511 --- libc/benchmarks/CMakeLists.txt | 2 ++ libc/benchmarks/LibcMemoryBenchmarkMain.cpp | 47 +++++++++++++++++++++++++++-- libc/src/string/CMakeLists.txt | 38 +++++++++++++++++------ 3 files changed, 75 insertions(+), 12 deletions(-)
diff --git a/libc/benchmarks/CMakeLists.txt b/libc/benchmarks/CMakeLists.txt index feff80cf4501..390b802bd8f7 100644 --- a/libc/benchmarks/CMakeLists.txt +++ b/libc/benchmarks/CMakeLists.txt @@ -169,3 +169,5 @@ endfunction()
add_libc_multi_impl_benchmark(memcpy) add_libc_multi_impl_benchmark(memset) +add_libc_multi_impl_benchmark(bzero) +add_libc_multi_impl_benchmark(memcmp) diff --git a/libc/benchmarks/LibcMemoryBenchmarkMain.cpp b/libc/benchmarks/LibcMemoryBenchmarkMain.cpp index e3d455423de2..6fa01ede52e3 100644 --- a/libc/benchmarks/LibcMemoryBenchmarkMain.cpp +++ b/libc/benchmarks/LibcMemoryBenchmarkMain.cpp @@ -17,10 +17,14 @@ #include "llvm/Support/MemoryBuffer.h" #include "llvm/Support/raw_ostream.h"
+#include <cstring> + namespace __llvm_libc {
extern void *memcpy(void *__restrict, const void *__restrict, size_t); extern void *memset(void *, int, size_t); +extern void bzero(void *, size_t); +extern int memcmp(const void *, const void *, size_t);
} // namespace __llvm_libc
@@ -79,7 +83,7 @@ struct Benchmark { return [this](ParameterType P) { __llvm_libc::memcpy(DstBuffer + P.OffsetBytes, SrcBuffer + P.OffsetBytes, P.SizeBytes); - return DstBuffer + P.OffsetBytes; + return DstBuffer[P.OffsetBytes]; }; }
@@ -97,18 +101,55 @@ struct Benchmark { return [this](ParameterType P) { __llvm_libc::memset(DstBuffer + P.OffsetBytes, P.OffsetBytes & 0xFF, P.SizeBytes); - return DstBuffer + P.OffsetBytes; + return DstBuffer[P.OffsetBytes]; + }; + } + + AlignedBuffer DstBuffer; +}; +#elif defined(LIBC_BENCHMARK_FUNCTION_BZERO) +struct Benchmark { + static constexpr auto GetDistributions = &getMemsetSizeDistributions; + static constexpr size_t BufferCount = 1; + + Benchmark(const size_t BufferSize) : DstBuffer(BufferSize) {} + + inline auto functor() { + return [this](ParameterType P) { + __llvm_libc::bzero(DstBuffer + P.OffsetBytes, P.SizeBytes); + return DstBuffer[P.OffsetBytes]; }; }
AlignedBuffer DstBuffer; }; +#elif defined(LIBC_BENCHMARK_FUNCTION_MEMCMP) +struct Benchmark { + static constexpr auto GetDistributions = &getMemcmpSizeDistributions; + static constexpr size_t BufferCount = 2; + + Benchmark(const size_t BufferSize) + : BufferA(BufferSize), BufferB(BufferSize) { + // The memcmp buffers always compare equal. + memset(BufferA.begin(), 0xF, BufferSize); + memset(BufferB.begin(), 0xF, BufferSize); + } + + inline auto functor() { + return [this](ParameterType P) { + return __llvm_libc::memcmp(BufferA + P.OffsetBytes, + BufferB + P.OffsetBytes, P.SizeBytes); + }; + } + + AlignedBuffer BufferA; + AlignedBuffer BufferB; +}; #else #error "Missing LIBC_BENCHMARK_FUNCTION_XXX definition" #endif
struct Harness : Benchmark { - Harness(const size_t BufferSize, size_t BatchParameterCount, std::function<unsigned()> SizeSampler, std::function<unsigned()> OffsetSampler) diff --git a/libc/src/string/CMakeLists.txt b/libc/src/string/CMakeLists.txt index 4dd8ee0bf4a2..97ac99cb89fe 100644 --- a/libc/src/string/CMakeLists.txt +++ b/libc/src/string/CMakeLists.txt @@ -58,14 +58,6 @@ add_entrypoint_object( .string_utils )
-add_entrypoint_object( - memcmp - SRCS - memcmp.cpp - HDRS - memcmp.h -) - add_entrypoint_object( memmove SRCS @@ -280,7 +272,6 @@ function(add_bzero bzero_name) .memory_utils.memory_utils libc.include.string COMPILE_OPTIONS - -fno-builtin-memset -fno-builtin-bzero ${ARGN} ) @@ -297,3 +288,32 @@ else() add_bzero(bzero_opt_host COMPILE_OPTIONS ${LIBC_COMPILE_OPTIONS_NATIVE}) add_bzero(bzero) endif() + +# ------------------------------------------------------------------------------ +# memcmp +# ------------------------------------------------------------------------------ + +function(add_memcmp memcmp_name) + add_implementation(memcmp ${memcmp_name} + SRCS ${LIBC_SOURCE_DIR}/src/string/memcmp.cpp + HDRS ${LIBC_SOURCE_DIR}/src/string/memcmp.h + DEPENDS + .memory_utils.memory_utils + libc.include.string + COMPILE_OPTIONS + -fno-builtin-memcmp + ${ARGN} + ) +endfunction() + +if(${LIBC_TARGET_ARCHITECTURE_IS_X86}) + add_memcmp(memcmp_x86_64_opt_sse2 COMPILE_OPTIONS -march=k8 REQUIRE SSE2) + add_memcmp(memcmp_x86_64_opt_sse4 COMPILE_OPTIONS -march=nehalem REQUIRE SSE4_2) + add_memcmp(memcmp_x86_64_opt_avx2 COMPILE_OPTIONS -march=haswell REQUIRE AVX2) + add_memcmp(memcmp_x86_64_opt_avx512 COMPILE_OPTIONS -march=skylake-avx512 REQUIRE AVX512F) + add_memcmp(memcmp_opt_host COMPILE_OPTIONS ${LIBC_COMPILE_OPTIONS_NATIVE}) + add_memcmp(memcmp) +else() + add_memcmp(memcmp_opt_host COMPILE_OPTIONS ${LIBC_COMPILE_OPTIONS_NATIVE}) + add_memcmp(memcmp) +endif() </cut>