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

    <tr>
        <th>Summary</th>
        <td>
            DCE depends on whether if or else is used
        </td>
    </tr>

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

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

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

<pre>
    In some cases, the compiler's ability to eliminate dead code depends on whether the if expression is left as it is or negated and the body moved to the else block.

LLVM (tested on 14.0.0) detects that the if expressions in the following code snippet evaluate to false and thus removes the dead code:

```c
#include <stdio.h>
#include <stdbool.h>

void DCEMarker0_();

void f(bool r, bool s, bool c) {
    if (!c == !s) {
        if ((c && !s && r) || (s && 0)) {
            DCEMarker0_();
        }
    }
}
```

In the following snippet, the inner if has been negated and the body has been moved to the else block. However, LLVM cannot eliminate the dead code anymore:

```c
#include <stdio.h>
#include <stdbool.h>

void DCEMarker0_();

void f(bool r, bool s, bool c) {
    if (!c == !s) {
        if (!((c && !s && r) || (s && 0))) {}
        else {
            DCEMarker0_();
        }
    }
}
```

This can also be seen via the following Compiler Explorer link: https://godbolt.org/z/xTrW9K5rf
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJzlVEtzmzAQ_jXioikjhAFz4JDYyTTT5pZpjx0Bi1EjS4wk7Li_vis5dtw8Lj30UkbG2vfrY1vTH5o7TZ3ZAu2EA0f4ivoRCbOdpAJLeOWoaKWS_kC9oaDkVmrhgfYgelTrw20C3TtqNN2PgNY2upADhafJgnMSJdJRBYOnwlHpA2Us1bBBTz0Vuo8WLaZDt2aHLAwVOKAcspXpHlPC1oRdHd9fv367p4QvPbhgj-6zRcpSRniN2XjovENz4d_mgdF15A5GKbOXenOswWk5TeAp7ISaQ3mYwCBC9GNys6MWQmouWp-LJ_nVZWKkZMfTPdM8l7pTM0Yg-cr5Xpp0JPnNB9LWGHUpj--dkT1dr27uhX0Ey35g3Vgnya_fKA0oCi6oDWOMN3e-daE5pHq2ovhgY6KvrMPwazxIZu6N2qXqElV5iSeqnu72aLPCE9TO_DCPd92F5-OKThqkWr8wzsTL5dTryz7cvZ7u82BPuJZaIzyxnBGB2ALo90F4ln6ERvrZ7GEHsdERjZ3Q2viL7-MPmKD3w9bY_w0u2d-D5uT3EgPhiTP4h4B6GHFX4XApLgODmKAuwGInxSucrZ4XJr15mhRO2lIl9SPOm47eTy4Mnt_i2Rgcm_KpsRukfuHv6cF-r78UdkigycqSMV5XGUv6Ju_rvBaJl15Bg9W9t2ix07hIY1Mwz9lBn8xWNa9iSlxgbYo7HQmldqe_T5M1P3FZIimdm8P2vy0qxlkyNnVdVIuyWJaLYlhWgyj7rFuWkGVLtihqEIkSLYZtSHFNONewp9EF3kmxTmTDGedsyWpW8WxRp2W2aKHrOuirturygiwYbIVUacgjNCOxTUypnTcOhUo6716EApf3RgPEcOhfzH40tnkYzVa4e3EAq5IYv4n5_wZMYfoz">