<html>
    <head>
      <base href="https://llvm.org/bugs/" />
    </head>
    <body><table border="1" cellspacing="0" cellpadding="8">
        <tr>
          <th>Bug ID</th>
          <td><a class="bz_bug_link 
          bz_status_NEW "
   title="NEW --- - Poor code generation from LLVM."
   href="https://llvm.org/bugs/show_bug.cgi?id=27631">27631</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>Poor code generation from LLVM.
          </td>
        </tr>

        <tr>
          <th>Product</th>
          <td>new-bugs
          </td>
        </tr>

        <tr>
          <th>Version</th>
          <td>trunk
          </td>
        </tr>

        <tr>
          <th>Hardware</th>
          <td>PC
          </td>
        </tr>

        <tr>
          <th>OS</th>
          <td>Linux
          </td>
        </tr>

        <tr>
          <th>Status</th>
          <td>NEW
          </td>
        </tr>

        <tr>
          <th>Severity</th>
          <td>normal
          </td>
        </tr>

        <tr>
          <th>Priority</th>
          <td>P
          </td>
        </tr>

        <tr>
          <th>Component</th>
          <td>new bugs
          </td>
        </tr>

        <tr>
          <th>Assignee</th>
          <td>unassignedbugs@nondot.org
          </td>
        </tr>

        <tr>
          <th>Reporter</th>
          <td>congh@google.com
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>llvm-bugs@lists.llvm.org
          </td>
        </tr>

        <tr>
          <th>Classification</th>
          <td>Unclassified
          </td>
        </tr></table>
      <p>
        <div>
        <pre>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.</pre>
        </div>
      </p>
      <hr>
      <span>You are receiving this mail because:</span>
      
      <ul>
          <li>You are on the CC list for the bug.</li>
      </ul>
    </body>
</html>