[committed v3] libsupc++: Change _Unordered comparison value to minimum value of signed char.
Jakub Jelinek
jakub@redhat.com
Wed Aug 27 16:58:22 GMT 2025
On Wed, Aug 27, 2025 at 03:18:55PM +0200, Tomasz Kamiński wrote:
> For any minimum value of a signed type, its negation (with wraparound) results
> in the same value, behaving like zero. Representing the unordered result with
> this minimum value, along with 0 for equal, 1 for greater, and -1 for less
> in partial_ordering, allows its value to be reversed using unary negation.
>
> The operator<=(partial_order, 0) now checks if the reversed value is positive.
> This works correctly because the unordered value remains unchanged and thus
> negative.
>
> libstdc++-v3/ChangeLog:
>
> * libsupc++/compare (_Ncmp::_Unordered): Rename and change the value
> to minimum value of signed char.
> (_Ncomp::unordered): Renamed from _Unordered, the name is reserved
> by partial_ordered::unordered.
> (partial_ordering::_M_reverse()): Define.
> (operator<=(partial_ordering, __cmp_cat::__unspec))
> (operator>=(__cmp_cat::__unspec, partial_ordering)): Implemented
> in terms of negated _M_value.
> (operator>=(partial_ordering, __cmp_cat::__unspec))
> (operator<=(__cmp_cat::__unspec, partial_ordering)): Directly
> compare _M_value, as unordered value is negative.
> (partial_ordering::unordered): Handle _Ncmp::unoredred rename.
> * python/libstdcxx/v6/printers.py: Add -128 as integer value
> for unordered, keeping 2 to preserve backward compatibility.
>
> Reviewed-by: Jonathan Wakely <jwakely@redhat.com>
> Signed-off-by: Tomasz Kamiński <tkaminsk@redhat.com>
This broke
+FAIL: g++.dg/opt/pr94589-2.C -std=gnu++20 scan-tree-dump-times optimized "i_[0-9]+\\\\(D\\\\) (?:<|<=|==|!=|>|>=) 5\\\\.0" 12
+FAIL: g++.dg/opt/pr94589-2.C -std=gnu++23 scan-tree-dump-times optimized "i_[0-9]+\\\\(D\\\\) (?:<|<=|==|!=|>|>=) 5\\\\.0" 12
+FAIL: g++.dg/opt/pr94589-2.C -std=gnu++26 scan-tree-dump-times optimized "i_[0-9]+\\\\(D\\\\) (?:<|<=|==|!=|>|>=) 5\\\\.0" 12
on i686-linux, x86_64-linux or powerpc64le-linux, additionally
FAIL: g++.dg/opt/pr94589-5.C -std=gnu++20 scan-tree-dump-times optimized "[ij]_[0-9]+\\\\(D\\\\) (?:<|<=|>|>=) [ij]_[0-9]+\\\\(D\\\\)" 8
FAIL: g++.dg/opt/pr94589-5.C -std=gnu++20 scan-tree-dump-times optimized "i_[0-9]+\\\\(D\\\\) (?:<|<=|>|>=) 5\\\\.0" 8
FAIL: g++.dg/opt/pr94589-5.C -std=gnu++23 scan-tree-dump-times optimized "[ij]_[0-9]+\\\\(D\\\\) (?:<|<=|>|>=) [ij]_[0-9]+\\\\(D\\\\)" 8
FAIL: g++.dg/opt/pr94589-5.C -std=gnu++23 scan-tree-dump-times optimized "i_[0-9]+\\\\(D\\\\) (?:<|<=|>|>=) 5\\\\.0" 8
FAIL: g++.dg/opt/pr94589-5.C -std=gnu++26 scan-tree-dump-times optimized "[ij]_[0-9]+\\\\(D\\\\) (?:<|<=|>|>=) [ij]_[0-9]+\\\\(D\\\\)" 8
FAIL: g++.dg/opt/pr94589-5.C -std=gnu++26 scan-tree-dump-times optimized "i_[0-9]+\\\\(D\\\\) (?:<|<=|>|>=) 5\\\\.0" 8
on powerpc64le-linux.
Both tree-ssa-phiopt.cc (spaceship_replacement)
and tree-ssa-math-opts.cc (optimize_spaceship)
attempt to optimize some spaceship comparisons.
Although I wrote both, my memory is weak, so just judging from function
comments, the latter likely should deal with values -1, 0, 1 and X where
X is some other value, so perhaps all we want to change there is
other than -1, 0, 1, for libstdc++ 2, for libc++ -127. */
to
other than -1, 0, 1, for libstdc++ -128, for libc++ -127. */
and adjust other comments that show the 2 value to show -128 instead.
But tree-ssa-phiopt.cc clearly optimizes only the 2 case and has pattern
recognition of the (x & ~1) == 0 and similar cases, which all will now be
different for -128. So, either spaceship_replacement needs to be rewritten
to only handle -128 instead of 2, or depending on the source either -128 or
2.
Jakub
More information about the Libstdc++
mailing list