[LLVMbugs] [Bug 20086] New: better 387 code for float x == (int)x

bugzilla-daemon at llvm.org bugzilla-daemon at llvm.org
Fri Jun 20 01:23:12 PDT 2014


http://llvm.org/bugs/show_bug.cgi?id=20086

            Bug ID: 20086
           Summary: better 387 code for float x == (int)x
           Product: libraries
           Version: trunk
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: normal
          Priority: P
         Component: Backend: X86
          Assignee: unassignedbugs at nondot.org
          Reporter: jay.foad at gmail.com
                CC: llvmbugs at cs.uiuc.edu
    Classification: Unclassified

I get this with clang 3.5.0 (trunk) at r211342:

$ clang -mno-sse -O3 -S -o - -x c - <<<"int f(float x) { return x == (int)x; }"
...
f:
    flds    8(%rsp)
    fnstcw    -10(%rsp)
    movw    -10(%rsp), %ax
    movw    $3199, -10(%rsp)        # imm = 0xC7F
    fldcw    -10(%rsp)
    movw    %ax, -10(%rsp)
    fistl    -8(%rsp)
    fldcw    -10(%rsp)
    movl    -8(%rsp), %eax
    movl    %eax, -4(%rsp)
    fildl    -4(%rsp)
    fucompi    %st(1)
    fstp    %st(0)
    setnp    %al
    sete    %cl
    andb    %al, %cl
    movzbl    %cl, %eax
    retq

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 clang
generated better 387 code for it.

On the corresponding GCC bug:
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=61563
Joseph pointed out that for other combinations of floating point and integer
types (e.g. double and int) it's not completely safe to use a different
rounding mode, because it might affect whether the conversion to int raises an
"invalid" exception.

-- 
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20140620/432da823/attachment.html>


More information about the llvm-bugs mailing list