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

            Bug ID: 35016
           Summary: suboptimal loop codegen?
           Product: libraries
           Version: trunk
          Hardware: PC
                OS: All
            Status: NEW
          Severity: normal
          Priority: P
         Component: Backend: X86
          Assignee: unassignedb...@nondot.org
          Reporter: tras...@gmail.com
                CC: llvm-bugs@lists.llvm.org

#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;
}

https://godbolt.org/g/sJTGjz

$ 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

-- 
You are receiving this mail because:
You are on the CC list for the bug.
_______________________________________________
llvm-bugs mailing list
llvm-bugs@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to