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

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

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

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

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

<pre>
    https://godbolt.org/z/n3eMoP5hq

Given the following code:

```C
void foo(void);
static int a = 1;
static int *c, *d, *g = &a, *h;
static int **e = &c, **i = &c;
static int ***f = &e, ***j = &e;
static char(k)(int b) {
    if (!(((b) >= 1) && ((b) <= 6))) {
        __builtin_unreachable();
 }
    return 0;
}
int main() {
    {
        int l;
 *i = &a;
        if (*c)
            ;
        else {
 c = 0;
            a = 2;
        }
        d = &l;
 k(a);
        *g = 0;
    }
    h = **f;
    if (h == 0 || h == &a)
        ;
    else
        foo();
    ;
    int ***m = j;
    &m == 0;
    k(6);
}

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

```asm
main: # @main
# %bb.0:
        pushq   %rax
        leaq    a(%rip), %rax
        xorl    %ecx, %ecx
        cmpl    $0, a(%rip)
        cmovneq %rax, %rcx
        movq    %rcx, c(%rip)
        leaq    4(%rsp), %rdx
        movq    %rdx, d(%rip)
        movl    $0, a(%rip)
        movq    %rcx, h(%rip)
        testq   %rcx, %rcx
        je      .LBB0_3
# %bb.1:
        cmpq    %rax, %rcx
        je      .LBB0_3
# %bb.2:
        callq   foo@PLT
.LBB0_3:
        xorl    %eax, %eax
        popq    %rcx
        retq
.Lfunc_end0:
```

clang-15.0.7 -O2 eliminates the call to foo:

```asm
main: # @main
# %bb.0:
        leaq    a(%rip), %rax
        xorl    %ecx, %ecx
        cmpl    $0, a(%rip)
        cmovneq %rax, %rcx
        movq    %rcx, c(%rip)
        leaq    -4(%rsp), %rax
        movq    %rax, d(%rip)
        movl    $0, a(%rip)
        movq    %rcx, h(%rip)
        xorl    %eax, %eax
        retq
.Lfunc_end0:
```

Bisects to 6b9317f52a66318a57a216da2e5e4890ef2aef7b (@clubby789 )
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJzUVlGPozYQ_jXOi7WRGcDAQx6y2Utfruqp6vvKhiF41-AcNrm9_vrKJiSQzd5JlVrpUBRgvm--GQ8zYGGtOnSIG5I-kvRpJQbXmH7jGnQNmsr0K2mq75vGuaMl8ZbAnsD-YCpptFub_kBg_zeBfRfj7-ZL2nwl7Imw7fj_mzphR12DtDZam2-qO9DSVOh1ZjTC2fjbjfcnoypaG0Mg95cEChI_jpB1wqmSqs5RQUn8RKN7EIFtSWDnz9X5fAhsAlycDc0HjgS2OHEnEQJbdbV96EdgW080vLoS2L5czTfeZSN6AvmrXyTkXksSKCjJzjRKKVU1JZATiMK__42c-NNYAX8NnACnC3TnUR6Ei3ea_nh-loPSTnXPQ9ejKBshNQaJa8EpyZ6uXj26oe8ou8AX1GfeCtWN7stY7wJ7sp6FmJVXXM0T-bx6_0iLJRTEb_moLc5ClkGZvaP5Y2wheIct1uyPakpvlvUrgVwsSjV5T922DLoQbc6CoWcWtHG5AQ8alGQ7ku3oxTL28E0lFhK-Akt4HKbbZJdx523chvRelmzg7SWrBeIrwefil6XezPd4W2rRHR5cP3Sv9OEPoJVBSzvjKGrVqk44DK-MUmhNnQm5f_C-ELYdLaHzYt9JMSUJC7cj1RsglXLNZiLFcbD-TVUQSHvxdjFrFN4qQq3SXh3D5Pg5XtDeTK9HZyzfzri_mvCyPY54wjy6lLuSzKnDWRLnODOd1pwmfIxT3lU6Z52cQTvPurqrVgW16q5aa04_T_5dZs1dmkPrlrybFb4gYcX68-Mje45vH1g0f2Ble_xhqX4kBAshobVX8l2VsC-f_xqRyXXGnD3lS0icdcHRHGdrm6w9uq-TZD105TN21az1lpMwn4coXbN1FgbiMgf2Px-EX7rjH-62vLgrJ_6nl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