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

    <tr>
        <th>Summary</th>
        <td>
            Missing optimization: Devirtualize functions if there's only one actual instantiated child class
        </td>
    </tr>

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

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

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

<pre>
    ```c++
struct IUnknown {
    virtual void Release() = 0;
};

namespace {
    struct base_object : IUnknown {
        void Release() override
        {
            delete this;
        }
        virtual ~base_object() {}
    };

 class the_impl : public base_object {};
}

IUnknown* create_it() { return new the_impl(); }
```

Expected: Release() should see that the_impl is the only child class that's used, and devirtualize its dtor (then inline it and just call operator delete). GCC performs this optimization.

Actual: It calls into the vtable.

https://godbolt.org/z/vbYY4ezqE
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJx0U89uozwQfxpzGTUCQ0I4cEia5tN32MtKe-ipMvYkuOvYrGdItznss68gaUJaLbIAMeP5_cOKyO49Yi3mazHfJKrnNsR65bSKIWmCea_FIj0vLeR6WOlGpCvi2GuG_3_4nz68eRDlpQAAcLSRe-XgGKyB7-hQEQq5FLICkW8gFfmlWZSb2_t49-qA1CmN9xMvcI0ifAnNK2oGka_-AT9S-AodjhijNXjf-GXncBl0yAjcWrryu23YfIK6qP0zYfehtlzftX_VC9opIuAWX-yhc6Oqrm-c1fdiz4Omvk2GfNgg5Ap0RMX4YicUICL30YPHtyvQuSry9U3PNejp6KffHWpGM_C6t5Pa0DsDhINPim8S7CgHgnfvoFvrzFWjYiFLgp7QCPkIyhsweLHPnhAsExgOEYRccoserHfWD9_H3teeGLRyDkKHUQ2N56CErGbw3-MjdBh3IR5oTA5Cx_ZgT4pt8LOpqJUeEMcf6DyQwHoOI-0jq8bhXXvL3JHIV0Juhdzug2mC41mIeyG3JyG3x-b5ucDTr6fE1Lmp8kolWGdlVlZLmecyaet0N1-mZrFY5FmZmaxQqNOFwt1uUSyN0svE1jKVRbrI0jTLlnM5K5pcl1VRFDrFYt7sRJHiQVk3c-54GLATS9RjXRWVLBKnGnQ0HmIph5jHopByONOxHvY8NP2eRJE6S0y3KWzZYf3NElm_v3NssGczTWfXez0UCOxusCrimOaYc_AIanQVrCdWnq1iNNP8kz66-pOVltu-melwEHI7ULo8HroYzqdoOwohIbdnocda_g0AAP__phtung">