[LLVMdev] Duplicate loading of double constants

Eugene Toder eltoder at gmail.com
Sun Aug 18 22:38:23 PDT 2013


Hi,

I found that in some cases llvm generates duplicate loads of double
constants,
e.g.

$ cat t.c
double f(double* p, int n)
{
    double s = 0;
    if (n)
        s += *p;
    return s;
}
$ clang -S -O3 t.c -o -
...
f:                                      # @f
        .cfi_startproc
# BB#0:
        xorps   %xmm0, %xmm0
        testl   %esi, %esi
        je      .LBB0_2
# BB#1:
        xorps   %xmm0, %xmm0
        addsd   (%rdi), %xmm0
.LBB0_2:
        ret
...

Note that there are 2 xorps instructions, the one in BB#1 being clearly
redundant
as it's dominated by the first one. Two xorps come from 2 FsFLD0SD
generated by
instruction selection and never eliminated by machine passes. My guess
would be
machine CSE should take care of it.

A variation of this case without indirection shows the same problem, as
well as
not commuting addps, resulting in an extra movps:

$ cat t.c
double f(double p, int n)
{
    double s = 0;
    if (n)
        s += p;
    return s;
}
$ clang -S -O3 t.c -o -
...
f:                                      # @f
        .cfi_startproc
# BB#0:
        xorps   %xmm1, %xmm1
        testl   %edi, %edi
        je      .LBB0_2
# BB#1:
        xorps   %xmm1, %xmm1
        addsd   %xmm1, %xmm0
        movaps  %xmm0, %xmm1
.LBB0_2:
        movaps  %xmm1, %xmm0
        ret
...

Thanks,
Eugene
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20130819/96dd40e6/attachment.html>


More information about the llvm-dev mailing list