[LLVMdev] Other Intrinsics?

Dan Gohman djg at cray.com
Tue Nov 27 13:37:16 PST 2007

On Tue, Nov 27, 2007 at 10:50:03AM -0700, Jon Sargeant wrote:
>  > > Do you have plans to add other intrinsics?  I'm curious as to why there
>  > > is an llvm.sin intrinsic and an llvm.cos intrinsic, but no llvm.atan
>  > > intrinsic.  Why is there an llvm.pow intrinsic but no llvm.log
>  > > intrinsic?
>  >
>  > Intrinsics get added on demand.  Generally there has to be a good reason
>  > to add them.  llvm.sin was implemented (for example) to allow generation
>  > of code that uses vector sin operations.
> What is the criteria for adding an intrinsic or a built-in operation?
> For example, could the 'frem' instruction be an intrinsic?  Could you 
> remove it from LLVM entirely and make it an external function?  What 
> distinguishes 'frem' from 'sin', 'pow', 'atan2', etc.?

The main difference from my perspective between intrinsics and instructions
is that intrinsics don't require bitcode format changes. If someone wants an
atan2 intrinsic for example, it would be fairly easy, and we wouldn't have
to worry very much about collisions with other people adding new intrinsics,
where we would if we were adding new operators.

The main reason for adding intrinsics instead of just using C library
calls is for support for vector types. @llvm.sin.* can be overloaded as
@llvm.sin.v4f32, for example, which is very useful for some users.

The intrinsics for sin, cos, and pow are fairly new; I added them when
I implemented the support for vector types in intrinsics, to exercise this
new infastructure. It would be easy now to add similar intrinsics for other
math functions.


Dan Gohman, Cray Inc.

More information about the llvm-dev mailing list