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

    <tr>
        <th>Summary</th>
        <td>
            Optimization taken with likely(!x), but not with unlikely(x)
        </td>
    </tr>

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

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

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

<pre>
    Default case, no optimization taken (correct behavior): https://godbolt.org/z/51zfer5Mj

Case with `likely(!x)`, optimization taken: https://godbolt.org/z/c879rKPdq

Case with `unlikely(x)`, optimization NOT taken (even though they should be semantically the same): https://godbolt.org/z/xTfs7Prza

Same also applies in C++ if you replace the second `if + unreachable` with `[[assume]]`.
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJyMks1O6z4QxZ9mshlROXbTJIssaKts_vpfkC4v4I9pY3DiXH8U2qe_SkFwBUJCiuLFjOecn-fIGO1xIuqg2kK1L2ROgw-dUooLepl9JFMob87dng4yu4RaRgK-w8mjn5Md7UUm6ydM8okmBN5oHwLphIoGebI-AG9B3OKQ0hxB3ALvgfdHb5R3aeXDEXh_Ad5X5eVAofr_Edge2O3rfycj4bNNA8KGOftE7gy8AV6-LFM3bDHy1cVP5HRTt-G_e_PnW7k8vQt-p_br7uGDm040YRp8Pg6YBjpjHHx2BhVhpFFOyWrp3HmpYZQj_fBdXh4Osb4PF_mv0d9yJJQuepTz7CxFtBPugG-Bb9Ee8OwzBpqd1PSqR9pPZqGyB1x68hRI6kEqR7Bh78zXEGxljHkkqPbLt2GrwnTCtKKVBXVlLcp1XYtKFENXq7Ykbtalqo0mxhRpIUyzUaqu68awwnac8XVZloJVVVWJFaubtdCSOEmlGqNhzWiU1q2cO40LdWFjzNSVZdW2beGkIhev2eR8ome8VoHzJaqhWy7dqHyMsGbOxhQ_xiSbHHV3XxN6Rf0SJb5DlRNOPr02fFp-kYPrPm3KpiGrlfYj8H6RfTtu5uAfSSfg_dVsBN6_0Zw6_jcAAP__cF4XLg">