[LLVMdev] complex library functions (creal and cimag)

Akira Hatanaka ahatanak at gmail.com
Wed May 2 16:23:40 PDT 2012


Please see the attached patches.

The first patch implements this optimization in SimplifyLibCalls.cpp.
I tried to accommodate all the different ways complex arguments are
converted in clang/lib/CodeGen/TargetInfo.cpp, but I am pretty sure some of
them haven't been covered.

The second patch implements it in CGBuiltin.cpp. This one is much simpler
than the first one.
The downside of this approach is that it only optimizes builtin functions.
Also, the optimization is not available to non-clang front-ends.

Which one is the better approach?

I will resend the patch with a test case to llvm-commit if either one is
acceptable.

On Sat, Apr 28, 2012 at 9:29 AM, Chris Lattner <clattner at apple.com> wrote:

> On Apr 27, 2012, at 2:02 PM, Eli Friedman wrote:
> > On Fri, Apr 27, 2012 at 12:09 PM, Akira Hatanaka <ahatanak at gmail.com>
> wrote:
> >> 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...
>
> It would also make sense to handle this in simplifylibcalls.  There isn't
> anything C-specific about this.
>
> -Chris
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20120502/e8061171/attachment.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: simplifycreal.patch
Type: text/x-patch
Size: 4477 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20120502/e8061171/attachment.bin>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: builtincreal.patch
Type: text/x-patch
Size: 870 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20120502/e8061171/attachment-0001.bin>


More information about the llvm-dev mailing list