Using gcc (GCC) 4.4.0 20080909 (experimental) with optimization level -O3 to compile the attached c++ or .ii file, I get a huge amount of assembly code. See the attached source, precompiled source and assembly files. If compiled with -Os or -O2 code size is way less. The inlined code that appears to produce that sse instruction storm appears to originates from ctype<char>::_M_widen_init in bits/locale_facets.h around line 1169. I am not sure if this is a compiler/optimizer/inliner problem or if libstdc++ is just unlucky implementing the iostream/locale stuff. Since g++ compiles much better overall optimized code with 4.4 compared to oprevious versions, I hope that this can be fixed in libstdc++. Just my 2 cent ... Thanks! Mathias Fröhlich
Created attachment 16277 [details] Original c++ code.
Created attachment 16278 [details] Preprocessed code.
Created attachment 16279 [details] Generated assembly file.
Note that the code path in question is called with every outputstream << std::endl; Thanks
Yes, but frankly it's unlikely that in 4.4.0 timeframe, also given the ABI constraints, we can change the libstdc++ implementation, which admittedly has too much code inline in this area, enough to solve this problem. We are just unlucky that 4.3.x was less aggressive at -O3, nothing changed lately (and also less recently) on the library side...
(In reply to comment #5) > Yes, but frankly it's unlikely that in 4.4.0 timeframe, also given the ABI > constraints, we can change the libstdc++ implementation, which admittedly has > too much code inline in this area, enough to solve this problem. We are just > unlucky that 4.3.x was less aggressive at -O3, nothing changed lately (and also > less recently) on the library side... Ok, one idea I have while reading your comment: Gcc has that per function optimization attributes - may be an __attribute__((optimize ('Os'))) or something similar helps for some selected functions in this area? Greetings Mathias
I have a patch in testing which changes -O3 to be the same as -O2, essentially I moved _M_narrow_init and _M_widen_init out of line. For further tweaks, really after 4.4.0.
Fine! Thanks! Mathias
This is a regression, not horribly serious still a regression.
Subject: Bug 37455 Author: paolo Date: Wed Sep 10 16:48:47 2008 New Revision: 140238 URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=140238 Log: 2008-09-10 Paolo Carlini <paolo.carlini@oracle.com> PR libstdc++/37455 * include/bits/locale_facets.h (ctype<char>::_M_narrow_init, ctype<char>::_M_widen_init): Don't define inline. * config/locale/darwin/ctype_members.cc: ... define here. * config/locale/gnu/ctype_members.cc: ... likewise. * config/locale/generic/ctype_members.cc: ... likewise. * config/abi/pre/gnu.ver: Export. Modified: trunk/libstdc++-v3/ChangeLog trunk/libstdc++-v3/config/abi/pre/gnu.ver trunk/libstdc++-v3/config/locale/darwin/ctype_members.cc trunk/libstdc++-v3/config/locale/generic/ctype_members.cc trunk/libstdc++-v3/config/locale/gnu/ctype_members.cc trunk/libstdc++-v3/include/bits/locale_facets.h
Fixed.