[LLVMdev] complex library functions (creal and cimag)

Eli Friedman eli.friedman at gmail.com
Fri Apr 27 14:02:11 PDT 2012


On Fri, Apr 27, 2012 at 12:09 PM, Akira Hatanaka <ahatanak at gmail.com> wrote:
> When I compile this code which includes call to crealf,
>
> $ cat foo1.c
> #include <complex.h>
>
> float foo1(complex float z) { return crealf(z); }
>
> clang emits a call to crealf,
>
> $ clang  foo1.c -S -o - -O3
> foo1:                                   # @foo1
>     .cfi_startproc
> # BB#0:                                 # %entry
>     jmp    crealf                  # TAILCALL
>
> while gcc does it in two move instructions:
>
> $ gcc foo1.c -S -o -O3
> foo1:
> .LFB0:
>         .cfi_startproc
>         movq    %xmm0, -8(%rsp)
>         movss   -8(%rsp), %xmm0
>
> Is this an optimization which is missing in llvm?

Missing optimization.  There isn't any reason to avoid inlining the
implementation.

Probably the simplest place to implement this would be CGBuiltin in clang...

-Eli




More information about the llvm-dev mailing list