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

    <tr>
        <th>Summary</th>
        <td>
            Dead Code Elimination Regression when using __builtin_unreachable (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/9PbnnbhMj

Given the following code:

```C
void foo(void);
static int a = 7, c;
static int *d = &a, *e = &c, *f = &a, *g = &c;
static int **h = &d;
static int(i)(int b) {
    if (!(((b) >= -8) && ((b) <= 7))) {
 __builtin_unreachable();
    }
    return 0;
}
static void j(int **k) {
    int l = *d;
n:
    if (**k) {
        *g = *d;
        i(c);
        if (*d) i(~(l != 0 | **k));
        if (**k)
            ;
        else {
            foo();
 goto n;
        }
    }
}
int main() {
    int *m = f;
 j(&m);
    *h = e;
}

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

```asm
main:                                   # @main
# %bb.0:
        movl    a(%rip), %eax
        testl   %eax, %eax
        je      .LBB0_6
# %bb.1:
        pushq   %rax
        .p2align        4, 0x90
.LBB0_2:                                # =>This Inner Loop Header: Depth=1
        movq    d(%rip), %rcx
        movl    (%rcx), %edx
        movl    %edx, c(%rip)
        cmpl    $0, (%rcx)
        je      .LBB0_5
# %bb.3: #   in Loop: Header=BB0_2 Depth=1
        testl   %eax, %eax
        jne     .LBB0_5
# %bb.4:                                #   in Loop: Header=BB0_2 Depth=1
        callq   foo@PLT
        movl    a(%rip), %eax
        testl   %eax, %eax
        jne     .LBB0_2
.LBB0_5:
        addq    $8, %rsp
.LBB0_6:
        leaq    c(%rip), %rax
        movq    %rax, d(%rip)
        xorl    %eax, %eax
        retq
.Lfunc_end0:
```

clang-15.0.7 -O2 eliminates the call to foo:

```asm
main:                                   # @main
# %bb.0:
        cmpl    $0, a(%rip)
        je      .LBB0_2
# %bb.1:
        movq    d(%rip), %rax
        movl    (%rax), %eax
        movl    %eax, c(%rip)
.LBB0_2:
        leaq    c(%rip), %rax
        movq    %rax, d(%rip)
        xorl    %eax, %eax
        retq
.Lfunc_end0:
```

Bisects to 2754ff883d9ebf5452a10a2b739262b481cb3458 (@jayfoad )
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJzUVkGP4yYU_jXkgibCD9uxDzlkkk1baauuqr2PsHmOyTqQNXg220N_ewV2EifxTLdSD21keQx8fPB97_EGYa3aacQlSZ5JspmJztWmXboaXY1GmnZWGPl9WTt3tISvCGwJbHdGFqZxc9PuCGz_ILDNPxVaF_Wve8I2hK3690_qFTV1NdLKNI35pvSOlkai5xnBSMr6Z923X42StDKGQOY_CeSEP_dD1gmnSqq0o4ISvqELAmtaTo0TWMkAIZAKjyKwwnNHOXRU94jdFTHNSWBVnzFyAkMgU37HkPkJBYGcksWAopRSVVECGYEovP3TY_gHT_qUhQakBFJ6M7we1Ob9MyJ9eSk61TilXzrdoihrUTQY5l598yuTxebaaNF1rabsgriMDlJCEPaDjF73l0cx2tFmcGN1dUNfAjxWPE0Rdnb1fcRyHlUEsvJezA2xT5EA-5NA1lBvLt9QRsliPdr6uxRnzM1o2Nv9FGwsPkrwvz5lb5bZGWeofuC4CcWlcfnwth6E0j3bo-UEVofgV3Vl3gdweniI-jlf8THUd8evb5aN0Lsn13b6C336Dag0aKk2jmKjDkoLh-FEl6JpqDNB9BvHWdhD3xO08Buv3vgR4JTELEzoyXwHJEUxZ6Nl8oN5bQjLRRCdtOoY4uujnaA4XWAOrfO4ofsRsEfC8vnH52f2kt4vGI0XPHa2_toztaP58yOIRu00YXns6dkpH2zsSeEHZIcV-YbwD59rZekvWmNLPxpzpD-jkNh6ig0eXU34Jho74PcjJxxoy9O9UQOqPI18khOo0Bsq6pj2DCsPxx4Ws55kRDrhaHLvKPdSfNOncZDoO84qN8GwCal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