<table border="1" cellspacing="0" cellpadding="8">
    <tr>
        <th>Issue</th>
        <td>
            <a href=https://github.com/llvm/llvm-project/issues/60818>60818</a>
        </td>
    </tr>

    <tr>
        <th>Summary</th>
        <td>
            [AArch64] Sub-optimal folding of a != -a in LLVM
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            backend:AArch64,
            missed-optimization
      </td>
    </tr>

    <tr>
      <th>Assignees</th>
      <td>
      </td>
    </tr>

    <tr>
      <th>Reporter</th>
      <td>
          SamTebbs33
      </td>
    </tr>
</table>

<pre>
    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

</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJykU0tv2zwQ_DWry8IGtdTzoIMf8HdJ8B0S9E5Ja4sNRboi1aD59YVoG3kgSIGWsJcSZjk7u9Qo7_XJMjeQbyHfJ2oOg5uaBzU-ctt6KZPW9b-ax4FxB7QF2mLnega5AbEHcYuFuP7ia-ucwaNzCFTNNhboUQHV1-xye3lAnDjMk0WFQCnIPa4UyO0ta_8p-SU6i0pN3VBkeHf37R5X_xOe2PKkAvuv1R2de6tL27Aokxv8wwI6AB0QMvE5w7WlyzLexP25Atrhs1gikEzfZ3Xj-U0WkBQfcM8h4vG85ffoxOGLCf2322Hv2GMYGEc3MXZuPKsu_N10Pgq3-Crs-Sb7X_SeXN86E9Bo-7TcxhDCOd5kHPsVXbvpBHR4Wf7VvR2G4kd2OZ70jexrWauEm7Qoi7wo6qxMhkaWgqtOyFymss7SYy9yruUxzduiFuWxSHRDgqSgtEhLQVSuu4K6umPRUllz1RWQCR6VNmtjfo6LgkR7P3NTiCqtEqNaNj76h6hV3RPbHuRms4lfJxAB7YBo1N5zv3LnoEf9ooJ2dsHyfTI1C--qnU8eMmG0D_61UtDBRHPe-PI9PszthUctLjO9tid0x7cmQm2jLZJ5Ms2HQeowzO26cyPQYSlz3VbnyX3nLgAdYnce6BAb_B0AAP__i-IdgA">