[RFC] transforming libm calls into intrinsics

Alex Rosenberg alexr at leftfield.org
Wed Jan 30 21:38:42 PST 2013


I may be in the minority on this, but I far prefer that the front end identify calls that are intrinsics. It can confirm that the calling conventions match and even perhaps that the function is declared in the standard-specified header for extra paranoia.

It may also be important to avoid this transformation within the standard library or kernel, and Clang already has a means to request disabling transformations of this type.

Sent from my iPad

On Jan 30, 2013, at 9:20 AM, "Redmond, Paul" <paul.redmond at intel.com> wrote:

> Attached is pass called LibCallToInstrinsic which transforms math function calls into intrinsics. The primary motivation for this patch is:
> 
> 1) Expose more intrinsics to the loop vectorizer
> 
> The loop vectorizer can widen some intrinsics but Clang doesn't generate any. Therefore any loops with sinf, sqrtf, etc. are not vectorized.
> 
> 2) Make it easier to perform more optimizations on math functions (e.g., InstCombine)
> 
> It should be easy to add math function optimizations using intrinsic pattern matchers for example.
> 
> 3) Consolidate handling of intrinsics/lib calls
> 
> If you have a function and an intrinsic that do the same thing it doesn't make sense to treat them differently. When functions are subsets of intrinsics it makes sense to transform the call to an intrinsic call.
> 
> 
> Currently this patch only transforms some calls when -ffast-math is enabled. I don't think this is a requirement given that the reference manual says they are equivalent to their libm counterparts but I don't have a good idea how to do this safely.
> 
> This patch is far from complete but I'd like to use it to start a discussion and gauge interest. Here are a few questions I have:
> 
> - should this transformation be its own pass or added to an existing pass?
> - would it make sense to support fast math flags on the intrinsics? (perhaps the math intrinsics should be promoted to instructions?)
> - are there any drawbacks to this approach that I've overlooked?
> 
> paul
> 
> <libcalltointrinsic.diff>
> _______________________________________________
> 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