[libcxx-commits] [libcxx] [libc++] Add constant folding for optimized std::find variants (PR #96491)
Louis Dionne via libcxx-commits
libcxx-commits at lists.llvm.org
Thu Jul 4 11:14:16 PDT 2024
================
@@ -132,6 +132,19 @@ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 _Tp* __constexpr_memchr(_Tp*
static_assert(sizeof(_Tp) == 1 && __libcpp_is_trivially_equality_comparable<_Tp, _Up>::value,
"Calling memchr on non-trivially equality comparable types is unsafe.");
+ if (__builtin_constant_p(__count) && __builtin_constant_p(__value)) {
----------------
ldionne wrote:
Let's add some kind of comment explaining that this is to aid constant-folding and it also handles evaluation inside constant expressions, since that is not super obvious.
https://github.com/llvm/llvm-project/pull/96491
More information about the libcxx-commits
mailing list