Re: libstdc++: Speed up push_back

2023-11-24 Thread Jonathan Wakely
On Fri, 24 Nov 2023 at 20:07, Jan Hubicka wrote: > The vector.tcc change was regtested on x86_64-linux, OK? > > libstdc++-v3/ChangeLog: > > * include/bits/vector.tcc (reserve): Copy _M_start and _M_finish > to local variables to allow propagation across call to > allocator.

Re: libstdc++: Speed up push_back

2023-11-24 Thread Jan Hubicka
> With my changes at -O3 we now inline push_back, so we could optimize the > first loop to the second. However with > ~/trunk-install/bin/gcc -O3 auto.C -S -fdump-tree-all-details > -fno-exceptions -fno-store-merging -fno-tree-slp-vectorize > the fist problem is right at the begining: > >[

Re: libstdc++: Speed up push_back

2023-11-24 Thread Marc Glisse
On Thu, 23 Nov 2023, Jonathan Wakely wrote: That's why we need -fsane-operator-new Although the standard forbids it, some of us just provide an inline implementation inline void* operator new(std::size_t n){return malloc(n);} inline void operator delete(void*p)noexcept{free(p);} inline void

Re: libstdc++: Speed up push_back

2023-11-24 Thread Richard Biener
On Fri, 24 Nov 2023, Martin Jambor wrote: > Hello, > > On Thu, Nov 23 2023, Jonathan Wakely wrote: > > On Thu, 23 Nov 2023 at 15:34, Jan Hubicka wrote: > >> > > [...] > > >> > >> I also wonder, if default operator new and malloc can be handled as not > >> reading/modifying anything visible to

Re: libstdc++: Speed up push_back

2023-11-24 Thread Martin Jambor
Hello, On Thu, Nov 23 2023, Jonathan Wakely wrote: > On Thu, 23 Nov 2023 at 15:34, Jan Hubicka wrote: >> [...] >> >> I also wonder, if default operator new and malloc can be handled as not >> reading/modifying anything visible to the user code. > > No, there's no way to know if the default oper

Re: libstdc++: Speed up push_back

2023-11-23 Thread Jonathan Wakely
On Thu, 23 Nov 2023 at 15:44, Jan Hubicka wrote: > > Hi, > so if I understand it right, it should be safe to simply replace memmove > by memcpy. I wonder if we can get rid of the count != 0 check at least > for glibc systems. I don't think we can do that. It's still undefined with glibc, and gli

Re: libstdc++: Speed up push_back

2023-11-23 Thread Jonathan Wakely
On Thu, 23 Nov 2023 at 15:34, Jan Hubicka wrote: > > > > On Sunday, 19 November 2023 22:53:37 CET Jan Hubicka wrote: > > > > Sadly it is really hard to work out this > > > > from IPA passes, since we basically care whether the iterator points to > > > > the same place as the end pointer, which are

Re: libstdc++: Speed up push_back

2023-11-23 Thread Jan Hubicka
Hi, so if I understand it right, it should be safe to simply replace memmove by memcpy. I wonder if we can get rid of the count != 0 check at least for glibc systems. In general push_back now need inline-insns-auto to be 33 to be inlined at -O2 jh@ryzen4:/tmp> cat ~/tt.C #include typedef unsig

Re: libstdc++: Speed up push_back

2023-11-23 Thread Jan Hubicka
> > On Sunday, 19 November 2023 22:53:37 CET Jan Hubicka wrote: > > > Sadly it is really hard to work out this > > > from IPA passes, since we basically care whether the iterator points to > > > the same place as the end pointer, which are both passed by reference. > > > This is inter-procedural va

Re: libstdc++: Speed up push_back

2023-11-23 Thread Jan Hubicka
> On Sunday, 19 November 2023 22:53:37 CET Jan Hubicka wrote: > > Sadly it is really hard to work out this > > from IPA passes, since we basically care whether the iterator points to > > the same place as the end pointer, which are both passed by reference. > > This is inter-procedural value number

Re: libstdc++: Speed up push_back

2023-11-23 Thread Matthias Kretz
On Sunday, 19 November 2023 22:53:37 CET Jan Hubicka wrote: > Sadly it is really hard to work out this > from IPA passes, since we basically care whether the iterator points to > the same place as the end pointer, which are both passed by reference. > This is inter-procedural value numbering that i

Re: libstdc++: Speed up push_back

2023-11-21 Thread Jonathan Wakely
On Tue, 21 Nov 2023 at 12:50, Jan Hubicka wrote: > > > > + // RAII type to destroy initialized elements. > > > > There's only one initialized element, not "elements". > > > > > + struct _Guard_elts > > > + { > > > + pointer _M_first, _M_last; // Elements

Re: libstdc++: Speed up push_back

2023-11-21 Thread Jan Hubicka
> > + // RAII type to destroy initialized elements. > > There's only one initialized element, not "elements". > > > + struct _Guard_elts > > + { > > + pointer _M_first, _M_last; // Elements to destroy > > We only need to store one pointer here, call it

Re: libstdc++: Speed up push_back

2023-11-20 Thread Jonathan Wakely
On Mon, 20 Nov 2023 at 15:44, Jan Hubicka wrote: > > > > + // RAII type to destroy initialized elements. > > > > There's only one initialized element, not "elements". > > > > > + struct _Guard_elts > > > + { > > > + pointer _M_first, _M_last; // Elements

Re: libstdc++: Speed up push_back

2023-11-20 Thread Jan Hubicka
> > + // RAII type to destroy initialized elements. > > There's only one initialized element, not "elements". > > > + struct _Guard_elts > > + { > > + pointer _M_first, _M_last; // Elements to destroy > > We only need to store one pointer here, call it

Re: libstdc++: Speed up push_back

2023-11-20 Thread Jonathan Wakely
On Sun, 19 Nov 2023 at 21:53, Jan Hubicka wrote: > > Hi, > this patch speeds up the push_back at -O3 significantly by making the > reallocation to be inlined by default. _M_realloc_insert is general > insertion that takes iterator pointing to location where the value > should be inserted. As suc

libstdc++: Speed up push_back

2023-11-19 Thread Jan Hubicka
Hi, this patch speeds up the push_back at -O3 significantly by making the reallocation to be inlined by default. _M_realloc_insert is general insertion that takes iterator pointing to location where the value should be inserted. As such it contains code to move other entries around that is quite