-
Notifications
You must be signed in to change notification settings - Fork 15.2k
[libc++] Remove zero size branch from memmove #155419
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
Conversation
243954b
to
2bc86be
Compare
@llvm/pr-subscribers-libcxx Author: Nikolas Klauser (philnik777) ChangesThis can significantly reduce the generated code, since it avoids a branch the optimizer has to see through. At least with our benchmarks there isn't a significant change in performance. There might be a bit of an improvement, but it's inconclusive IMO:
Full diff: https://github.com/llvm/llvm-project/pull/155419.diff 1 Files Affected:
diff --git a/libcxx/include/__string/constexpr_c_functions.h b/libcxx/include/__string/constexpr_c_functions.h
index 119669e16bbcf..160d2af10950f 100644
--- a/libcxx/include/__string/constexpr_c_functions.h
+++ b/libcxx/include/__string/constexpr_c_functions.h
@@ -22,7 +22,6 @@
#include <__type_traits/is_equality_comparable.h>
#include <__type_traits/is_integral.h>
#include <__type_traits/is_same.h>
-#include <__type_traits/is_trivially_copyable.h>
#include <__type_traits/is_trivially_lexicographically_comparable.h>
#include <__type_traits/remove_cv.h>
#include <__utility/element_count.h>
@@ -225,6 +224,8 @@ __constexpr_memmove(_Tp* __dest, _Up* __src, __element_count __n) {
std::__assign_trivially_copyable(__dest[__i], __src[__i]);
}
}
+ } else if _LIBCPP_CONSTEXPR (sizeof(_Tp) == __datasizeof_v<_Tp>) {
+ ::__builtin_memmove(__dest, __src, __count * sizeof(_Tp));
} else if (__count > 0) {
::__builtin_memmove(__dest, __src, (__count - 1) * sizeof(_Tp) + __datasizeof_v<_Tp>);
}
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a clear win, nice!
This can significantly reduce the generated code, since it avoids a branch the optimizer has to see through. At least with our benchmarks there isn't a significant change in performance. There might be a bit of an improvement, but it's inconclusive IMO: