[llvm-bugs] [Bug 30577] New: [AArch64] Missed cbnz opportunity when compare value is known positive

via llvm-bugs llvm-bugs at lists.llvm.org
Fri Sep 30 08:23:12 PDT 2016


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

            Bug ID: 30577
           Summary: [AArch64] Missed cbnz opportunity when compare value
                    is known positive
           Product: libraries
           Version: trunk
          Hardware: PC
                OS: Windows NT
            Status: NEW
          Severity: normal
          Priority: P
         Component: Backend: AArch64
          Assignee: unassignedbugs at nondot.org
          Reporter: mcrosier at codeaurora.org
                CC: llvm-bugs at lists.llvm.org
    Classification: Unclassified

Given the following test case:

 void foo(int a, char *ptr) {
   while (a > 0) {
     *ptr++ = a & 0xff;
     a >>= 8;
   }
 }

GCC generates:
foo:
        cmp     w0, 0
        ble     .L1
        .p2align 2
.L5:
        strb    w0, [x1], 1
        asr     w0, w0, 8
        cbnz    w0, .L5
.L1:
        ret

Clang generates:
foo:                                    // @foo
// BB#0:                                // %entry
        cmp             w0, #1          // =1
        b.lt    .LBB0_2
.LBB0_1:                                // %while.body
                                        // =>This Inner Loop Header: Depth=1
        strb    w0, [x1], #1
        asr     w0, w0, #8
        cmp             w0, #0          // =0
        b.gt    .LBB0_1
.LBB0_2:                                // %while.end
        ret


In Clang's case, we should be able to replace the cmp + b.gt with a cbnz
because we know a will always be greater than zero if we execute the loop
(LBB0_1).

-- 
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/20160930/e5c223f4/attachment-0001.html>


More information about the llvm-bugs mailing list