public inbox for gcc-bugs@sourceware.org help / color / mirror / Atom feed
From: "yongxiangng at gmail dot com" <gcc-bugzilla@gcc.gnu.org> To: gcc-bugs@gcc.gnu.org Subject: [Bug tree-optimization/110057] New: Missed devirtualization opportunities Date: Wed, 31 May 2023 10:08:25 +0000 [thread overview] Message-ID: <bug-110057-4@http.gcc.gnu.org/bugzilla/> (raw) https://gcc.gnu.org/bugzilla/show_bug.cgi?id=110057 Bug ID: 110057 Summary: Missed devirtualization opportunities Product: gcc Version: 14.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: tree-optimization Assignee: unassigned at gcc dot gnu.org Reporter: yongxiangng at gmail dot com Target Milestone: --- There are some missed devirtualization opportunities involving vectors. The issue is discussed in the stackoverflow here. https://stackoverflow.com/questions/73257739/missed-optimization-stdvectortpop-back-not-qualifying-destructor-call/ Because we know the type of the objects in the vector (they have to be _Tp), there is no need to invoke the virtual methods and we can devirtualize them. I believe this applies not just to the destructor, but also other member functions. This missed optimization does not only affect vector. When creating an array, the virtual destructor is invoked even though it should be quite clear to the compiler that it can resolve the type of the object in the array at compile time. There is a possibility of using placement new and "spoofing" the type https://godbolt.org/z/3MdMsdKha (thanks Jonathan Wakely), but I'm not sure if this is legal c++ and if this applies to raw arrays I think this might be a problem with the IPA component, I might have mislabelled the issue because there isn't an option for IPA. Please let me know if this makes sense or I have some misconception. A sample program that shows this behavior is below. /* { dg-do run } */ /* Virtual calls should be devirtualized because we know dynamic type of object in vector at compile time */ /* { dg-options "-O3 -fdump-tree-ssa" } */ #include <vector> using std::vector; class A { public: virtual ~A() { } }; class B : public A { public: virtual ~B() { } }; int main() { vector<B> arr; // B b[40]; return 0; } /* { dg-final { scan-tree-dump-times "OBJ_TYPE_REF" 0 "ssa"} } */
next reply other threads:[~2023-05-31 10:08 UTC|newest] Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top 2023-05-31 10:08 yongxiangng at gmail dot com [this message] 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
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@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).