-
Notifications
You must be signed in to change notification settings - Fork 12k
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
[libc++] Check explicit values in the partial_ordering comparators for better code gen #81366
Conversation
@llvm/pr-subscribers-libcxx Author: Nikolas Klauser (philnik777) ChangesThis allows the compiler to check for specific bit patterns instead of value ranges. Full diff: https://github.com/llvm/llvm-project/pull/81366.diff 1 Files Affected:
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
|
56bf23d
to
b4477ec
Compare
✅ With the latest revision this PR passed the C/C++ code formatter. |
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.
LGTM. Please rebase onto main
and merge if the CI is green.
…r better code gen
b4477ec
to
d8ae1ff
Compare
This allows the compiler to check for specific bit patterns instead of value ranges.