https://gcc.gnu.org/bugzilla/show_bug.cgi?id=115410
Bug ID: 115410 Summary: Missing optimization: typeid(*a)==typeid(*b) could be optimized to a->_vptr==b->_vptr Product: gcc Version: 15.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: user202729 at protonmail dot com Target Milestone: --- As in the title. I think if both `*a` and `*b` are objects of type with a virtual pointer then `typeid(*a)==typeid(*b)` could be optimized to if(!a) throw bad_typeid; if(!b) throw bad_typeid; return a->_vptr==b->_vptr; Godbolt: https://godbolt.org/z/MjY67Pc4b Although I think this optimization should be done at the level of the C++ front end (`cp_build_binary_op`?) because once the expression is down to gimple level then it becomes something like type_info::operator==(a->_vptr[-1], b->vptr[-1]) and it seems not clean to hard code the constant `-1` (it is currently hard coded only in `get_tinfo_decl_dynamic` function).