Skip to content

Conversation

@google-yfyang
Copy link
Contributor

WASM supports bulk memory operations and can benefit from using generic/builtin.h.

@llvmbot llvmbot added the libc label Jan 22, 2026
@llvmbot
Copy link
Member

llvmbot commented Jan 22, 2026

@llvm/pr-subscribers-libc

Author: None (google-yfyang)

Changes

WASM supports bulk memory operations and can benefit from using generic/builtin.h.


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

3 Files Affected:

  • (modified) libc/src/string/memory_utils/inline_memcpy.h (+1-1)
  • (modified) libc/src/string/memory_utils/inline_memmove.h (+1-1)
  • (modified) libc/src/string/memory_utils/inline_memset.h (+1-1)
diff --git a/libc/src/string/memory_utils/inline_memcpy.h b/libc/src/string/memory_utils/inline_memcpy.h
index 13975e6b3bd0e..931d2821be3a9 100644
--- a/libc/src/string/memory_utils/inline_memcpy.h
+++ b/libc/src/string/memory_utils/inline_memcpy.h
@@ -31,7 +31,7 @@
 #elif defined(LIBC_TARGET_ARCH_IS_ANY_RISCV)
 #include "src/string/memory_utils/riscv/inline_memcpy.h"
 #define LIBC_SRC_STRING_MEMORY_UTILS_MEMCPY inline_memcpy_riscv
-#elif defined(LIBC_TARGET_ARCH_IS_GPU)
+#elif defined(LIBC_TARGET_ARCH_IS_GPU) || defined(LIBC_TARGET_ARCH_IS_WASM)
 #include "src/string/memory_utils/generic/builtin.h"
 #define LIBC_SRC_STRING_MEMORY_UTILS_MEMCPY inline_memcpy_builtin
 #else
diff --git a/libc/src/string/memory_utils/inline_memmove.h b/libc/src/string/memory_utils/inline_memmove.h
index 71a28c32e4c56..31627669b06bf 100644
--- a/libc/src/string/memory_utils/inline_memmove.h
+++ b/libc/src/string/memory_utils/inline_memmove.h
@@ -29,7 +29,7 @@
 #define LIBC_SRC_STRING_MEMORY_UTILS_MEMMOVE_SMALL_SIZE                        \
   inline_memmove_no_small_size
 #define LIBC_SRC_STRING_MEMORY_UTILS_MEMMOVE_FOLLOW_UP inline_memmove_riscv
-#elif defined(LIBC_TARGET_ARCH_IS_GPU)
+#elif defined(LIBC_TARGET_ARCH_IS_GPU) || defined(LIBC_TARGET_ARCH_IS_WASM)
 #include "src/string/memory_utils/generic/builtin.h"
 #define LIBC_SRC_STRING_MEMORY_UTILS_MEMMOVE_SMALL_SIZE                        \
   inline_memmove_no_small_size
diff --git a/libc/src/string/memory_utils/inline_memset.h b/libc/src/string/memory_utils/inline_memset.h
index e41bdb626d60e..da85f09d0db57 100644
--- a/libc/src/string/memory_utils/inline_memset.h
+++ b/libc/src/string/memory_utils/inline_memset.h
@@ -27,7 +27,7 @@
 #elif defined(LIBC_TARGET_ARCH_IS_ANY_RISCV)
 #include "src/string/memory_utils/riscv/inline_memset.h"
 #define LIBC_SRC_STRING_MEMORY_UTILS_MEMSET inline_memset_riscv
-#elif defined(LIBC_TARGET_ARCH_IS_GPU)
+#elif defined(LIBC_TARGET_ARCH_IS_GPU) || defined(LIBC_TARGET_ARCH_IS_WASM)
 #include "src/string/memory_utils/generic/builtin.h"
 #define LIBC_SRC_STRING_MEMORY_UTILS_MEMSET inline_memset_builtin
 #else

@aheejin
Copy link
Member

aheejin commented Jan 23, 2026

Diff between emscripten-core/emscripten#26151 and LLVM 21.1.8 has this too:

diff --git a/libc/src/__support/macros/properties/architectures.h b/libc/src/__support/macros/properties/architectures.h
index c88956ff4114..817ced4e95c2 100644
--- a/libc/src/__support/macros/properties/architectures.h
+++ b/libc/src/__support/macros/properties/architectures.h
@@ -41,6 +41,10 @@
 #define LIBC_TARGET_ARCH_IS_ARM
 #endif

+#if defined(__wasm__)
+#define LIBC_TARGET_ARCH_IS_WASM
+#endif
+
 #if defined(__aarch64__) || defined(__arm64__) || defined(_M_ARM64)
 #define LIBC_TARGET_ARCH_IS_AARCH64
 #endif

Should we include this here too?

@google-yfyang
Copy link
Contributor Author

Diff between emscripten-core/emscripten#26151 and LLVM 21.1.8 has this too:

diff --git a/libc/src/__support/macros/properties/architectures.h b/libc/src/__support/macros/properties/architectures.h
index c88956ff4114..817ced4e95c2 100644
--- a/libc/src/__support/macros/properties/architectures.h
+++ b/libc/src/__support/macros/properties/architectures.h
@@ -41,6 +41,10 @@
 #define LIBC_TARGET_ARCH_IS_ARM
 #endif

+#if defined(__wasm__)
+#define LIBC_TARGET_ARCH_IS_WASM
+#endif
+
 #if defined(__aarch64__) || defined(__arm64__) || defined(_M_ARM64)
 #define LIBC_TARGET_ARCH_IS_AARCH64
 #endif

Should we include this here too?

This already went into the HEAD 4 months ago. https://github.com/llvm/llvm-project/blob/main/libc/src/__support/macros/properties/architectures.h. Presumably LLVM 21.1.8 isn't new enough to see this change reflected.

@google-yfyang
Copy link
Contributor Author

@michaelrj-google Could you please take a look?

Copy link
Contributor

@jhuber6 jhuber6 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm assuming you've verified that __builtin_memmove and similar do not emit libcalls in their implementation? Should be fine.

sbc100 pushed a commit to emscripten-core/emscripten that referenced this pull request Jan 23, 2026
This makes llvm libc on par with libcxx and libcxxabi. #26058 

The remaining local changes to libc sources are very minor and is all in
llvm/llvm-project#177474.

Once both of these PRs go in, we can try syncing it to the LLVM upstream
HEAD.
Copy link
Contributor

@michaelrj-google michaelrj-google left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM as long as you've confirmed that the builtins don't call the library functions (as jhuber suggested)

@google-yfyang
Copy link
Contributor Author

Yes, https://godbolt.org/z/T69z9TYc8. Looks like no libcalls are emitted.

@jhuber6 jhuber6 merged commit 8206c81 into llvm:main Jan 23, 2026
29 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants