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

            Bug ID: 98095
           Summary: Optimize __builtin_unordered (...) ||
                    __builtin_is{less,greater}{,equal}
           Product: gcc
           Version: unknown
            Status: UNCONFIRMED
          Severity: enhancement
          Priority: P3
         Component: tree-optimization
          Assignee: unassigned at gcc dot gnu.org
          Reporter: ubizjak at gmail dot com
  Target Milestone: ---

These two functions are equivalent:

int t3 (float a, float b)
{
  return  __builtin_isless (a, b) || __builtin_isunordered (a, b);
}

int t4 (float a, float b)
{
  return  !__builtin_isgreaterequal (a, b);
}

gcc -O2:

t3:
        ucomiss %xmm0, %xmm1
        seta    %al
        ucomiss %xmm1, %xmm0
        setp    %dl
        orl     %edx, %eax
        movzbl  %al, %eax
        ret

t4:
        xorl    %eax, %eax
        ucomiss %xmm1, %xmm0
        setb    %al
        ret

Proof:

for ordered operands:
the result of t3 is (a < b); the result of t4 is !(a >= b) = (a < b)

for unordered operands:
the result of the t3 is true; the result of t4 is !false = true.

q.e.d.

The above equivalence is true for all relations. I didn't check
__builtin_islessgreater; although gcc provides UNEQ, it doesn't provide
__builtin_isequal builtin function.
  • [Bug tree-optimization/98095] ... ubizjak at gmail dot com via Gcc-bugs

Reply via email to