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

            Bug ID: 44412
           Summary: Optimize add X, -1; cmp X,-1; jne to add X, -1; jae
           Product: libraries
           Version: trunk
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: Backend: X86
          Assignee: unassignedb...@nondot.org
          Reporter: david.bolvan...@gmail.com
                CC: craig.top...@gmail.com, llvm-bugs@lists.llvm.org,
                    llvm-...@redking.me.uk, spatel+l...@rotateright.com

void foo (int i);

void bar (int i)
{
  while (i--)
    foo(i);
}

https://godbolt.org/z/RaXjQb

bar(int):                                # @bar(int)
        push    rbx
        test    edi, edi
        je      .LBB0_3
        mov     ebx, edi
        add     ebx, -1
.LBB0_2:                                # =>This Inner Loop Header: Depth=1
        mov     edi, ebx
        call    foo(int)
        add     ebx, -1
        cmp     ebx, -1
        jne     .LBB0_2
.LBB0_3:
        pop     rbx
        ret


Could be:

bar(int):                                # @bar(int)
        push    rbx
        test    edi, edi
        je      .LBB0_3
        mov     ebx, edi
        add     ebx, -1
.LBB0_2:                                # =>This Inner Loop Header: Depth=1
        mov     edi, ebx
        call    foo(int)
        add     ebx, -1
        jae     .LBB0_2
.LBB0_3:
        pop     rbx
        ret

-- 
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