[llvm-bugs] [Bug 44412] New: Optimize add X, -1; cmp X,-1; jne to add X, -1; jae

via llvm-bugs llvm-bugs at lists.llvm.org
Mon Dec 30 09:57:31 PST 2019


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: unassignedbugs at nondot.org
          Reporter: david.bolvansky at gmail.com
                CC: craig.topper at gmail.com, llvm-bugs at lists.llvm.org,
                    llvm-dev at redking.me.uk, spatel+llvm at 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.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20191230/b0c36127/attachment.html>


More information about the llvm-bugs mailing list