<html>
    <head>
      <base href="https://bugs.llvm.org/">
    </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 - LLVM misses loadpre opportunities"
   href="https://bugs.llvm.org/show_bug.cgi?id=33234">33234</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>LLVM misses loadpre opportunities
          </td>
        </tr>

        <tr>
          <th>Product</th>
          <td>clang
          </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>enhancement
          </td>
        </tr>

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

        <tr>
          <th>Component</th>
          <td>LLVM Codegen
          </td>
        </tr>

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

        <tr>
          <th>Reporter</th>
          <td>danielcdh@gmail.com
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>llvm-bugs@lists.llvm.org
          </td>
        </tr></table>
      <p>
        <div>
        <pre>#cat t.cc
void foo(int *p, int t, int *a, int *b, int *c) {
  for (int i = 0; i < t; i++) {
    if (a[i]) {
      *p += b[i];
    } else {
      *p *= c[i];
    }
  }
}
#clang -O2 -S t.cc -fno-unroll-loops
        testl   %esi, %esi
        jle     .LBB0_6
# BB#1:
        movl    %esi, %eax
        .p2align        4, 0x90
.LBB0_2:                                # =>This Inner Loop Header: Depth=1
        cmpl    $0, (%rdx)
        je      .LBB0_4
# BB#3:                                 #   in Loop: Header=BB0_2 Depth=1
        movl    (%rdi), %esi
        addl    (%rcx), %esi
        jmp     .LBB0_5
        .p2align        4, 0x90
.LBB0_4:                                #   in Loop: Header=BB0_2 Depth=1
        movl    (%rdi), %esi
        imull   (%r8), %esi
.LBB0_5:                                #   in Loop: Header=BB0_2 Depth=1
        movl    %esi, (%rdi)
        addq    $4, %rdx
        addq    $4, %rcx
        addq    $4, %r8
        decq    %rax
        jne     .LBB0_2
.LBB0_6:
        retq

#gcc -O2 -S t.cc -fno-unroll-loops
        testl   %esi, %esi
        jle     .L1
        movl    (%rdi), %r9d
        xorl    %eax, %eax
        jmp     .L5
        .p2align 4,,10
        .p2align 3
.L9:
        addl    (%rcx,%rax,4), %r9d
        addq    $1, %rax
        movl    %r9d, (%rdi)
        cmpl    %eax, %esi
        jle     .L1
.L5:
        movl    (%rdx,%rax,4), %r10d
        testl   %r10d, %r10d
        jne     .L9
        imull   (%r8,%rax,4), %r9d
        addq    $1, %rax
        movl    %r9d, (%rdi)
        cmpl    %eax, %esi
        jg      .L5
.L1:
        rep
        ret

For the gcc version, there are only 2 loads + 1 store each iteration. For llvm
version, there are 3 loads + 1 store each iteration.

The problem is that llvm failed to move the load of *p outside of the loop.</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>