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

    <tr>
        <th>Summary</th>
        <td>
            [clang] X86 Missed optimization for unwrapping simple Optional passed as pointer
        </td>
    </tr>

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

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

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

<pre>
    Given the following code [godbolt](https://godbolt.org/z/KrYd6a5zj):

```cpp
struct O {
 int b;
    bool c;
};

int f(O &o) {
    if (!o.c) return -1;
    return o.b;
}

int f(O *o) {
    if (!o->c) return -1;
    return o->b;
}
```

Compiling with `-O3` both functions should generate the same assembly but actually the second function generates worse code.

```asm
f(O&): # @f(O&)
        xor     eax, eax
        cmp     byte ptr [rdi + 4], 1
        sbb     eax, eax
        or      eax, dword ptr [rdi]
 ret
f(O*):                                # @f(O*)
        cmp byte ptr [rdi + 4], 0
        je      .LBB1_1
        mov     eax, dword ptr [rdi]
        ret
.LBB1_1:
        mov     eax, -1
 ret
```

</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJyMVE1zmzwQ_jXLZceMEFgWBw52_Po9tBkfemlPHQlko4xAjCTiOL--A9iO7SZpNIwW9uvh0a5WeK_3rVIFzFcwX0eiD7V1xfLxB00iaatj8b9-Vi2GWuHOGmMPut1jaSuFMF_tbSWtCTBfA-V1CJ2HdAl0A3RzMsXW7YFuXoFuvrlfFRPz1yeg-eBG1kDOOyPTU3bdpPHB9WXALcJiNWlQtwElpOdPRJTWGiwvKlis397HfQjZAeVbBMos0PwqHSLqHQLlQBMbl4PRqdC7FmfJDcpJa2N5g_QBzPIzmBmk_30BaXB7D-x8StfYD7bptBmKctChRmBktk2BEZQ21Ljr2zJo23r0te1NhXvVKieCGgvqRaNQeK8aaY4o-4CiDL0w5jiZVWnb6pLjEuvxYJ1XYxfE75ZR-GbSjKcClE0lR6ApQkautRfyw3qxbpRKvAB9GMWNvWy6UcpjUNgFN_SgqzQCXWE2duEDJrchXspPU54Qz_bqYF11lXpIOvk7FW44LU-c_rFuKS__ojxQ-owOuXV_UpOMv69Wye87ro19_hqX07pQOmc738oPEs6S-7O4a8moKtIqT3MRqSJhnKQspwse1QXhyZxRLkmW5nLBdqWSSi4yVjHBpRJJpAtKaEoykiSLJEt5zHiSS66IEKRiuySHjKhGaBMb89wMUyXS3veqYAnnPDJCKuPPQ8wVg9NM9nsPGTHaB_8WFnQw47grjWj3MF_jT87wUXuvKrRd0I1-FWO_76zDvj040XXD_fK66YzCbTcYhcFOjCHCY2d1G5SLemeKuymoQ93LuLQN0M3wCycx65x9UmUAuhlpeKCbkcmfAAAA__8hm4XP">