[LLVMdev] Optimize away sqrt in simple cases?

Owen Anderson resistor at mac.com
Tue Apr 23 16:01:07 PDT 2013


On Apr 23, 2013, at 3:33 PM, Christoph Grenz <christophg+llvm at grenz-bonn.de> wrote:

> Hello,
> 
> Am Dienstag, 23. April 2013, 13:26:19 schrieb Owen Anderson:
>> That's a pretty seriously unsafe floating point optimization.  It could be
>> done in fast-math mode, but I doubt we currently do it.
> 
> I just saw this thread and wonder why it's "seriously" unsafe? I see only one 
> problematic corner case.
> 
> For x >= 0.0 the result cannot lose precision.

This is not true.  The mathematically correct result for sqrt might not be a representable value in floating point, so rounding may occur between the two steps.  In that case, pow2(sqrt(x)) != x.

--Owen





More information about the llvm-dev mailing list