Please see the attached patches.<br><br>The first patch implements this optimization in SimplifyLibCalls.cpp.<br>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.<br>
<br>The second patch implements it in CGBuiltin.cpp. This one is much simpler than the first one.<br>The downside of this approach is that it only optimizes builtin functions. Also, the optimization is not available to non-clang front-ends.<br>
<br>Which one is the better approach?<br><br>I will resend the patch with a test case to llvm-commit if either one is acceptable.<br><br><div class="gmail_quote">On Sat, Apr 28, 2012 at 9:29 AM, Chris Lattner <span dir="ltr"><<a href="mailto:clattner@apple.com" target="_blank">clattner@apple.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0pt 0pt 0pt 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div class="im">On Apr 27, 2012, at 2:02 PM, Eli Friedman wrote:<br>
> On Fri, Apr 27, 2012 at 12:09 PM, Akira Hatanaka <<a href="mailto:ahatanak@gmail.com">ahatanak@gmail.com</a>> wrote:<br>
</div><div class="im">>> while gcc does it in two move instructions:<br>
>><br>
>> $ gcc foo1.c -S -o -O3<br>
>> foo1:<br>
>> .LFB0:<br>
>>         .cfi_startproc<br>
>>         movq    %xmm0, -8(%rsp)<br>
>>         movss   -8(%rsp), %xmm0<br>
>><br>
>> Is this an optimization which is missing in llvm?<br>
><br>
> Missing optimization.  There isn't any reason to avoid inlining the<br>
> implementation.<br>
><br>
> Probably the simplest place to implement this would be CGBuiltin in clang...<br>
<br>
</div>It would also make sense to handle this in simplifylibcalls.  There isn't anything C-specific about this.<br>
<span class="HOEnZb"><font color="#888888"><br>
-Chris<br>
</font></span></blockquote></div><br>