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

    <tr>
        <th>Summary</th>
        <td>
            DCE sometimes fails with depending if statements
        </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, DCE fails when multiple if statements are used. 

For example, LLVM detects that the following if statement always evaluates to false and thus removes the dead code:

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

void DCEMarker0_();

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

In the next snippet, the if statement is used to set a variable. This variable is then used in another if statement. However, LLVM now fails to detect and eliminate the dead code:

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

void DCEMarker0_();

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

This is actually a regression: 
In LLVM 12 both snippets can be optimised.
In LLVM 13 neither snippet can be optimised.
In LLVM 14 only the top snippet can be optimised.

This can also be seen via the following Compiler Explorer link: https://godbolt.org/z/EzKWjjMn7
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJzdVc1y2jAQfhr7slPG2NiGgw8JkGmn4dROe8zI1oKVyJJHkiHk6bsymAJJJoe2l3qEWGn_dz9Jpeb74ptu0IkGbRDPYTFfwpoJaWFXo4Kmk060EkGswTrmsEHlLDCD0FnkIwiiRRDdHOY7bQCfWUPy3tT9_Y8VcHRYkYarmaMJYa2l1DuhNhcmgckd21vALZMd7ZGCpjikRWCKk2JnwWCjt55DVjgyDpXmGCQ35yEEWXQY1XEdJ0JVsuMIQTK3jgs9qoNk-Q631Fqe8_t5qwX3dVkx84QmegjiaRDPguT2ldCaWN4E9KXsKXOiKlKCID9qAX1UgN7WYYwtcec0oKLtjIZXng20HQiS9PuvrPnv_Sg9N8gXx5BPxFCu81S-qL7ECp8dWCXaFp1Pwu9dtEzYHgO-Uxapg7BlRrBS4gi-18Qcll7QeTD10kJRRzWtzYW1EXzWO9yiOSFH6d0RieTgAKMeCyhFIxSp_UdA8NVUDk2DXFBmDwYtHTyKZQHRRQv_PmTe8zt-Gzp_HMQg_IbffwfpHo80WOU6JuWewGpwQ16t0IqQAyfk99Abx9QpVw_ot1AxBSWCbumeFP7eu5JP6LSIHtNHlQ81JqAVxeEh7HT7kdpZFl6C7kXtxSzSqdoKdnWxznXTCknBLJ9bqQ0RUqgnn2btXGv9SYnvaGw04Vy6kTYbWr3Qb_ny9efj40rlIRbjLIuiNEmyaciLhM-SGQudcBIL_0bY4dEYXgtKnw5ji4pf3-027IwsrlyTeFeOKt3QQsrt8PepNfqRTjothbWdf5Pu0jyKp2FdTJOknGKaY7nmeZROkI1ZXPI8jsdZmpVVKFmJ0hZBehvEscId9CaIDtJFKIo4iuNoGs3GSZpF-Sid5WU0yXiyThnZLINJhA3lMvJx-JqEpuhDKruNJaYU1tnfTEbY2SjE3h3ZZ52rtSm-17phdsX2aGTY-y_6-H8Buc8xIQ">