[libcxx-commits] [libcxx] [libc++] std::cmp_less and other integer comparison functions could be improved (PR #151332)

A. Jiang via libcxx-commits libcxx-commits at lists.llvm.org
Thu Aug 7 23:18:26 PDT 2025


================
@@ -28,7 +29,13 @@ _LIBCPP_BEGIN_NAMESPACE_STD
 
 template <__signed_or_unsigned_integer _Tp, __signed_or_unsigned_integer _Up>
 _LIBCPP_HIDE_FROM_ABI constexpr bool cmp_equal(_Tp __t, _Up __u) noexcept {
-  if constexpr (is_signed_v<_Tp> == is_signed_v<_Up>)
+  if constexpr (sizeof(_Tp) < sizeof(int) && sizeof(_Up) < sizeof(int)) {
+    _LIBCPP_ASSUME(__t < numeric_limits<int>::max() && __u < numeric_limits<int>::max());
----------------
frederick-vs-ja wrote:

On Clang 21 (or 22?), `_LIBCPP_ASSUME` doesn't affect the generated same assembly. I'd like to remove `_LIBCPP_ASSUME` here.

https://github.com/llvm/llvm-project/pull/151332


More information about the libcxx-commits mailing list