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

            Bug ID: 127617
           Summary: convert double comparison to difference or the other
                    way around
           Product: gcc
           Version: 16.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: middle-end
          Assignee: unassigned at gcc dot gnu.org
          Reporter: manu at gcc dot gnu.org
  Target Milestone: ---

https://godbolt.org/z/ozoh3Y46G

I am not sure which option is faster, but _2 and _3 should produce the same
code, no? (whatever code is faster)


```
#include <stdbool.h>
bool
dominates_2d(const double * restrict a, const double * restrict b)
{
    return a[0] <= b[0] && a[1] <= b[1] && (a[0] != b[0] || a[1] != b[1]);
}

bool
dominates_2d_2(const double * restrict a, const double * restrict b)
{
    return (a[0] <= b[0]) & (a[1] <= b[1]) & (a[0] != b[0] || a[1] != b[1]);
}

bool
dominates_2d_3(const double * restrict a, const double * restrict b)
{
    const double diff0 = b[0] - a[0];
    const double diff1 = b[1] - a[1];
    return (diff0 >= 0) & (diff1 >= 0) & ((diff0 != 0) || (diff1 != 0));
}
```

Compile with: -Wall -Wpedantic -Wextra -O3 -march=x86-64-v2 -ffast-math

produces:

"dominates_2d":
        movsd   xmm1, QWORD PTR [rdi]
        movsd   xmm0, QWORD PTR [rsi]
        comisd  xmm0, xmm1
        jb      .L4
        movsd   xmm3, QWORD PTR [rdi+8]
        movsd   xmm2, QWORD PTR [rsi+8]
        comisd  xmm2, xmm3
        jb      .L4
        comisd  xmm3, xmm2
        setne   al
        comisd  xmm1, xmm0
        setne   dl
        or      eax, edx
        ret
.L4:
        xor     eax, eax
        ret
"dominates_2d_2":
        movsd   xmm1, QWORD PTR [rdi]
        movsd   xmm0, QWORD PTR [rsi]
        movsd   xmm3, QWORD PTR [rdi+8]
        movsd   xmm2, QWORD PTR [rsi+8]
        comisd  xmm0, xmm1
        setnb   al
        comisd  xmm2, xmm3
        setnb   dl
        and     eax, edx
        comisd  xmm3, xmm2
        setne   dl
        comisd  xmm1, xmm0
        setne   cl
        or      edx, ecx
        and     eax, edx
        ret
"dominates_2d_3":
        movsd   xmm2, QWORD PTR [rsi]
        subsd   xmm2, QWORD PTR [rdi]
        pxor    xmm0, xmm0
        movsd   xmm1, QWORD PTR [rsi+8]
        subsd   xmm1, QWORD PTR [rdi+8]
        comisd  xmm2, xmm0
        setnb   al
        comisd  xmm1, xmm0
        setnb   dl
        and     eax, edx
        comisd  xmm2, xmm0
        setne   dl
        comisd  xmm1, xmm0
        setne   cl
        or      edx, ecx
        and     eax, edx
        ret

Reply via email to