Skip to content

[libc][bazel] Enable software prefetching for memcpy #108939

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 20, 2024

Conversation

gchatelet
Copy link
Contributor

This will affect only Bazel configuration for now.

This will affect only Bazel configuration for now.
@llvmbot llvmbot added libc bazel "Peripheral" support tier build system: utils/bazel labels Sep 17, 2024
@llvmbot
Copy link
Member

llvmbot commented Sep 17, 2024

@llvm/pr-subscribers-libc

Author: Guillaume Chatelet (gchatelet)

Changes

This will affect only Bazel configuration for now.


Full diff: https://github.com/llvm/llvm-project/pull/108939.diff

1 Files Affected:

  • (modified) utils/bazel/llvm-project-overlay/libc/libc_configure_options.bzl (+1-1)
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 f65da9e98226b6..96d7fa86e9ddf2 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_SOFTWARE_PREFETCHING",
+    "LIBC_COPT_MEMCPY_X86_USE_SOFTWARE_PREFETCHING",
     "LIBC_COPT_MEMSET_X86_USE_SOFTWARE_PREFETCHING",
 
     # Documentation in libc/docs/dev/printf_behavior.rst

@gchatelet gchatelet merged commit 42b696d into llvm:main Sep 20, 2024
9 checks passed
@gchatelet gchatelet deleted the enable_prefetching_for_memcpy branch September 20, 2024 13:16
gchatelet added a commit that referenced this pull request Oct 7, 2024
gchatelet added a commit that referenced this pull request Oct 7, 2024
Reverts #108939

When `AVX` is available but `-mprefer-vector-width=128` some of the
`mov` instructions turn into the x86 `rep;movsb` instruction leading to
poor performance on "old" architectures (sandybridge, haswell). The
possible solutions are : get rid of the `-mprefer-vector-width` option
or use smaller static copy sizes in
`inline_memcpy_x86_sse2_ge64_sw_prefetching`. Right now a copy size of 3
cache lines (192B) relying exclusively on xmm registers gets turned into
`rep;movsb`.
gchatelet added a commit to gchatelet/llvm-project that referenced this pull request Oct 21, 2024
…movsb`

When using `-mprefer-vector-width=128` with `-march=sandybridge` copying 3 cache lines in one go (192B) gets converted into `rep;movsb` which translate into a 60% hit in performance.

Consecutive calls to `__builtin_memcpy_inline` (implementation behind `builtin::Memcpy::block_offset`) are not coalesced by the compiler and so calling it three times in a row generates the desired assembly. It only differs in the interleaving of the loads and stores and does not affect performance.

This is needed to reland llvm#108939.
gchatelet added a commit that referenced this pull request Oct 22, 2024
…movsb` (#113161)

When using `-mprefer-vector-width=128` with `-march=sandybridge` copying
3 cache lines in one go (192B) gets converted into `rep;movsb` which
translate into a 60% hit in performance.

Consecutive calls to `__builtin_memcpy_inline` (implementation behind
`builtin::Memcpy::block_offset`) are not coalesced by the compiler and
so calling it three times in a row generates the desired assembly. It
only differs in the interleaving of the loads and stores and does not
affect performance.

This is needed to reland
#108939.
gchatelet added a commit to gchatelet/llvm-project that referenced this pull request Oct 28, 2024
This will affect only Bazel configuration for now.
This is a reland of llvm#108939 which has been reverted because of codegen
issues fixed by llvm#113161.
gchatelet added a commit that referenced this pull request Oct 28, 2024
This will affect only Bazel configuration for now.
This is a reland of #108939 which has been reverted because of codegen
issues fixed by #113161.
NoumanAmir657 pushed a commit to NoumanAmir657/llvm-project that referenced this pull request Nov 4, 2024
…3886)

This will affect only Bazel configuration for now.
This is a reland of llvm#108939 which has been reverted because of codegen
issues fixed by llvm#113161.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bazel "Peripheral" support tier build system: utils/bazel libc
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants