public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/106991] New: new+delete pair not optimized by g++ at -O3 but optimized at -Os
@ 2022-09-21  4:53 hiraditya at msn dot com
  2022-09-21  8:17 ` [Bug ipa/106991] " rguenth at gcc dot gnu.org
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: hiraditya at msn dot com @ 2022-09-21  4:53 UTC (permalink / raw)
  To: gcc-bugs

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

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

end of thread, other threads:[~2022-09-21 21:37 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-09-21  4:53 [Bug c++/106991] New: new+delete pair not optimized by g++ at -O3 but optimized at -Os hiraditya at msn dot com
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

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