public inbox for gcc-bugs@sourceware.org help / color / mirror / Atom feed
From: "hiraditya at msn dot com" <gcc-bugzilla@gcc.gnu.org> To: gcc-bugs@gcc.gnu.org Subject: [Bug c++/106991] New: new+delete pair not optimized by g++ at -O3 but optimized at -Os Date: Wed, 21 Sep 2022 04:53:47 +0000 [thread overview] Message-ID: <bug-106991-4@http.gcc.gnu.org/bugzilla/> (raw) https://gcc.gnu.org/bugzilla/show_bug.cgi?id=106991 Bug ID: 106991 Summary: new+delete pair not optimized by g++ at -O3 but optimized at -Os Product: gcc Version: 13.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: hiraditya at msn dot com Target Milestone: --- https://godbolt.org/z/PeYcoqTKn ----------------------------------------------------------- #include<cassert> #include<cstdlib> int volatile gv = 0; void* operator new(long unsigned sz ) { ++gv; return malloc( sz ); } void operator delete(void *p) noexcept { --gv; free(p); } class c { int l; public: c() : l(0) {} int get(){ return l; } }; int caller( void ){ c *f = new c(); assert( f->get() == 0 ); delete f; return gv; } ----------------------------------------------------------- $ g++ -std=c++20 -O3 operator new(unsigned long): mov eax, DWORD PTR gv[rip] add eax, 1 mov DWORD PTR gv[rip], eax jmp malloc operator delete(void*): mov eax, DWORD PTR gv[rip] sub eax, 1 mov DWORD PTR gv[rip], eax jmp free caller(): sub rsp, 8 mov eax, DWORD PTR gv[rip] mov edi, 4 add eax, 1 mov DWORD PTR gv[rip], eax call malloc mov esi, 4 mov rdi, rax call operator delete(void*, unsigned long) mov eax, DWORD PTR gv[rip] add rsp, 8 ret gv: .zero 4 ----------------------------------------------------------- $ g++ -std=c++20 -Os operator new(unsigned long): mov eax, DWORD PTR gv[rip] inc eax mov DWORD PTR gv[rip], eax jmp malloc operator delete(void*): mov eax, DWORD PTR gv[rip] dec eax mov DWORD PTR gv[rip], eax jmp free caller(): mov eax, DWORD PTR gv[rip] ret gv: .zero 4
next reply other threads:[~2022-09-21 4:53 UTC|newest] Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top 2022-09-21 4:53 hiraditya at msn dot com [this message] 2022-09-21 8:17 ` [Bug ipa/106991] " rguenth at gcc dot gnu.org 2022-09-21 11:18 ` hubicka at ucw dot cz 2022-09-21 21:37 ` hiraditya at msn 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-106991-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).