[libc-commits] [libc] [libc] Remove unnecessary call in memfunction dispatchers (PR #75800)
Guillaume Chatelet via libc-commits
libc-commits at lists.llvm.org
Mon Dec 18 06:32:21 PST 2023
https://github.com/gchatelet created https://github.com/llvm/llvm-project/pull/75800
Before this patch the compiler could generate unncessary calls to the selected implementation.
https://clang.llvm.org/docs/AttributeReference.html#flatten
>From 8a7a186e9472da22536a329b46d2846aecb1176f Mon Sep 17 00:00:00 2001
From: Guillaume Chatelet <gchatelet at google.com>
Date: Mon, 18 Dec 2023 14:31:57 +0000
Subject: [PATCH] [libc] Remove unnecessary call in memfunction dispatchers
Before this patch the compiler could generate unncessary calls to the selected implementation.
https://clang.llvm.org/docs/AttributeReference.html#flatten
---
libc/src/string/memory_utils/inline_bcmp.h | 3 ++-
libc/src/string/memory_utils/inline_bzero.h | 6 ++++--
libc/src/string/memory_utils/inline_memcmp.h | 3 ++-
libc/src/string/memory_utils/inline_memcpy.h | 4 ++--
libc/src/string/memory_utils/inline_memmove.h | 8 ++++----
5 files changed, 14 insertions(+), 10 deletions(-)
diff --git a/libc/src/string/memory_utils/inline_bcmp.h b/libc/src/string/memory_utils/inline_bcmp.h
index b1c981d859e022..bbbcf581df3de4 100644
--- a/libc/src/string/memory_utils/inline_bcmp.h
+++ b/libc/src/string/memory_utils/inline_bcmp.h
@@ -32,7 +32,8 @@
namespace LIBC_NAMESPACE {
-LIBC_INLINE int inline_bcmp(const void *p1, const void *p2, size_t count) {
+__attribute__((flatten)) LIBC_INLINE int
+inline_bcmp(const void *p1, const void *p2, size_t count) {
return static_cast<int>(LIBC_SRC_STRING_MEMORY_UTILS_BCMP(
reinterpret_cast<CPtr>(p1), reinterpret_cast<CPtr>(p2), count));
}
diff --git a/libc/src/string/memory_utils/inline_bzero.h b/libc/src/string/memory_utils/inline_bzero.h
index ed83cab68b2fd1..68fa48a3b4d21b 100644
--- a/libc/src/string/memory_utils/inline_bzero.h
+++ b/libc/src/string/memory_utils/inline_bzero.h
@@ -16,11 +16,13 @@
namespace LIBC_NAMESPACE {
-LIBC_INLINE static void inline_bzero(Ptr dst, size_t count) {
+__attribute__((flatten)) LIBC_INLINE static void inline_bzero(Ptr dst,
+ size_t count) {
inline_memset(dst, 0, count);
}
-LIBC_INLINE static void inline_bzero(void *dst, size_t count) {
+__attribute__((flatten)) LIBC_INLINE static void inline_bzero(void *dst,
+ size_t count) {
inline_bzero(reinterpret_cast<Ptr>(dst), count);
}
diff --git a/libc/src/string/memory_utils/inline_memcmp.h b/libc/src/string/memory_utils/inline_memcmp.h
index d88d43691daee8..58c6bd405a5b6c 100644
--- a/libc/src/string/memory_utils/inline_memcmp.h
+++ b/libc/src/string/memory_utils/inline_memcmp.h
@@ -33,7 +33,8 @@
namespace LIBC_NAMESPACE {
-LIBC_INLINE int inline_memcmp(const void *p1, const void *p2, size_t count) {
+__attribute__((flatten)) LIBC_INLINE int
+inline_memcmp(const void *p1, const void *p2, size_t count) {
return static_cast<int>(LIBC_SRC_STRING_MEMORY_UTILS_MEMCMP(
reinterpret_cast<CPtr>(p1), reinterpret_cast<CPtr>(p2), count));
}
diff --git a/libc/src/string/memory_utils/inline_memcpy.h b/libc/src/string/memory_utils/inline_memcpy.h
index a92bf4ddf881d5..35d8cec5d04926 100644
--- a/libc/src/string/memory_utils/inline_memcpy.h
+++ b/libc/src/string/memory_utils/inline_memcpy.h
@@ -40,8 +40,8 @@
namespace LIBC_NAMESPACE {
-LIBC_INLINE void inline_memcpy(void *__restrict dst, const void *__restrict src,
- size_t count) {
+__attribute__((flatten)) LIBC_INLINE void
+inline_memcpy(void *__restrict dst, const void *__restrict src, size_t count) {
LIBC_SRC_STRING_MEMORY_UTILS_MEMCPY(reinterpret_cast<Ptr>(dst),
reinterpret_cast<CPtr>(src), count);
}
diff --git a/libc/src/string/memory_utils/inline_memmove.h b/libc/src/string/memory_utils/inline_memmove.h
index 30c2c3ddbf1bb7..fbcd7a6b10df17 100644
--- a/libc/src/string/memory_utils/inline_memmove.h
+++ b/libc/src/string/memory_utils/inline_memmove.h
@@ -49,14 +49,14 @@ LIBC_INLINE constexpr bool inline_memmove_no_small_size(void *, const void *,
return false;
}
-LIBC_INLINE bool inline_memmove_small_size(void *dst, const void *src,
- size_t count) {
+__attribute__((flatten)) LIBC_INLINE bool
+inline_memmove_small_size(void *dst, const void *src, size_t count) {
return LIBC_SRC_STRING_MEMORY_UTILS_MEMMOVE_SMALL_SIZE(
reinterpret_cast<Ptr>(dst), reinterpret_cast<CPtr>(src), count);
}
-LIBC_INLINE void inline_memmove_follow_up(void *dst, const void *src,
- size_t count) {
+__attribute__((flatten)) LIBC_INLINE void
+inline_memmove_follow_up(void *dst, const void *src, size_t count) {
LIBC_SRC_STRING_MEMORY_UTILS_MEMMOVE_FOLLOW_UP(
reinterpret_cast<Ptr>(dst), reinterpret_cast<CPtr>(src), count);
}
More information about the libc-commits
mailing list