<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 - suboptimal loop codegen?"
   href="https://bugs.llvm.org/show_bug.cgi?id=35016">35016</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>suboptimal loop codegen?
          </td>
        </tr>

        <tr>
          <th>Product</th>
          <td>libraries
          </td>
        </tr>

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

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

        <tr>
          <th>OS</th>
          <td>All
          </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>Backend: X86
          </td>
        </tr>

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

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

        <tr>
          <th>CC</th>
          <td>llvm-bugs@lists.llvm.org
          </td>
        </tr></table>
      <p>
        <div>
        <pre>#include <stdint.h>
uint8_t data[32] = { 1,2,3,4 };
int main(int argc, const char* argv[])
{
        int sum = 0;
        for (int i=0; i < argc; ++i)
#if 0
                sum += ((uint32_t*)data)[2 + i];
#else
                sum += *(uint32_t*)&data[8 + i * 4];
#endif
        return sum;
}

<a href="https://godbolt.org/g/sJTGjz">https://godbolt.org/g/sJTGjz</a>

$ clang -c -Oz
main: # @main
  movsxd rcx, edi
  xor edx, edx
  push 8
  pop rsi
  xor eax, eax
  jmp .LBB0_1
.LBB0_3: # in Loop: Header=BB0_1 Depth=1
  movsxd rsi, esi
  add eax, dword ptr [rsi + data]
  inc rdx
  add esi, 4
.LBB0_1: # =>This Inner Loop Header: Depth=1
  cmp rdx, rcx
  jl .LBB0_3
  ret
data:
  .asciz
"\001\002\003\004\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"

$ g++ -c -Os
main:
  xor edx, edx
  xor eax, eax
.L3:
  cmp edi, edx
  jle .L1
  add eax, DWORD PTR data[8+rdx*4]
  inc rdx
  jmp .L3
.L1:
  ret
data:
  .byte 1
  .byte 2
  .byte 3
  .byte 4
  .zero 28</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>