[LLVMdev] sqrt

0 views
Skip to first unread message

Jon Harrop

unread,
Jan 7, 2010, 10:06:07 AM1/7/10
to LLVM Developers Mailing List

What is the state of sqrt in LLVM?

It was an intrinsic but there are no OCaml bindings for it and, last I looked,
it generated inefficient code on Linux due to this bug:

http://www.llvm.org/PR3219

Is the intrinsic deprecated? Am I losing a lot of performance by calling sqrt
from libm instead of using the intrinsic?

--
Dr Jon Harrop, Flying Frog Consultancy Ltd.
http://www.ffconsultancy.com/?e
_______________________________________________
LLVM Developers mailing list
LLV...@cs.uiuc.edu http://llvm.cs.uiuc.edu
http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev

Chris Lattner

unread,
Jan 7, 2010, 12:48:03 PM1/7/10
to Jon Harrop, LLVM Developers Mailing List

On Jan 7, 2010, at 7:06 AM, Jon Harrop wrote:

>
> What is the state of sqrt in LLVM?
>
> It was an intrinsic but there are no OCaml bindings for it and, last
> I looked,
> it generated inefficient code on Linux due to this bug:
>
> http://www.llvm.org/PR3219
>
> Is the intrinsic deprecated? Am I losing a lot of performance by
> calling sqrt
> from libm instead of using the intrinsic?

There is a fundamental difference between sqrt() and llvm.sqrt: the
former is defined on negative values and sets errno (on linux). The
later is undefined. Both work well for their stated purpose,
llvm.sqrt should not be slower than sqrt even on linux. Both
llvm.sqrt and sqrt could be much better on linux, but noone seems
compelled to do the work.

-Chris

Sandeep Patel

unread,
Jan 7, 2010, 3:28:57 PM1/7/10
to Chris Lattner, Jon Harrop, LLVM Developers Mailing List
On Thu, Jan 7, 2010 at 5:48 PM, Chris Lattner <clat...@apple.com> wrote:
>
> On Jan 7, 2010, at 7:06 AM, Jon Harrop wrote:
>
>>
>> What is the state of sqrt in LLVM?
>>
>> It was an intrinsic but there are no OCaml bindings for it and, last
>> I looked,
>> it generated inefficient code on Linux due to this bug:
>>
>>  http://www.llvm.org/PR3219
>>
>> Is the intrinsic deprecated? Am I losing a lot of performance by
>> calling sqrt
>> from libm instead of using the intrinsic?
>
> There is a fundamental difference between sqrt() and llvm.sqrt: the
> former is defined on negative values and sets errno (on linux).  The
> later is undefined.  Both work well for their stated purpose,
> llvm.sqrt should not be slower than sqrt even on linux.  Both
> llvm.sqrt and sqrt could be much better on linux, but noone seems
> compelled to do the work.

Many platforms could also benefit from recognizing 1.0/sqrt() as rsqrt().

deep

Robert A. Zeh

unread,
Jan 7, 2010, 6:53:11 PM1/7/10
to Chris Lattner, Jon Harrop, LLVM Developers Mailing List

On Jan 7, 2010, at 11:48 AM, Chris Lattner <clat...@apple.com> wrote:

> There is a fundamental difference between sqrt() and llvm.sqrt: the
> former is defined on negative values and sets errno (on linux). The
> later is undefined. Both work well for their stated purpose,
> llvm.sqrt should not be slower than sqrt even on linux. Both
> llvm.sqrt and sqrt could be much better on linux, but noone seems
> compelled to do the work.
>
> -Chris

What exactly is the work for llvm.sqrt on Linux?

Chris Lattner

unread,
Jan 7, 2010, 7:04:36 PM1/7/10
to Robert A. Zeh, Jon Harrop, LLVM Developers Mailing List

On Jan 7, 2010, at 3:53 PM, Robert A. Zeh wrote:

>
> On Jan 7, 2010, at 11:48 AM, Chris Lattner <clat...@apple.com> wrote:
>
>> There is a fundamental difference between sqrt() and llvm.sqrt: the
>> former is defined on negative values and sets errno (on linux). The
>> later is undefined. Both work well for their stated purpose,
>> llvm.sqrt should not be slower than sqrt even on linux. Both
>> llvm.sqrt and sqrt could be much better on linux, but noone seems
>> compelled to do the work.
>>
>> -Chris
>
> What exactly is the work for llvm.sqrt on Linux?

Ah sorry, llvm.sqrt works fine on linux. The issue is that a raw call to sqrt() in a C program doesn't typically compile to llvm.sqrt on linux, because it sets errno. This can be controlled with -fmath-errno.

-Chris

Dale Johannesen

unread,
Jan 7, 2010, 7:14:32 PM1/7/10
to Chris Lattner, Jon Harrop, LLVM Developers Mailing List

On Jan 7, 2010, at 4:04 PMPST, Chris Lattner wrote:
> On Jan 7, 2010, at 3:53 PM, Robert A. Zeh wrote:
> On Jan 7, 2010, at 11:48 AM, Chris Lattner <clat...@apple.com> wrote:
>>
>>> There is a fundamental difference between sqrt() and llvm.sqrt: the
>>> former is defined on negative values and sets errno (on linux). The
>>> later is undefined. Both work well for their stated purpose,
>>> llvm.sqrt should not be slower than sqrt even on linux. Both
>>> llvm.sqrt and sqrt could be much better on linux, but noone seems
>>> compelled to do the work.
>>>
>>> -Chris
>>
>> What exactly is the work for llvm.sqrt on Linux?
>
> Ah sorry, llvm.sqrt works fine on linux. The issue is that a raw
> call to sqrt() in a C program doesn't typically compile to llvm.sqrt
> on linux, because it sets errno. This can be controlled with -fmath-
> errno.


It is more than errno. sqrt() should't compile to llvm.sqrt on any
platform that uses IEEE754 math, because IEEE sqrt() is well defined
on negative arguments and llvm.sqrt isn't. There are currently no
command line arguments to override this.

Duncan Sands

unread,
Jan 8, 2010, 1:46:05 AM1/8/10
to Dale Johannesen, Jon Harrop, LLVM Developers Mailing List
Hi Dale,

> It is more than errno. sqrt() should't compile to llvm.sqrt on any
> platform that uses IEEE754 math, because IEEE sqrt() is well defined
> on negative arguments and llvm.sqrt isn't. There are currently no
> command line arguments to override this.

-funsafe-math-optimizations?

Ciao,

Duncan.

Reply all
Reply to author
Forward
0 new messages