[libcxx-commits] [libcxx] [libc++] std::cmp_less and other integer comparison functions could be improved (PR #151332)
via libcxx-commits
libcxx-commits at lists.llvm.org
Fri Aug 1 06:00:01 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());
----------------
kisuhorikka wrote:
[Previous bench](https://quick-bench.com/q/BcqNhwMMj53O4xg6MQvhKe9PWok) shows slower results when converting parameters from `short` to `long long`. The performance is better if parameters are converted to `int`. https://quick-bench.com/q/q87HT8ePhR1AqI_Gy3Zj6rbElp8
However, the above results are based on clang 15 (I neglected this before unfortunately), and the difference seems vanished on clang 17. https://quick-bench.com/q/q0Q-bgFsVQyqe8QiDTiPHkawIu4
Though the little difference between speed, the assembly for `int` is shorter than `long long`, and `_LIBCPP_ASSUME` seems no work now. https://godbolt.org/z/a5s3zx64W
https://github.com/llvm/llvm-project/pull/151332
More information about the libcxx-commits
mailing list