[LLVMdev] llvm.powi intrinsic

Chris Lattner sabre at nondot.org
Mon Nov 26 19:50:36 PST 2007


> The purpose of the llvm.powi intrinsic isn't clear to me.  Why is
> llvm.powi preferable to multiplication and division for small constant
> powers (e.g., 1/x, x*x, etc.)?  Why is it preferable to llvm.pow for
> large variable powers?  I'm also curious about the time bound.  I'm
> assuming that powi(x,1000000) doesn't do a million multiplications...
> Do any architectures have an integer power instruction of some sort?

The purpose of this is to capture this information at a higher level, 
allowing the code generator top (eventually) lower it into an optimal 
sequence of multiplies.  for example, powi(x, 9) can be lowered to:

t = x*x;
t2 = t*t
result = t2*t2*x

The code generator doesn't currently do any smart lowering, if you're 
interested in this, it would be a great place to dive in

-Chris

-- 
http://nondot.org/sabre/
http://llvm.org/



More information about the llvm-dev mailing list