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

Antoine Pitrou via llvm-dev llvm-dev at lists.llvm.org
Thu Jan 12 05:03:05 PST 2017

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.

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

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()



More information about the llvm-dev mailing list