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

            Bug ID: 61563
           Summary: better 387 code for float x == (int)x
           Product: gcc
           Version: unknown
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: target
          Assignee: unassigned at gcc dot gnu.org
          Reporter: jay.foad at gmail dot com

I get this with GCC 4.10.0 20140619 (experimental):

$ gcc -mno-sse -O3 -S -o - -x c - <<<"int f(float x) { return x == (int)x; }"
...
f:
    fnstcw    -2(%rsp)
    movzwl    -2(%rsp), %eax
    flds    8(%rsp)
    movl    $0, %edx
    orb    $12, %ah
    movw    %ax, -4(%rsp)
    xorl    %eax, %eax
    fldcw    -4(%rsp)
    fistl    -12(%rsp)
    fldcw    -2(%rsp)
    fildl    -12(%rsp)
    fucomip    %st(1), %st
    fstp    %st(0)
    setnp    %al
    cmovne    %edx, %eax
    ret

All the fnstcw and fldcw stuff is unnecessary, because when we convert x to
int, it doesn't matter what rounding mode we use; all that matters is whether
it is already an exact int value or not.

I think the x == (int)x pattern is fairly common, and it would be nice if GCC
generated better 387 code for it.

Reply via email to