Bug 37455 - [4.4 Regression] Code bloat for ostream.widen('\n')
Summary: [4.4 Regression] Code bloat for ostream.widen('\n')
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: libstdc++ (show other bugs)
Version: 4.4.0
: P3 normal
Target Milestone: 4.4.0
Assignee: Paolo Carlini
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2008-09-10 06:54 UTC by Mathias Fröhlich
Modified: 2008-09-10 16:51 UTC (History)
1 user (show)

See Also:
Host: x86_64-unknown-linux-gnu
Target: x86_64-unknown-linux-gnu
Build: x86_64-unknown-linux-gnu
Known to work:
Known to fail:
Last reconfirmed: 2008-09-10 15:34:19


Attachments
Original c++ code. (77 bytes, text/x-c++src)
2008-09-10 06:55 UTC, Mathias Fröhlich
Details
Preprocessed code. (60.29 KB, text/plain)
2008-09-10 06:56 UTC, Mathias Fröhlich
Details
Generated assembly file. (19.63 KB, text/plain)
2008-09-10 06:56 UTC, Mathias Fröhlich
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Mathias Fröhlich 2008-09-10 06:54:17 UTC
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
Comment 1 Mathias Fröhlich 2008-09-10 06:55:23 UTC
Created attachment 16277 [details]
Original c++ code.
Comment 2 Mathias Fröhlich 2008-09-10 06:56:03 UTC
Created attachment 16278 [details]
Preprocessed code.
Comment 3 Mathias Fröhlich 2008-09-10 06:56:38 UTC
Created attachment 16279 [details]
Generated assembly file.
Comment 4 Mathias Fröhlich 2008-09-10 07:06:59 UTC
Note that the code path in question is called with every

outputstream << std::endl;

Thanks
Comment 5 Paolo Carlini 2008-09-10 15:23:42 UTC
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...
Comment 6 Mathias Fröhlich 2008-09-10 15:38:08 UTC
(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
Comment 7 Paolo Carlini 2008-09-10 15:54:45 UTC
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.
Comment 8 Mathias Fröhlich 2008-09-10 16:13:33 UTC
Fine!
Thanks!

Mathias
Comment 9 Paolo Carlini 2008-09-10 16:20:51 UTC
This is a regression, not horribly serious still a regression.
Comment 10 paolo@gcc.gnu.org 2008-09-10 16:49:59 UTC
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

Comment 11 Paolo Carlini 2008-09-10 16:51:43 UTC
Fixed.