<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><br>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>