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

    <tr>
        <th>Summary</th>
        <td>
            [AArch64] Failure to combine compares using `ccmp` or `fccmp`
        </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>
          Kmeakin
      </td>
    </tr>
</table>

<pre>
    LLVM does not combine compares into `ccmp` or `fccmp` if the comparison is used more than once

For example:
```c
#include <stdbool.h>
#include <stdint.h>

typedef uint64_t u64;
typedef int64_t i64;
typedef double f64;

struct UPair {
    u64 x;
 u64 y;
};

bool ult(struct UPair lhs, struct UPair rhs) {
 return (lhs.x < rhs.x) | ((lhs.x == rhs.x) & (lhs.y < rhs.y));
}
```

LLVM generates:
```asm
ult: // @ult
        cmp     x0, x2
        cset    w8, eq
        cmp     x1, x3
        csel    w8, wzr, w8, hs
 cmp     x0, x2
        csinc   w0, w8, wzr, hs
 ret
```

GCC generates:
```asm
ult:
        cmp     x1, x3
        ccmp    x2, x0, 0, cc
        ccmp    x2, x0, 2, ne
 cset    w0, hi
 ret
```

https://godbolt.org/z/zx67boYY1
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJyUVEtv4zYQ_jXUhYghUe-DDo5d9dAU6KUFciooamRxQ5FaPhI5v35B-p1sNhuDnvHMNw_OR2OoMXwnARqU36N8G1FnR6WbvyagT1xGner3zcPDf3_jXoHBUlnM1NRxCV7PVIPBXFqFUREzNs2oiLHS3hpOJh-wHU_h3CiJucHOQI8npQHbkUqsJAMUb1G8PshWaQwLnWYBKD36UBEfDjvaJOWSCdcDRunG2L5TSqxGlP7xAc6lvYaDtPsZehiw49IW2f8WuyJD6f0teML4T7BeuU4AHq6ggzRWO2bxv_9QrjEqjxjG2LfAyzk6mPtLcrl9U8iPhZ2wiFQ3NcVoENngG5_2vvqqnQbrtMSIVGI0q8Uz4YNWyyFs45ErcIvS7RVOilPm_py5R6T25_rCt-9zffnw19mBBE0tmPdvSc108PgB0zVGpEWkxSiLveNMmf-waQ56if3YC3mDGrBev1Qehe8f5CYhN32XKy65L686qGCM5hj6WXcuma8QX1KPdc4VNNhfEPXnZvMFnr403RFeSEDDDYNg7PPA8FPCiYQTyQEb-W9NNlo7h4nC0-5U3ylhV0rvEGlf_Xcpyk49PiZR36R9ndY0giYpSVykaZ3m0dgUVRJ3SU4GqOpqqIsBBpolkPV5R7o6zyLekJhkcZnESZmTJFtBXiXDUNCyywklpERZDBPlYiXE8-R7R9wYB01dpXkZCdqBMGEDEtJR9gSyR-l6vdZsLDJEPAmIkIkbA_2dmi2f-Cu1XEmP5dtIN77uXed2BmWx4MaaSyfLrQjr9VQv3-KWcuH88lPv16kzXO4-3qeR06J5wym3o-tWTE2ItL7vUd3NWn0DZhFpw7gGkfYw8XNDfgQAAP__Z4epIA">