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

            Bug ID: 103973
           Summary: x86: 4-way comparison of floats/doubles with spaceship
                    operator possibly suboptimal
           Product: gcc
           Version: 12.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: target
          Assignee: unassigned at gcc dot gnu.org
          Reporter: nekotekina at gmail dot com
  Target Milestone: ---

Hello, I may be missing something here but the generated code seems strange and
suboptimal. It looks like all 4 possible paths can use flags from a single
UCOMISD instruction, not calling it 3 times in worst case.

cmp4way(double, double):
        ucomisd xmm0, xmm1
        jp      .L8
        mov     eax, 0
        jne     .L8
.L2:
        ret
.L8:
        comisd  xmm1, xmm0
        mov     eax, -1
        ja      .L2
        ucomisd xmm0, xmm1
        setbe   al
        add     eax, 1
        ret

https://godbolt.org/z/j1j7G1MYP

#include <compare>

auto cmp4way(double a, double b)
{
    return a <=> b;
}

Reply via email to