[llvm-bugs] [Bug 47247] New: Unroll small loops implied by	llvm.assume
    via llvm-bugs 
    llvm-bugs at lists.llvm.org
       
    Thu Aug 20 02:09:10 PDT 2020
    
    
  
https://bugs.llvm.org/show_bug.cgi?id=47247
            Bug ID: 47247
           Summary: Unroll small loops implied by llvm.assume
           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
#include <cstddef>
unsigned sum_small(unsigned data[], size_t count) {
    if ( count > 4)   {
    __builtin_unreachable();
    }
    unsigned sum = 0;
    for (size_t i = 0; i < count; ++i) {
        sum += data[i];
    }
    return sum;
}
LLVM generates loop:
sum_small(unsigned int*, unsigned long):                        #
@sum_small(unsigned int*, unsigned long)
        test    rsi, rsi
        je      .LBB0_1
        xor     ecx, ecx
        xor     eax, eax
.LBB0_4:                                # =>This Inner Loop Header: Depth=1
        add     eax, dword ptr [rdi + 4*rcx]
        add     rcx, 1
        cmp     rsi, rcx
        jne     .LBB0_4
        ret
.LBB0_1:
        xor     eax, eax
        ret
GCC unrolls loop:
sum_small(unsigned int*, unsigned long):
        test    rsi, rsi
        je      .L4
        mov     eax, DWORD PTR [rdi]
        cmp     rsi, 1
        je      .L1
        add     eax, DWORD PTR [rdi+4]
        cmp     rsi, 2
        je      .L1
        add     eax, DWORD PTR [rdi+8]
        cmp     rsi, 3
        je      .L1
        add     eax, DWORD PTR [rdi+12]
        ret
.L4:
        xor     eax, eax
.L1:
        ret
https://godbolt.org/z/Przjfo
-- 
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/20200820/02ceceb5/attachment.html>
    
    
More information about the llvm-bugs
mailing list