[RFC] transforming libm calls into intrinsics

Redmond, Paul paul.redmond at intel.com
Wed Jan 30 09:20:51 PST 2013


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

-------------- next part --------------
A non-text attachment was scrubbed...
Name: libcalltointrinsic.diff
Type: application/octet-stream
Size: 24967 bytes
Desc: libcalltointrinsic.diff
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20130130/310b0fe6/attachment.obj>


More information about the llvm-commits mailing list