[libcxx-commits] [libcxx] [libc++] Check explicit values in the partial_ordering comparators for better code gen (PR #81366)
Nikolas Klauser via libcxx-commits
libcxx-commits at lists.llvm.org
Sat Feb 10 08:43:05 PST 2024
https://github.com/philnik777 created https://github.com/llvm/llvm-project/pull/81366
This allows the compiler to check for specific bit patterns instead of value ranges.
>From 56bf23d6fb50b6e36d8d2c8db6191f30c6b395f1 Mon Sep 17 00:00:00 2001
From: Nikolas Klauser <nikolasklauser at berlin.de>
Date: Sat, 10 Feb 2024 17:39:11 +0100
Subject: [PATCH] [libc++] Check explicit values in the partial_ordering
comparators for better code gen
---
libcxx/include/__compare/ordering.h | 22 +++++++++-------------
1 file changed, 9 insertions(+), 13 deletions(-)
diff --git a/libcxx/include/__compare/ordering.h b/libcxx/include/__compare/ordering.h
index 2995d381304f0e..0bd9c5f27b3c1c 100644
--- a/libcxx/include/__compare/ordering.h
+++ b/libcxx/include/__compare/ordering.h
@@ -47,10 +47,6 @@ class partial_ordering {
_LIBCPP_HIDE_FROM_ABI explicit constexpr partial_ordering(_NCmpResult __v) noexcept : __value_(_ValueT(__v)) {}
- _LIBCPP_HIDE_FROM_ABI constexpr bool __is_ordered() const noexcept {
- return __value_ != _ValueT(_NCmpResult::__unordered);
- }
-
public:
// valid values
static const partial_ordering less;
@@ -62,39 +58,39 @@ class partial_ordering {
_LIBCPP_HIDE_FROM_ABI friend constexpr bool operator==(partial_ordering, partial_ordering) noexcept = default;
_LIBCPP_HIDE_FROM_ABI friend constexpr bool operator==(partial_ordering __v, _CmpUnspecifiedParam) noexcept {
- return __v.__is_ordered() && __v.__value_ == 0;
+ return __v.__value_ == 0;
}
_LIBCPP_HIDE_FROM_ABI friend constexpr bool operator<(partial_ordering __v, _CmpUnspecifiedParam) noexcept {
- return __v.__is_ordered() && __v.__value_ < 0;
+ return __v.__value_ == -1;
}
_LIBCPP_HIDE_FROM_ABI friend constexpr bool operator<=(partial_ordering __v, _CmpUnspecifiedParam) noexcept {
- return __v.__is_ordered() && __v.__value_ <= 0;
+ return __v.__value_ == 0 || __v.__value_ == -1;
}
_LIBCPP_HIDE_FROM_ABI friend constexpr bool operator>(partial_ordering __v, _CmpUnspecifiedParam) noexcept {
- return __v.__is_ordered() && __v.__value_ > 0;
+ return __v.__value_ == 1;
}
_LIBCPP_HIDE_FROM_ABI friend constexpr bool operator>=(partial_ordering __v, _CmpUnspecifiedParam) noexcept {
- return __v.__is_ordered() && __v.__value_ >= 0;
+ return __v.__value_ == 0 || __v.__value_ == 1;
}
_LIBCPP_HIDE_FROM_ABI friend constexpr bool operator<(_CmpUnspecifiedParam, partial_ordering __v) noexcept {
- return __v.__is_ordered() && 0 < __v.__value_;
+ return __v.__value_ == 1;
}
_LIBCPP_HIDE_FROM_ABI friend constexpr bool operator<=(_CmpUnspecifiedParam, partial_ordering __v) noexcept {
- return __v.__is_ordered() && 0 <= __v.__value_;
+ return __v.__value_ == 0 || __v.__value_ == 1;
}
_LIBCPP_HIDE_FROM_ABI friend constexpr bool operator>(_CmpUnspecifiedParam, partial_ordering __v) noexcept {
- return __v.__is_ordered() && 0 > __v.__value_;
+ return __v.__value_ == -1;
}
_LIBCPP_HIDE_FROM_ABI friend constexpr bool operator>=(_CmpUnspecifiedParam, partial_ordering __v) noexcept {
- return __v.__is_ordered() && 0 >= __v.__value_;
+ return __v.__value_ == 0 || __v.__value_ == -1;
}
_LIBCPP_HIDE_FROM_ABI friend constexpr partial_ordering
More information about the libcxx-commits
mailing list