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

    <tr>
        <th>Summary</th>
        <td>
            LLVM fails to merge chain of blocks without side effects
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
      </td>
    </tr>

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

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

<pre>
    Given the following code, which is the difference between `x >= 0 && x < len` vs `(x >= 0) & (x < len)`: https://godbolt.org/z/Tj6Kraj55, LLVM fails to realize in the former case that `x < len` and `0 <= len` implies `0 <= x`, so it can be elided.

Alive2 verifies that transforming the && into a & is valid (https://alive2.llvm.org/ce/z/deAu5r) but LLVM does not seem to notice and thus emits two branches for the && version and one for the & version.

Note that this does not depend on the code lowering to actual branches; LLVM still emits two flag-check operations for && but only one for &, despite both expressions having no side effects.
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJxck01zozgQhn-NuHTFRQTY5sDBk6z3sLN72tq7kBrTGSG51I2d5NdvCZMPz8Wu6g_xvA_IMNMpIHaq-aGa58LMMsbUTfat6KN76_6kCwaQEWGI3scrhRPY6FDpJ7iOZEcgXtqOhgETBovQo1wRA6ht-Qqq-kNVz1CC0lult5ArT-AxqG0JF85DSu-_5pRu8yisxduobvNYdYBR5MyqOih9VPp4iq6PXjYxnZQ-vit9_Pdl-1cyL02T-X7-_O9vGAx5BomQ0Hh6R6CPOGnCBNYwgoxGPmg_2UxwuVbmWiZbyzSdPSHftV6XEE_AEUjAmgA9Anpy6DaqfFbl4fZ78HRBDRdMNOQzludKMoEzTVabyVZRFCSCWVwQw8V4clnKvQGznLjx_jKtFiyuKhwe5iZlnf0sNxcuIkOIAow4ZSchCllcoso4M-BEwiDXCH0ywY7I2dN3qgsmphiWlRjwe_ujdxf5nyirXxmJvwgcnnE5YtnOXxT4eMW0SIhgrMzGf1Ko6sctAQt5_w1z8Ob0YEe0vyCeMRmhGG7MK2_OHoN_-4Rd6k_gkM8kCH2UEfD1nJB52R3NJTOECEwOAYcBrfCmcF3l2qo1BXaP21253-8avS_Gbm-GXdvsUZc91rbc1rbu0Va7nWus7WssqNOl1o_6UetKN3q_cbu2atuyqW2962uHqi5xMuQ_32JBzDN2TVvv68KbHj1_XM_U5aGHfj6xqktPLPy1JiQeu_uvfsJ0QrCjoQBxgN5H-4vhSjLGWe4iFnPy3W_3i2Sc-42Nk9LH_Jj17-Gc4gtaUfq4oLLSx4X2_wAAAP__MYZgbQ">