[LLVMdev] Math instructions

Morten Ofstad morten at hue.no
Tue Jan 4 01:53:07 PST 2005


Hello,

I'm currently adding the floating point math instructions (fabs, fsin, 
fcos ...) to the x86 instruction set. I'm a bit unsure how to make the 
back end actually generate these instructions, though. My current plan 
is to add llvm intrinsics for these instructions but I've noticed that 
llvm already handles C math library functions to some extent. It feels a 
bit strange to add code for example to constant fold these intrinsics 
when there is already code to constant fold a calls to libmath functions 
-- but the libmath functions have certain semantics regarding how errno 
is set which I don't really want to deal with.

Other compilers have options to enable the direct use of fp instructions 
for math operations (gcc has -fno-math-errno, 
-funsafe-math-optimizations and -fno-trapping-math), this could be 
useful also for LLVM. Assuming there is such an option, should I modify 
the visitCallInst function to generate machine instructions directly for 
calls to math functions or is it better to include a pass which converts 
the calls into intrinsics? An advantage of the second solution is that 
it makes it easier for other front ends (like ours) which don't have the 
semantics of libmath to generate code...

Awaiting feedback,

m.




More information about the llvm-dev mailing list