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

    <tr>
        <th>Summary</th>
        <td>
            Dead Code Elimination Regression when using __builtin_unreachable (trunk/16 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/Wrs7fr7K3](https://godbolt.org/z/Wrs7fr7K3)

Given the following code:

```
void foo(void);
static int b, c = 36819;
static unsigned short e;
static int *f;
static short a(unsigned short g) { 
    if (g <= 0) __builtin_unreachable(); 
 return -g; 
}
static int d() { 
    if ((b) >= 0) 
     foo(); 
    return b; 
}
int main() {
  int *h = &c;
  e = a(*h);
 &f == &h ^ e >= 57956 && d();
  *h = 0;
}
```
`clang (trunk and 16) -O3`  generates:
```
main:                                   # @main
        cmpb    $1, c(%rip)
        jne     .LBB0_2
 pushq   %rax
        callq   foo@PLT
        addq    $8, %rsp
.LBB0_2:
        movb    $1, c(%rip)
        xorl    %eax, %eax
        retq
```
`clang-15 -O3` can eliminate the call to `foo`:
```
main:                                   # @main
 movb    $1, c(%rip)
        xorl    %eax, %eax
 retq
```
Note: the regression only manifests if the ` if (g <= 0) __builtin_unreachable(); ` is included (see godbolt link)

Bisects to 09cb9fdef983719b509f43fe0e77762005265039 (@RKSimon)

</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJy0VVFv4zYM_jXMC9FClmzFfshD0zR7uMM23AbssZBt2tadIqWWnPb26wcpTtLmusNh2BVFnIgf-fEjZVJ5r3tLtIJiDcVmoaYwuHEVBgoDudaNi9q1X6N1CGHvQdwB3wLf9q6tnQm3buyBb_8Gvv1r9MtuXH4QUGyAlz8O5xWwDbC74-cv-kAWw0DYOWPcs7Y9Nq6lGOo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