public inbox for gcc-prs@sourceware.org
help / color / mirror / Atom feed
* optimization/9767: explicit instantiation of class members unoptimized?
@ 2003-02-20  5:56 bkoz
  0 siblings, 0 replies; 2+ messages in thread
From: bkoz @ 2003-02-20  5:56 UTC (permalink / raw)
  To: gcc-gnats


>Number:         9767
>Category:       optimization
>Synopsis:       explicit instantiation of class members unoptimized?
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    unassigned
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Thu Feb 20 05:56:00 UTC 2003
>Closed-Date:
>Last-Modified:
>Originator:     bkoz@redhat.com
>Release:        gcc version 3.4 20030217 (experimental), maybe gcc-3.3
>Organization:
>Environment:
x86/linux
>Description:
Apparently,  explicit instantation of class templates is outputting code for member functions that is not optimized. See below. 

The codegen for the explicit instantiation of just the write member function is optimized, at -02 and -O1. In particular, the _M_write function is inlined. However, when the same member function is instantiated during the instantiation of the whole class, this member function has substantially different codegen. In particular, the _M_write function is not inlined.

The only way to get this same codegen for just the instantiation of the member function itself is to use '-O0'. Ouch.

Please help!

Sample output below.

For just the member function instantiation:


_ZNSo5writeEPKci:
.LFB1548:
	pushl	%ebp
.LCFI0:
	movl	%esp, %ebp
.LCFI1:
	leal	-24(%ebp), %eax
	pushl	%esi
.LCFI2:
	pushl	%ebx
.LCFI3:
	subl	$32, %esp
.LCFI4:
	movl	8(%ebp), %ebx
	movl	%eax, (%esp)
	movl	16(%ebp), %esi
	movl	%ebx, 4(%esp)
.LEHB0:
	call	_ZNSo6sentryC1ERSo
.LEHE0:
	cmpb	$0, -24(%ebp)
	jne	.L43
.L2:
	movl	-20(%ebp), %eax
	movl	(%eax), %edx
	movl	-12(%edx), %esi
	addl	%esi, %eax
	testb	$32, 13(%eax)
	jne	.L44
.L40:
	addl	$32, %esp
	movl	%ebx, %eax
	popl	%ebx
	popl	%esi
	popl	%ebp
	ret
	.p2align 4,,7
.L43:
	movl	(%ebx), %eax
	movl	-12(%eax), %edx
	leal	(%edx,%ebx), %eax
	movl	124(%eax), %edx
	movl	12(%ebp), %eax
	movl	(%edx), %ecx
	movl	%esi, 8(%esp)
	movl	%eax, 4(%esp)
	movl	%edx, (%esp)
.LEHB1:
	call	*48(%ecx)
	cmpl	%esi, %eax
	je	.L2
	movl	(%ebx), %eax
	movl	%ebx, %edx
	movl	-12(%eax), %ecx
	addl	%ecx, %edx
	movl	20(%edx), %eax
	movl	%edx, (%esp)
	orl	$1, %eax
	movl	%eax, 4(%esp)
	call	_ZNSt9basic_iosIcSt11char_traitsIcEE5clearESt12_Ios_Iostate
.LEHE1:
	jmp	.L2
	.p2align 4,,7
.L44:
	call	_ZSt18uncaught_exceptionv
	testb	%al, %al
	jne	.L40
	movl	-20(%ebp), %eax
	movl	(%eax), %edx
	movl	-12(%edx), %ecx
	addl	%ecx, %eax
	movl	124(%eax), %edx
	testl	%edx, %edx
	je	.L40
	movl	(%edx), %eax
	movl	%edx, (%esp)
.LEHB2:
	call	*24(%eax)
	incl	%eax
	jne	.L40
	movl	-20(%ebp), %eax
	movl	(%eax), %edx
	movl	-12(%edx), %esi
	addl	%esi, %eax
	movl	20(%eax), %edx
	movl	%eax, (%esp)
	orl	$1, %edx
	movl	%edx, 4(%esp)
	call	_ZNSt9basic_iosIcSt11char_traitsIcEE5clearESt12_Ios_Iostate
	jmp	.L40
	.p2align 4,,7
.L41:
.L11:
	movl	%eax, %ebx
	movl	-20(%ebp), %eax
	movl	(%eax), %edx
	movl	-12(%edx), %ecx
	addl	%ecx, %eax
	testb	$32, 13(%eax)
	jne	.L45
.L25:
.L26:
	movl	%ebx, (%esp)
	call	_Unwind_Resume
.LEHE2:
.L45:
	call	_ZSt18uncaught_exceptionv
	testb	%al, %al
	jne	.L25
	movl	-20(%ebp), %eax
	movl	(%eax), %edx
	movl	-12(%edx), %esi
	addl	%esi, %eax
	movl	124(%eax), %edx
	testl	%edx, %edx
	je	.L25
	movl	(%edx), %eax
	movl	%edx, (%esp)
	call	*24(%eax)
	incl	%eax
	jne	.L25
	movl	-20(%ebp), %eax
	movl	(%eax), %edx
	movl	-12(%edx), %ecx
	addl	%ecx, %eax
	movl	20(%eax), %edx
	movl	%eax, (%esp)
	orl	$1, %edx
	movl	%edx, 4(%esp)
	call	_ZNSt9basic_iosIcSt11char_traitsIcEE5clearESt12_Ios_Iostate
	jmp	.L25



And the same function clipped from the whole class instantiation:

_ZNSo5writeEPKci:
.LFB1627:
	pushl	%ebp
.LCFI124:
	movl	%esp, %ebp
.LCFI125:
	subl	$40, %esp
.LCFI126:
	movl	%ebx, -8(%ebp)
.LCFI127:
	movl	8(%ebp), %ebx
	movl	%esi, -4(%ebp)
.LCFI128:
	leal	-24(%ebp), %esi
	movl	%ebx, 4(%esp)
	movl	%esi, (%esp)
.LEHB104:
	call	_ZNSo6sentryC1ERSo
.LEHE104:
	cmpb	$0, -24(%ebp)
	je	.L813
	movl	%ebx, (%esp)
	movl	16(%ebp), %eax
	movl	%eax, 8(%esp)
	movl	12(%ebp), %eax
	movl	%eax, 4(%esp)
.LEHB105:
	call	_ZNSo8_M_writeEPKci   <--------FUCKED
.LEHE105:
.L813:
	movl	%esi, (%esp)
.LEHB106:
	call	_ZNSo6sentryD1Ev
.LEHE106:
	movl	%ebx, %eax
	movl	-4(%ebp), %esi
	movl	-8(%ebp), %ebx
	movl	%ebp, %esp
	popl	%ebp
	ret
	.p2align 4,,7
.L819:
.L815:
.L817:
	movl	%esi, (%esp)
	movl	%eax, %ebx
	call	_ZNSo6sentryD1Ev
	movl	%ebx, (%esp)
.LEHB107:
	call	_Unwind_Resume

>How-To-Repeat:
compile the following with '-O2 -S'

#include <ostream>

namespace std
{
#if 1
  template 
    basic_ostream<char>& 
    basic_ostream<char>::write(const char*, streamsize);
#else
   template class basic_ostream<char>;
#endif
}
>Fix:

>Release-Note:
>Audit-Trail:
>Unformatted:


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

* Re: optimization/9767: explicit instantiation of class members unoptimized?
@ 2003-03-22  5:07 bangerth
  0 siblings, 0 replies; 2+ messages in thread
From: bangerth @ 2003-03-22  5:07 UTC (permalink / raw)
  To: bkoz, gcc-bugs, gcc-prs, nobody

Synopsis: explicit instantiation of class members unoptimized?

State-Changed-From-To: open->analyzed
State-Changed-By: bangerth
State-Changed-When: Sat Mar 22 05:07:49 2003
State-Changed-Why:
    Jason analyzed this already.

http://gcc.gnu.org/cgi-bin/gnatsweb.pl?cmd=view%20audit-trail&database=gcc&pr=9767


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

end of thread, other threads:[~2003-03-22  5:07 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2003-02-20  5:56 optimization/9767: explicit instantiation of class members unoptimized? bkoz
2003-03-22  5:07 bangerth

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