public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/115410] New: Missing optimization: typeid(*a)==typeid(*b) could be optimized to a->_vptr==b->_vptr
@ 2024-06-10  6:06 user202729 at protonmail dot com
  2024-06-10  6:09 ` [Bug c++/115410] " pinskia at gcc dot gnu.org
                   ` (8 more replies)
  0 siblings, 9 replies; 10+ messages in thread
From: user202729 at protonmail dot com @ 2024-06-10  6:06 UTC (permalink / raw)
  To: gcc-bugs

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).

^ permalink raw reply	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2024-06-10  9:20 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-06-10  6:06 [Bug c++/115410] New: Missing optimization: typeid(*a)==typeid(*b) could be optimized to a->_vptr==b->_vptr user202729 at protonmail dot com
2024-06-10  6:09 ` [Bug c++/115410] " pinskia at gcc dot gnu.org
2024-06-10  6:11 ` user202729 at protonmail dot com
2024-06-10  6:16 ` pinskia at gcc dot gnu.org
2024-06-10  6:20 ` pinskia at gcc dot gnu.org
2024-06-10  6:29 ` user202729 at protonmail dot com
2024-06-10  6:33 ` pinskia at gcc dot gnu.org
2024-06-10  6:51 ` user202729 at protonmail dot com
2024-06-10  9:18 ` redi at gcc dot gnu.org
2024-06-10  9:20 ` user202729 at protonmail dot com

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).