[LLVMbugs] [Bug 17758] New: calling double-precision sqrt with a float: not so fast, fast-math

bugzilla-daemon at llvm.org bugzilla-daemon at llvm.org
Thu Oct 31 10:55:13 PDT 2013


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

            Bug ID: 17758
           Summary: calling double-precision sqrt with a float: not so
                    fast, fast-math
           Product: new-bugs
           Version: trunk
          Hardware: PC
                OS: All
            Status: NEW
          Severity: normal
          Priority: P
         Component: new bugs
          Assignee: unassignedbugs at nondot.org
          Reporter: kkhoo at perfwizard.com
                CC: llvmbugs at cs.uiuc.edu
    Classification: Unclassified

$ cat sqrt.c 
#include <math.h>
float foo(float x) {
    return sqrt(x);
}

Compiled for x86-64 *without* fast-math produces (extra text removed):

$ ./clang  -O3 -fomit-frame-pointer  -o - -S sqrt.c 
_foo:                                   ## @foo
    sqrtss    %xmm0, %xmm0
    ret


Compiled for x86-64 *with* fast-math produces:

$ ./clang  -O3 -fomit-frame-pointer  -o - -S sqrt.c -ffast-math
_foo:                                   ## @foo
    cvtss2sd    %xmm0, %xmm0
    sqrtsd    %xmm0, %xmm0
    cvtsd2ss    %xmm0, %xmm0
    ret

I'm not sure if there are one or two bugs here:
1. Without fast-math, is it legal to *not* have the type conversions (ie, is
the compiler allowed to transform a call to double-precision 'sqrt' into
'sqrtf')?

2. With fast-math, I would expect to avoid the type conversions and use of the
double-precision square root instruction (ie, the compiler should convert the
call to 'sqrt' to 'sqrtf' because the input and output are both
single-precision).

This is with:
$ ./clang -v
clang version 3.4 (trunk 193529) (llvm/trunk 193527)
Target: x86_64-apple-darwin11.4.2
Thread model: posix

-- 
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/20131031/4013ae91/attachment.html>


More information about the llvm-bugs mailing list