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

            Bug ID: 50105
           Summary: Suboptimal runtime unrolling
           Product: libraries
           Version: trunk
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: Loop Optimizer
          Assignee: unassignedb...@nondot.org
          Reporter: david.bolvan...@gmail.com
                CC: llvm-bugs@lists.llvm.org

int p(int x, int *arr) {
    int s = 0;
    for (int i = 0; i < x && i < 3; ++i) {
        s += arr[i];
    }
    return s;
}

LLVM
p(int, int*): # @p(int, int*)
  test edi, edi
  jle .LBB0_1
  add edi, -1
  cmp edi, 2
  mov ecx, 2
  cmovb ecx, edi
  mov eax, dword ptr [rsi]
  test ecx, ecx
  je .LBB0_5
  add eax, dword ptr [rsi + 4]
  cmp ecx, 1
  je .LBB0_5
  add eax, dword ptr [rsi + 8]
.LBB0_5:
  ret
.LBB0_1:
  xor eax, eax
  ret

GCC
p(int, int*):
  xor eax, eax
  test edi, edi
  jle .L1
  mov eax, DWORD PTR [rsi]
  cmp edi, 1
  jle .L1
  add eax, DWORD PTR [rsi+4]
  cmp edi, 2
  jle .L1
  add eax, DWORD PTR [rsi+8]
.L1:
  ret

We have here some useless code which can be eliminated and then LLVM can match
GCC.


Also with for (int i = 0; i < x && i < 16; ++i) LLVM produces a lot of
(vectorized) asm, GCC just unrolls 16x.

https://godbolt.org/z/sc59Gv3a9

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

Reply via email to