<div dir="ltr">On 18 August 2013 22:38, Eugene Toder <span dir="ltr"><<a href="mailto:eltoder@gmail.com" target="_blank">eltoder@gmail.com</a>></span> wrote:<br><div class="gmail_extra"><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">

<div dir="ltr">Hi,<br><br>I found that in some cases llvm generates duplicate loads of double constants,<br>e.g.<br><br>$ cat t.c<br>double f(double* p, int n)<br>{<br>    double s = 0;<br>    if (n)<br>        s += *p;<br>


    return s;<br>}<br>$ clang -S -O3 t.c -o -<br>...<br>f:                                      # @f<br>        .cfi_startproc<br># BB#0:<br>        xorps   %xmm0, %xmm0<br>        testl   %esi, %esi<br>        je      .LBB0_2<br>


# BB#1:<br>        xorps   %xmm0, %xmm0<br>        addsd   (%rdi), %xmm0<br>.LBB0_2:<br>        ret<br>...<br></div></blockquote><div><br></div><div>Thanks. Please file a bug for this on <a href="http://llvm.org/bugs">llvm.org/bugs</a> .</div>

<div><br></div><div>The crux of the problem is that machine CSE runs before register allocation and is consequently extremely conservative when doing CSE to avoid potentially increasing register pressure. Of course, with such a small testcase, register pressure isn't a problem. MachineCSE might be able to do a better job here.</div>

<div><br></div><div>Nick</div><div><br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">Note that there are 2 xorps instructions, the one in BB#1 being clearly redundant<br>

as it's dominated by the first one. Two xorps come from 2 FsFLD0SD generated by<br>
instruction selection and never eliminated by machine passes. My guess would be<br>machine CSE should take care of it.<br><br>A variation of this case without indirection shows the same problem, as well as<br>not commuting addps, resulting in an extra movps:<br>


<br>$ cat t.c<br>double f(double p, int n)<br>{<br>    double s = 0;<br>    if (n)<br>        s += p;<br>    return s;<br>}<br>$ clang -S -O3 t.c -o -<br>...<br>f:                                      # @f<br>        .cfi_startproc<br>


# BB#0:<br>        xorps   %xmm1, %xmm1<br>        testl   %edi, %edi<br>        je      .LBB0_2<br># BB#1:<br>        xorps   %xmm1, %xmm1<br>        addsd   %xmm1, %xmm0<br>        movaps  %xmm0, %xmm1<br>.LBB0_2:<br>        movaps  %xmm1, %xmm0<br>


        ret<br>...<br><br>Thanks,<br>Eugene<br><br></div>
<br>_______________________________________________<br>
LLVM Developers mailing list<br>
<a href="mailto:LLVMdev@cs.uiuc.edu">LLVMdev@cs.uiuc.edu</a>         <a href="http://llvm.cs.uiuc.edu" target="_blank">http://llvm.cs.uiuc.edu</a><br>
<a href="http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev" target="_blank">http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev</a><br>
<br></blockquote></div><br></div></div>