public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/56861] New: std::vector::reserve optimization bug
@ 2013-04-07  3:13 david at doublewise dot net
  2013-04-07 13:32 ` [Bug libstdc++/56861] " redi at gcc dot gnu.org
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: david at doublewise dot net @ 2013-04-07  3:13 UTC (permalink / raw)
  To: gcc-bugs


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=56861

             Bug #: 56861
           Summary: std::vector::reserve optimization bug
    Classification: Unclassified
           Product: gcc
           Version: 4.7.2
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
        AssignedTo: unassigned@gcc.gnu.org
        ReportedBy: david@doublewise.net


std::vector::reserve has a few peculiarities currently, as far as the optimizer
is concerned. In some cases, calling reserve with the final size of the vector
doesn't improve performance at all, but calling reserve with room for one extra
element does. In other cases, calling reserve with exactly the correct amount
improves performance, but calling with one extra gives the same performance as
no reserve at all. I don't know under what circumstances this happens, but it
appears to be somewhat system dependent, and changes with otherwise
insignificant changes to the code.

This arose from a StackOverflow discussion at
http://stackoverflow.com/questions/15707688/why-is-calling-vector-reserverequired-1-faster-than-vector-reserverequired

That thread contains the code in the first post, which shows the reserve + 1
situation being fastest. The answer by smossen gives some simple changes that
lead to the optimizer always working correctly or working correctly in
different situations. Unfortunately, I do not know exactly what causes this,
but it happens with and without LTO enabled, depending on the code. smossen
believes it has to do with the architecture-specific cost model being
misapplied in certain circumstances.



Using built-in specs.
COLLECT_GCC=g++
COLLECT_LTO_WRAPPER=/usr/libexec/gcc/x86_64-redhat-linux/4.7.2/lto-wrapper
Target: x86_64-redhat-linux
Configured with: ../configure --prefix=/usr --mandir=/usr/share/man
--infodir=/usr/share/info --with-bugurl=http://bugzilla.redhat.com/bugzilla
--enable-bootstrap --enable-shared --enable-threads=posix
--enable-checking=release --disable-build-with-cxx
--disable-build-poststage1-with-cxx --with-system-zlib --enable-__cxa_atexit
--disable-libunwind-exceptions --enable-gnu-unique-object
--enable-linker-build-id --with-linker-hash-style=gnu
--enable-languages=c,c++,objc,obj-c++,java,fortran,ada,go,lto --enable-plugin
--enable-initfini-array --enable-java-awt=gtk --disable-dssi
--with-java-home=/usr/lib/jvm/java-1.5.0-gcj-1.5.0.0/jre
--enable-libgcj-multifile --enable-java-maintainer-mode
--with-ecj-jar=/usr/share/java/eclipse-ecj.jar --disable-libjava-multilib
--with-ppl --with-cloog --with-tune=generic --with-arch_32=i686
--build=x86_64-redhat-linux
Thread model: posix
gcc version 4.7.2 20121109 (Red Hat 4.7.2-8) (GCC)


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

* [Bug libstdc++/56861] std::vector::reserve optimization bug
  2013-04-07  3:13 [Bug c++/56861] New: std::vector::reserve optimization bug david at doublewise dot net
@ 2013-04-07 13:32 ` redi at gcc dot gnu.org
  2013-04-07 13:34 ` redi at gcc dot gnu.org
  2021-12-05 10:00 ` pinskia at gcc dot gnu.org
  2 siblings, 0 replies; 4+ messages in thread
From: redi at gcc dot gnu.org @ 2013-04-07 13:32 UTC (permalink / raw)
  To: gcc-bugs


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=56861

Jonathan Wakely <redi at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |WAITING
   Last reconfirmed|                            |2013-04-07
     Ever Confirmed|0                           |1

--- Comment #1 from Jonathan Wakely <redi at gcc dot gnu.org> 2013-04-07 13:32:26 UTC ---
You apparently didn't read http://gcc.gnu.org/bugs

Please do not supply a URL to some other site, that's not a valid bug report.


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

* [Bug libstdc++/56861] std::vector::reserve optimization bug
  2013-04-07  3:13 [Bug c++/56861] New: std::vector::reserve optimization bug david at doublewise dot net
  2013-04-07 13:32 ` [Bug libstdc++/56861] " redi at gcc dot gnu.org
@ 2013-04-07 13:34 ` redi at gcc dot gnu.org
  2021-12-05 10:00 ` pinskia at gcc dot gnu.org
  2 siblings, 0 replies; 4+ messages in thread
From: redi at gcc dot gnu.org @ 2013-04-07 13:34 UTC (permalink / raw)
  To: gcc-bugs


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=56861

--- Comment #2 from Jonathan Wakely <redi at gcc dot gnu.org> 2013-04-07 13:34:20 UTC ---
(Andrew, I don't think this is a libstdc++ bug, maybe tree-optimization)


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

* [Bug libstdc++/56861] std::vector::reserve optimization bug
  2013-04-07  3:13 [Bug c++/56861] New: std::vector::reserve optimization bug david at doublewise dot net
  2013-04-07 13:32 ` [Bug libstdc++/56861] " redi at gcc dot gnu.org
  2013-04-07 13:34 ` redi at gcc dot gnu.org
@ 2021-12-05 10:00 ` pinskia at gcc dot gnu.org
  2 siblings, 0 replies; 4+ messages in thread
From: pinskia at gcc dot gnu.org @ 2021-12-05 10:00 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=56861

Andrew Pinski <pinskia at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
         Resolution|---                         |WORKSFORME
             Status|UNCONFIRMED                 |RESOLVED

--- Comment #4 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Can't reproduce the issue so closing.

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

end of thread, other threads:[~2021-12-05 10:00 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-04-07  3:13 [Bug c++/56861] New: std::vector::reserve optimization bug david at doublewise dot net
2013-04-07 13:32 ` [Bug libstdc++/56861] " redi at gcc dot gnu.org
2013-04-07 13:34 ` redi at gcc dot gnu.org
2021-12-05 10:00 ` pinskia at gcc dot gnu.org

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