[llvm-commits] Patch: Math Lib call optimization

Zhao, Weiming weimingz at qualcomm.com
Wed Nov 2 13:46:08 PDT 2011


Yes, it would be a very nice feature if C front-end could support this.
But for existing .bc codes, such a pass still provides an opportunity to optimize the performance.

-----Original Message-----
From: llvm-commits-bounces at cs.uiuc.edu [mailto:llvm-commits-bounces at cs.uiuc.edu] On Behalf Of Dan Gohman
Sent: Wednesday, November 02, 2011 1:16 PM
To: Weiming Zhao
Cc: rajav at codeaurora.org; llvm-commits at cs.uiuc.edu
Subject: Re: [llvm-commits] Patch: Math Lib call optimization

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

_______________________________________________
llvm-commits mailing list
llvm-commits at cs.uiuc.edu
http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits




More information about the llvm-commits mailing list