[llvm-commits] Patch: Math Lib call optimization

Dan Gohman gohman at apple.com
Wed Nov 2 13:15:45 PDT 2011


On Nov 2, 2011, at 11:07 AM, Weiming Zhao wrote:

> Hello,
> 
> I worked on an LLVM patch to optimize mathematical library calls and would like to submit it to your review.
> 
> A. Background:
> In C89, most of the mathematical accept only the type "double" for the floating-point arguments. 
> Later on, in C99, this limitation was fixed by introducing new sets of functions with "f" suffixes that accept "float" arguments.   Our experiments show that, on ARM platform, the "float" type versions are significantly faster than their double precision counterparts. For example, "float sinf(float)" is 1.87 times faster than "double sin(double)".  
>  
> However, this new set of functions are not always exploited by programmers. For example, a programmer may write:
> void foo(float y)
>   float x = sin(y);
>   ...
> }
> instead of writing:
> void foo(float y)
>   float x = sinf(y);
>   ...
> }
> 
> B. This optimization:
> This optimization looks for missed opportunities, in which a lighter weighted function could be used without losing precision. 

There is precision loss in some cases, even with sin.

This seems top me like a good example of an optimization that should be
done in the source code, rather than the compiler.  C front-ends could
easily detect such opportunities, and could suggest the use of <tgmath.h>
or the use of the appropriate "f" function as a fixit. This would make it
easy for people to update their code to realize the speedups, while
making their own determinations on when and where single-precision
library calls are acceptable.

Dan




More information about the llvm-commits mailing list