[llvm-bugs] [Bug 52140] New: [AArch64] compare and branch with long immediate optimisation

via llvm-bugs llvm-bugs at lists.llvm.org
Mon Oct 11 13:18:05 PDT 2021


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

            Bug ID: 52140
           Summary: [AArch64] compare and branch with long immediate
                    optimisation
           Product: libraries
           Version: trunk
          Hardware: PC
                OS: Linux
            Status: NEW
          Keywords: beginner
          Severity: enhancement
          Priority: P
         Component: Backend: AArch64
          Assignee: unassignedbugs at nondot.org
          Reporter: pavel.iliin at arm.com
                CC: arnaud.degrandmaison at arm.com,
                    llvm-bugs at lists.llvm.org, smithp352 at googlemail.com,
                    Ties.Stuij at arm.com

–°omparison with complex immediates followed by branch/cset can be improved.
Currently clang optimise  
int feqi (int a)
{
  return a == 0x111111;
}

long long feql (long long a)
{
  return a == 0x222222;
}

int fnei (int a)
{
  return a != 0x333333;
}

long long fnel (long long a)
{
  return a != 0x444444;
}
into 
feqi(int):                               // @feqi(int)
        mov     w8, #4369
        movk    w8, #17, lsl #16
        cmp     w0, w8
        cset    w0, eq
        ret
feql(long long):                               // @feql(long long)
        mov     w8, #8738
        movk    w8, #34, lsl #16
        cmp     x0, x8
        cset    w0, eq
        ret
fnei(int):                               // @fnei(int)
        mov     w8, #13107
        movk    w8, #51, lsl #16
        cmp     w0, w8
        cset    w0, ne
        ret
fnel(long long):                               // @fnel(long long)
        mov     w8, #17476
        movk    w8, #68, lsl #16
        cmp     x0, x8
        cset    w0, ne
        ret
However gcc performs better emitting sub+subs instead of mov+movk+cmp:
feqi(int):
        sub     w0, w0, #1118208
        subs    w0, w0, #273
        cset    w0, eq
        ret
feql(long long):
        sub     x0, x0, #2236416
        subs    x0, x0, #546
        cset    x0, eq
        ret
fnei(int):
        sub     w0, w0, #3354624
        subs    w0, w0, #819
        cset    w0, ne
        ret
fnel(long long):
        sub     x0, x0, #4472832
        subs    x0, x0, #1092
        cset    x0, ne
        ret

Details of GCC implementation:
https://gcc.gnu.org/legacy-ml/gcc-patches/2015-10/msg00800.html

-- 
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/20211011/771c0979/attachment-0001.html>


More information about the llvm-bugs mailing list