Skip to content

[AArch64] Sub-optimal folding of a != -a #60818

@SamTebbs33

Description

@SamTebbs33

The C++ code:

bool foo (unsigned a)
{
  return a != -a;
}

on AArch64 LLVM -O2 generates:

foo(unsigned int):                                // @foo(unsigned int)
        lsl     w8, w0, #1
        cmp     w8, #0
        cset    w0, ne
        ret

GCC does the more compact:

foo(unsigned int):
        cmn     w0, w0
        cset    w0, ne
        ret

Godbolt link: https://godbolt.org/z/z8Mnhh6q4

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions