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

    <tr>
        <th>Summary</th>
        <td>
            Dead Code Elimination Regression (trunk vs 16)
        </td>
    </tr>

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

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

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

<pre>
    https://godbolt.org/z/9Yx9jPEjG

Given the following code:

```C
void foo(void);
static int d = 185, e, f, n;
static int *g, *o = &e, *q = &f;
static int **h = &g;
static int ***i = &h;
static int ****j = &i;
static char m;
void(a)();
static short(b)(short c) {
    if (!(((c) >= 1) && ((c) <= 1))) {
        __builtin_unreachable();
    }
    return 0;
}
static signed char l();
static long k() {
    for (;;) {
 *o = d;
        l();
    }
}
static signed char l() {
 if (e) {
        int s = **h;
        int *t = **i;
        int ***u = &h;
        if (f) {
            for (; d == 8;) foo();
 b(0);
            return 0;
        }
        if (u != *j) {
            for (; d >= 8;)
                ;
            a();
 *q = s;
        }
        *t = 0;
    }
    **h = 0;
    return f;
}
int main() {
    int ****p = &i, ****r = p;
    d || k();
    b(3 >= 0);
    m = d;
    d = m;
    &n == &r;
}

```
clang-trunk -O2 does not eliminate the call to foo:

```asm
main:                                   # @main
# %bb.0:
        pushq   %rax
        movl    d(%rip), %eax
        testl   %eax, %eax
        je      .LBB0_1
# %bb.7:
        movsbl  %al, %eax
        movl    %eax, d(%rip)
        xorl    %eax, %eax
        popq    %rcx
        retq
.LBB0_1:
        movl    f(%rip), %eax
        movq    g(%rip), %rcx
        xorl    %esi, %esi
        movl    d(%rip), %edx
        jmp     .LBB0_2
        .p2align        4, 0x90
.LBB0_6: #   in Loop: Header=BB0_2 Depth=1
        movl    $0, (%rcx)
        movl    %edx, %esi
.LBB0_2:                                # =>This Inner Loop Header: Depth=1
        testl   %esi, %esi
        je      .LBB0_6
# %bb.3:                                #   in Loop: Header=BB0_2 Depth=1
        testl   %eax, %eax
        jne     .LBB0_4
# %bb.5: #   in Loop: Header=BB0_2 Depth=1
        movl    $0, (%rcx)
        jmp     .LBB0_6
        .p2align        4, 0x90
.LBB0_4: # =>This Inner Loop Header: Depth=1
        callq   foo@PLT
        jmp     .LBB0_4
.Lfunc_end0:
```

clang-16.0.6 -O2 eliminates the call to foo:

```asm
main: # @main
# %bb.0:
        movsbl  d(%rip), %eax
        movl    %eax, d(%rip)
        xorl    %eax, %eax
        retq
.Lfunc_end0:
```

Bisects to 6c25c58a4d7caa0337d36bb8c41546f2002130d1 (@fhahn)
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJy0V12PozYU_TXOizWRMd8Pecgkk22llbqq9qVPI4MNOAs2i0067a-vbAcChNnJVi2ySLCP7XPPPb4IohQvBWM7ED6D8Lghva5kt9MV0xWTVHabTNK_dpXWrQL-HuATwKdS0kzWeiu7EuDT3wCf0j_e0vOXl_MngI4A7d39E78wAXXFYCHrWv7JRQlzSZlZZwIDEXLt4J4vklNYSAlwYv4CnAL_2Q0pTTTPIRcaUgj8I_SSEOADZOZWmJtYwwK8L80gwHtppwEcsWvH96GjeGcmwPtqwJTvYwDe8wFW_RAG8P48IPkSmVekg83Y6wRIiBEBJytSqEp2GuAkcwj7CHOAUwjiKxJCCHkB7XzP3k1zGP_Fqmj_4wjgCM5GD8Ooa_M1zfX6mvW81ly89qJjJK9IVrMFU4MD8fH20DHddwKiETGODkEZS1KnRb0edy1FCb-5sTmtQnY2CP_ZtNnomH86I2eu5TYz0g_wm-zitGarehkjqGvyrbPuiFytoicg_h7Itf7ediPOUilWqcy1cufJLJRcZXMncKZJBnCClioN111Wh4FZ7m-semjs6II8P8rwZcLwHmx3W-NGlpGMB199THfMBnrf0tM6MYddZSnuzW6S2BAu1ky8LBjtrWC4sjW2zo60sz0pBPEBxIfhgMwGTRL9Qcq7bDYr58OV2mYePY7E4BiAo-4-vE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