[llvm-bugs] [Bug 26810] New: Redundant movs and an extra spill while using all xmm registers

via llvm-bugs llvm-bugs at lists.llvm.org
Wed Mar 2 04:15:37 PST 2016


https://llvm.org/bugs/show_bug.cgi?id=26810

            Bug ID: 26810
           Summary: Redundant movs and an extra spill while using all xmm
                    registers
           Product: libraries
           Version: trunk
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: normal
          Priority: P
         Component: Register Allocator
          Assignee: unassignedbugs at nondot.org
          Reporter: egor.kochetov at intel.com
                CC: llvm-bugs at lists.llvm.org
    Classification: Unclassified

Created attachment 15974
  --> https://llvm.org/bugs/attachment.cgi?id=15974&action=edit
The reproducer (1 source file, assemblies for clang and GCC, auxiliary
Makefile)

When compiling the loop below, clang produces the binary that runs ~25% slower
than that of GCC.

    constexpr unsigned nIterations = 76800000; //< an arbitrary large number
    __m128d v[8];
    __m128d m1[nIterations];
    __m128d m2[8];

    for (unsigned i = 0; i < nIterations; ++i) {
        const __m128d M = m1 [i];
        __m128d a;

        a = _mm_mul_pd(M, m2[0]);
        v[0] = _mm_add_pd(v[0], a);

        a = _mm_mul_pd(M, m2[1]);
        v[1] = _mm_add_pd(v[1], a);

        a = _mm_mul_pd(M, m2[2]);
        v[2] = _mm_add_pd(v[2], a);

        a = _mm_mul_pd(M, m2[3]);
        v[3] = _mm_add_pd(v[3], a);

        a = _mm_mul_pd(M, m2[4]);
        v[4] = _mm_add_pd(v[4], a);

        a = _mm_mul_pd(M, m2[5]);
        v[5] = _mm_add_pd(v[5], a);

        a = _mm_mul_pd(M, m2[6]);
        v[6] = _mm_add_pd(v[6], a);

        a = _mm_mul_pd(M, m2[7]);
        v[7] = _mm_add_pd(v[7], a);
    }

In particular, there are weird movs around calculating v[6]:

   0x08048c4e <+334>:    movapd %xmm5,%xmm6
   0x08048c52 <+338>:    movapd %xmm4,%xmm5
   0x08048c56 <+342>:    movapd %xmm3,%xmm4
   0x08048c5a <+346>:    movapd %xmm2,%xmm3

Also, throughout the loop clang uses 3 spills for storing values of v[1], v[6]
and v[7], while GCC uses only two spills (for v[0] and v[1]).

Attached is the source file, annotated assembly for clang and an assembly for
GCC for the function 'loop', and the (optional) Makefile.

The source needs to be compiled with '-m32' to limit the number of xmm
registers available. -O2 and -Ofast produce the same results (though the
register names are changing).

-- 
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20160302/5459c4e1/attachment.html>


More information about the llvm-bugs mailing list