https://gcc.gnu.org/bugzilla/show_bug.cgi?id=92985

Avi Kivity <a...@cloudius-systems.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |a...@cloudius-systems.com

--- Comment #5 from Avi Kivity <a...@cloudius-systems.com> ---
Here's another example:


#include <compare>

int strong_ordering_to_int(std::strong_ordering x) {
    if (x == std::strong_ordering::equal) {
        return 0;
    } else if (x == std::strong_ordering::less) {
        return -1;
    } else if (x == std::strong_ordering::greater) {
        return 1;
    }
    __builtin_unreachable();
}

Used to translate the new std::strong_ordering back to int (in this case for
compatibility with older code, but one can imagine many such translations from
opaque enums to another enum when crossing an API boundary).

gcc generates (-O3)

strong_ordering_to_int(std::strong_ordering):
        xorl    %eax, %eax
        testb   %dil, %dil
        je      .L1
        xorl    %eax, %eax
        cmpb    $-1, %dil
        setne   %al
        leal    -1(%rax,%rax), %eax
.L1:
        ret


Where it could have generated

        movsx    %dil, %eax
        ret

Reply via email to