<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/93005>93005</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
Missed optimization for devirtualisation
</td>
</tr>
<tr>
<th>Labels</th>
<td>
new issue
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
Ignition
</td>
</tr>
</table>
<pre>
Devirtualisation ATM does not take advantage of any local type provenance that it could use.
```cpp
struct B {
virtual void method() const = 0;
};
struct D : B {
void method() const FINAL_OVERRIDE;
};
auto get_D() -> D const &;
int main() {
// statically knows its `D`, or a subclass of `D`
auto const & d = get_D();
// For `D` if `method` is final, we can use a static call
d.method();
// missing optimization, no type provenance
B const & b = get_D();
// statically takes this as a B
// hence remains a virtual call
b.method();
}
```
clang-18.1.0
https://godbolt.org/z/1MsTjjhGG
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJyMVN1uszgQfRpzMwoyJiFwwUWylE-VtrvSp2pvK4MdcOvYETOkSp9-ZUKbn26llZCB8fjMmeOjkYimc1qXbLVlqyqSI_V-KB87Z8h4FzVencpKH81Ao7QGZYjC5vkJlNcIzhOQfNMg1VE6kp0GvwPpTmB9Ky3Q6aDhMPijdtK1GqiXBIag9aNVMKKOGa8Y38xrxs9PezicI0jD2BJsga235wjMVODojYK9pt4rJnImCmi9QwKWVsBZOqezdfX1PYNVwNLNDSTAj2j141-bP1_-_ufh9-_H6uE_Yc-rHMlDp-mlms8vWPoA1Scpkd3lG0ewl8bN2TdkmKiZqAFJkmmltSd4c_4dwRACy3gVRBJ_gB9AAo5NayVi0H3egwvSxOqLAqhJnSuWLN3Ct7q1H76gzIQ6CxP-EXbGSRvqv2topQu3GHhMZCHQvQCq-FrSOwWuKu4NonEd-AOZvfmYTBYqOH_voMvR7VVfzf_q60rP4FkE6g2CRJDwXfxeB78OOtxRyPi03VWDzQ_dras7O1933VrpukWSx0l8E--JDsjSzbl851XjLcV-6JioP5iokyd8fn3tf_2KVJmqIi1kpMtknWRplvGiiPpSLUVeSMGLJBMi3ykhRCrXidDLLBMtzyNTCi6WfCUEz0WSFnEi-KpYFWmbZTLPV0u25KFfG1t73IfakUEcdVmknK8iKxttcRoUQjj9DtMmEyLMjaEMZxbN2CFbcmuQ8IJChqwunwyiVjd3DDs_gLqfLtE42PJOD0P92MSt3zNRB9z5tTgM_lW3xEQ9sUEm6ontvwEAAP__36tqIA">