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

    <tr>
        <th>Summary</th>
        <td>
            DCE affected by inserting double negations
        </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>
    Sometimes the compiler's ability to detect and eliminate dead code decreases when double negations are inserted. LLVM detects that in the following snippet the if expression is always false and thus it can remove the dead code:

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

void DCEMarker0_();

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

Now two double negations are inserted:

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

void DCEMarker0_();

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

LLVM (14) is now unable to detect and remove the dead code.

This can also be seen via the following Compiler Explorer link: https://godbolt.org/z/5so4o5zor 
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJzlVEtv2zAM_jXyhVhgy3acHHxYk-7U7rJi10G2mFirIgWSnEd__SglTdPXzgNmMAopkh8piWRn5bH9YTcY1AY9hAGht5ut0ugYbzyITmkVjhAsSAzYBxBGAmq1UUYEpE0hyUNGrncoPIHsBzQg7dhpBINrEZQ1hOQQlPHoAsoJ3N39vD8jxqgikC5FX1mt7V6ZNXijtlsMaVetAA9bh94TFihC03tx9LAS2mNKKQyjBxWgFwYcbuwOk-MlP1Z-ZfmS5c_rND9Rf5Z5qUyvRzoIKxc-SGUnAytvP9F21uprfVp3VklYLm7vhXtEl_9ifMb4nJU374xWpIoQcGB8AYnzF44ufg6sOXsBfXT6hHWi4kBJLIloszgZ8ynRyaYorrS0Q8bNgiiGmr8zjgancMmGRP9ikMAv9Dql-H1-1KhlzfJ87gvzfOfX9_Hd7iHs7d_r5b9_vJP4fj1cv9C_-cCp08m9qGIMal1DLz4aEV_79VT5qG0n11APA7nHBqeut9AheKRJs1PizeRYnCcY3B622jpitDKPVEQwhLD1sZr4N6K1pVrQYWLdmqQn-tXeVrZ-sg4ybIvpNK-ns5zzTLalnJdzkQUVNLZ0MSBWK0ocJXTHc53G0G_LOBudbt9EVTSrugmNWRK03j3_fdk6-5sgSVTej-hjPk1R82xoORa1qFZNn895VVddz6XoxQx7WSDvK5lp0aH2LatvGOcG95AgiGf1MlMtp0Pks6IueF1WxaRoZh2fljmfd_2073NW5bgRSk9iHvE6MtemlLpx7UmplQ_-RSloDK8NYgpH-GIMg3Xtw2A3wt-LIzqdpfhtyv8Px1HQEA">