[llvm-bugs] [Bug 50105] New: Suboptimal runtime unrolling

via llvm-bugs llvm-bugs at lists.llvm.org
Fri Apr 23 11:37:09 PDT 2021


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: unassignedbugs at nondot.org
          Reporter: david.bolvansky at gmail.com
                CC: llvm-bugs at 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.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20210423/b3fe417a/attachment.html>


More information about the llvm-bugs mailing list