[LLVMbugs] [Bug 23084] New: [AArch64] Failure to canonicalize compare results in reloading of constants

bugzilla-daemon at llvm.org bugzilla-daemon at llvm.org
Tue Mar 31 06:45:27 PDT 2015


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

            Bug ID: 23084
           Summary: [AArch64] Failure to canonicalize compare results in
                    reloading of constants
           Product: libraries
           Version: trunk
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: normal
          Priority: P
         Component: Backend: AArch64
          Assignee: unassignedbugs at nondot.org
          Reporter: james.greenhalgh at arm.com
                CC: james.molloy at arm.com, llvmbugs at cs.uiuc.edu
    Classification: Unclassified

Created attachment 14123
  --> https://llvm.org/bugs/attachment.cgi?id=14123&action=edit
Testcase

In the attached testcase, after tail-call inlining, two comparisons of x
against 20,000 are generated. The compiler does not pick a canonical way to do
this comparison, and ends up checking (x > 20000) for the first comparison and
(x < 20001) for the second. This results in a useless load of the constant
20001.

clang --target aarch64 canonicalize-compare.c -O2 -S

foo:
    movz    w8, #0x4e20        /* !!!!  */
    cmp     w0, w8
    b.gt    .LBB0_3
    movz    w8, #0x4e21        /* !!!!  */
.LBB0_2:
    add    w9, w0, w0, lsl #6
    neg     w0, w9
    cmp     w0, w8
    b.lt    .LBB0_2      /* Could be B.LE and reuse the first constant  */
.LBB0_3:
    ret

GCC generates:

foo:
    mov    w1, 20000
    cmp    w0, w1
    bgt    .L2
.L3:
    add    w0, w0, w0, lsl 6
    neg    w0, w0
    cmp    w0, w1
    ble    .L3
.L2:
    ret

Which looks neater.

-- 
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/20150331/c7cbb9e4/attachment.html>


More information about the llvm-bugs mailing list