[llvm-bugs] [Bug 52354] New: Missed loop unrolling opportunity

via llvm-bugs llvm-bugs at lists.llvm.org
Fri Oct 29 12:08:22 PDT 2021


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

            Bug ID: 52354
           Summary: Missed loop unrolling opportunity
           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

#define C 3


struct node {
    struct node *next;
    int payload;
};

static int count_nodes(const node* p) {
    int size = 0;
    while (p) {
        p = p->next;
        size++;
    }
    return size;
}

bool has_one_node(const node* p) {
    return count_nodes(p) == 1;
}


bool has_C_nodes(const node* p) {
    return count_nodes(p) == C;
}

has_one_node(node const*):                # @has_one_node(node const*)
        test    rdi, rdi
        je      .LBB0_1
        mov     eax, 1
.LBB0_3:                                # =>This Inner Loop Header: Depth=1
        mov     rdi, qword ptr [rdi]
        add     eax, -1
        test    rdi, rdi
        jne     .LBB0_3
        test    eax, eax
        sete    al
        ret
.LBB0_1:
        xor     eax, eax
        ret
has_C_nodes(node const*):                 # @has_C_nodes(node const*)
        test    rdi, rdi
        je      .LBB1_1
        mov     eax, 3
.LBB1_3:                                # =>This Inner Loop Header: Depth=1
        mov     rdi, qword ptr [rdi]
        add     eax, -1
        test    rdi, rdi
        jne     .LBB1_3
        test    eax, eax
        sete    al
        ret
.LBB1_1:
        xor     eax, eax
        ret

C == 1 case could be also solved with loop deletion pass?


https://godbolt.org/z/do656c17b

-- 
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/20211029/6d3d3f43/attachment.html>


More information about the llvm-bugs mailing list