[llvm-dev] The most efficient way to implement an integer based power function pow in LLVM

Mehdi Amini via llvm-dev llvm-dev at lists.llvm.org
Thu Jan 12 09:33:57 PST 2017


> On Jan 12, 2017, at 5:03 AM, Antoine Pitrou via llvm-dev <llvm-dev at lists.llvm.org> wrote:
> 
> On Mon, 9 Jan 2017 11:43:17 -0600
> Wei Ding via llvm-dev <llvm-dev at lists.llvm.org> wrote:
>> Hi,
>> 
>> I want an efficient way to implement function pow in LLVM instead of
>> invoking pow() math built-in. For algorithm part, I am clear for the logic.
>> But I am not quite sure for which parts of LLVM should I replace built-in
>> pow with another efficient pow implementation. Any comments and feedback
>> are appreciated. Thanks!
> 
> In Numba, we have decided to optimize some usages of the power function
> in our own front-end, so that LLVM IR gets an already optimized form,
> as we have found that otherwise LLVM may miss some optimization
> opportunities. YMMV.

It seems to me that it would be more interesting to gather these misoptimization and fix LLVM to catch them.

> 
> (e.g. we detect that the exponent is a compile-time constant and
> transform `x**3` into `x*x*x`)

This seems definitely in the scope of what LLVM could do, potentially with TTI.

— 
Mehdi


> 
> Note that not only `pow(x, 3)` can be slower than `x*x*x`, but it may
> also have some precision issues, as it goes through log() and exp()
> calls.
> 
> Regards
> 
> Antoine.
> 
> 
> _______________________________________________
> LLVM Developers mailing list
> llvm-dev at lists.llvm.org
> http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev



More information about the llvm-dev mailing list