public inbox for gcc-bugs@sourceware.org help / color / mirror / Atom feed
From: "user202729 at protonmail dot com" <gcc-bugzilla@gcc.gnu.org> To: gcc-bugs@gcc.gnu.org Subject: [Bug ipa/110057] Missed devirtualization opportunities Date: Mon, 27 May 2024 09:29:27 +0000 [thread overview] Message-ID: <bug-110057-4-veCPyFXMrH@http.gcc.gnu.org/bugzilla/> (raw) In-Reply-To: <bug-110057-4@http.gcc.gnu.org/bugzilla/> https://gcc.gnu.org/bugzilla/show_bug.cgi?id=110057 user202729 <user202729 at protonmail dot com> changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |user202729 at protonmail dot com --- Comment #11 from user202729 <user202729 at protonmail dot com> --- One way this could be implemented is the following. * implement built-in `__builtin_vptr(object)` and `__builtin_vptr(Type)` that obtains the pointer to the vtable (or NULL if the object type has no virtual method) * in the implementation `vector.pop_back()` etc., add the the following: if (__builtin_vptr(this->_M_impl._M_finish) != __builtin_vptr(_Tp)) __builtin_unreachable(); * the optimizer should be able to figure out the rest. What do you think about this approach? -------- Alternatively, we can also use the existing `typeid()` --- although the optimizer is not smart enough to optimize the following code yet. ``` #include<cstdio> #include<typeinfo> struct Base{ Base() {} virtual void f(){ std::printf("Base\n"); } }; struct Derived final: Base{ Derived() {} virtual void f(){ std::printf("Derived\n"); } }; void f(Base* b){ if(!b or typeid(*b)!=typeid(Base)) __builtin_unreachable(); b->f(); } ```
prev parent reply other threads:[~2024-05-27 9:29 UTC|newest] Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top 2023-05-31 10:08 [Bug tree-optimization/110057] New: " yongxiangng at gmail dot com 2023-06-01 0:15 ` [Bug ipa/110057] " pinskia at gcc dot gnu.org 2023-06-01 0:24 ` pinskia at gcc dot gnu.org 2023-06-01 9:35 ` yongxiangng at gmail dot com 2023-06-01 9:37 ` yongxiangng at gmail dot com 2023-06-01 13:37 ` pinskia at gcc dot gnu.org 2023-06-02 3:43 ` yongxiangng at gmail dot com 2023-06-05 3:11 ` yongxiangng at gmail dot com 2023-06-05 3:13 ` yongxiangng at gmail dot com 2023-07-03 1:09 ` yongxiangng at gmail dot com 2023-07-28 15:40 ` cvs-commit at gcc dot gnu.org 2024-04-12 22:01 ` pinskia at gcc dot gnu.org 2024-05-27 9:29 ` user202729 at protonmail dot com [this message]
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=bug-110057-4-veCPyFXMrH@http.gcc.gnu.org/bugzilla/ \ --to=gcc-bugzilla@gcc.gnu.org \ --cc=gcc-bugs@gcc.gnu.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
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).