[llvm-bugs] [Bug 27631] New: Poor code generation from LLVM.

via llvm-bugs llvm-bugs at lists.llvm.org
Tue May 3 16:54:14 PDT 2016


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

            Bug ID: 27631
           Summary: Poor code generation from LLVM.
           Product: new-bugs
           Version: trunk
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: normal
          Priority: P
         Component: new bugs
          Assignee: unassignedbugs at nondot.org
          Reporter: congh at google.com
                CC: llvm-bugs at lists.llvm.org
    Classification: Unclassified

LLVM generates very poor code for the following source code:

struct A {
  int t[16] = {0};
};

const int N = 10000;
A a[N];
void foo() {
  for (int i = 0; i < N; ++i) {
    a[i] = A();
    a[i].t[0] = a[i].t[1] = a[i].t[2] = a[i].t[3] =
        a[i].t[4] = a[i].t[5] = a[i].t[6] = a[i].t[7] = i;
  }
}

When disabling loop unrolling, the assembly of the loop body generated on x86
is shown below (from clang++ t.C -O2 -fno-unroll-loops -S):

        xorps    %xmm0, %xmm0
LOOP:
    movaps    %xmm0, -24(%rsp)
    movaps    %xmm0, -40(%rsp)
    movaps    %xmm0, -56(%rsp)
    movaps    %xmm0, -72(%rsp)
    movaps    -72(%rsp), %xmm1
    movaps    -56(%rsp), %xmm2
    movaps    -40(%rsp), %xmm3
    movaps    -24(%rsp), %xmm4
    movups    %xmm4, 48(%rax)
    movups    %xmm3, 32(%rax)
    movups    %xmm2, 16(%rax)
    movups    %xmm1, (%rax)
    movd    %ecx, %xmm1
    pshufd    $0, %xmm1, %xmm1        # xmm1 = xmm1[0,0,0,0]
    movdqa    %xmm1, 16(%rax)
    movdqa    %xmm1, (%rax)
    incq    %rcx
    addq    $64, %rax
    cmpq    $10000, %rcx            # imm = 0x2710
    jne    .LBB0_1

Note that how the values in %xmm0 (all zeros) are copied to the stack multiple
times, which are then copied back to other SIMD registers, which are copied to
memory. Furthermore, the first 32 bytes of each object are written twice.

-- 
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/20160503/c8046177/attachment-0001.html>


More information about the llvm-bugs mailing list