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

    <tr>
        <th>Summary</th>
        <td>
            [AArch64] Branch on result of multiple comparisons not optimized
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            new issue
      </td>
    </tr>

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

    <tr>
      <th>Reporter</th>
      <td>
          KarlMeakin-Arm
      </td>
    </tr>
</table>

<pre>
    Returning the result of multiple comparisons is optimized to a sequence of `cmp` and `ccmp`. But if the result is branched on instead of returned, the comparison is not optimized ([godbolt](https://godbolt.org/z/TanMeqcn3)):

```c
uint32_t call(uint32_t w0, uint32_t w1, uint32_t w2, uint32_t w3) {
    if (w0 == w1 && w2 == w3) {
        return foo();
    } else {
        return 0;
    }
}
```

Resulting assembly is:
```asm
call: // @call
        cmp     w0, w1
 b.ne    .LBB1_3
        cmp     w2, w3
        b.ne    .LBB1_3
 b       foo
.LBB1_3:
        mov     w0, wzr
 ret
```

but it could be:
```asm
        cmp     w0, w1
 ccmp    w2, w3, #0, eq
        b.eq    foo
        mov     w0, wzr
        ret
```
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJyEVE2T4jgM_TXKRdWUo3yQHHKAobjszmVq71NOIsC7jg2xM9T0r9-yw_dud1MpgiQ_S-_ZPOmc2hvmBoo1FJtETv5gx-YPOervLP9R5m01Dklr-9_ND_bTaJTZoz8wjuwm7dHucJi0V0fN2NnhKEflrHGoHNqjV4N65x69RYmOTxObjgMEStENRygFStPHaA4XuJ48qt1jB-WwHaXpDtyjNaiM8yz7sMsYB-Ie6FsE3PsHkLH-YQSgCor13vat1R6KDVB18P7oIFsBbYG2l9LCjnug7TvQ9i9pvvOpMxlQHZ5sBWID4vpdivnp5nhSxmf002MntQaqbvFZhPnuYfoc0nMYmiEs1_OmiBjUAKrOAiHbQLbBc4pAJVCJZ7rl_gsLn1kg3Fkb6AcKDwtguUHWjj-EidflF-K3H1cFHmX5EQ8tXBLpHA-t_o3K3aW7QqQb5kxUK1vhfAgIuYiZp3m64Rjfs5Ln9FJtF4ZDevHnep3-zD7ARH3PL9X_h7aXatArZq7l6_hX-GB_PQ70Pl7KI_tPpGnD1fbY2Un32PInonxBvLvkb9zoGwJlcRGfXpny6YnTVxzud-BluqRvsr7Oaplwk5ZLqrOK0jw5NMyy7upeSi6LSpRCpLJflkVLOym46vJENSQoE6ko0qXIsnyR1rVsiWrZL5dFL1PIBQ9S6YXWv4bwD0yUcxM3RV3lZaJly9pFgyIyfMZYBKLgV2MTMG_ttHeQC62cd_ddvPI6OttqNXaHModig-voJcFJvnCwJ_9IplE3L4ah_GFqF50dgLah5eX1dhzt39x5oG0c1AFtI5F_AwAA__9WfoWz">