I was testing the quality of code generated by LLVM vs gcc
I have a small program like this
#include<math.h>
double mysqrt(double a){
return sqrt(a);
}
int main()
{
mysqrt(0.1);
return 1;
}
Clang was emitting
mysqrt: # @mysqrt
# BB#0: # %entry
jmp sqrt # TAILCALL
which means it was calling sqrt function
gcc was emitting
mysqrt:
.LFB25:
.cfi_startproc
subl $28, %esp
.cfi_def_cfa_offset 32
fldl 32(%esp)
fld %st(0)
fsqrt
fucomi %st(0), %st
which means it was using direct machine instruction fsqrt (which i suppose is much faster than calling function). This was done for X86 machine with O3 level of optimization. Does anybody know why LLVM is calling function instead of using machine instruction?
The behavior of gcc is not standard C, since that inlined call is missing error checks. To have standard conforming behavior with gcc, compile with option -std=c99 or similar. To force clang to forget about its standard compliance something like -ffast-math might help.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With