public inbox for gcc@gcc.gnu.org
 help / color / mirror / Atom feed
* Useless code generated by gcc 2.95.2????
@ 1999-11-01 13:43 Thomas E Deweese
  1999-11-02 23:46 ` Martin v. Loewis
  1999-11-30 23:37 ` Thomas E Deweese
  0 siblings, 2 replies; 18+ messages in thread
From: Thomas E Deweese @ 1999-11-01 13:43 UTC (permalink / raw)
  To: gcc

Hi all,

	We are looking to upgrade from egcs 1.0.2 to gcc 2.95.2, and
we noticed that object file sizes have gone up significantly (~50%)
between the two releases (On Sparc).  So, I thought I would take a
look at some of the generated asm. I noticed what looked to be dead
code that was generated. Based on my observations I have generated a
small test case:

------------------------------------------------------------------------

#include <stdlib.h>
template <class T>
class Foo {
  public:
    Foo() { }
};

Foo<unsigned char> *fu8=NULL;

void reset(void) {
  fu8 = new Foo<unsigned char>();
}

------------------------------------------------------------------------

I have included complete asm and verbose compile dumps at the end of
the message but I have brought out the part that most interests me up
here.  My basic question is: How can it ever reach '.LL5' with %l1
equal to zero?

	It looks to me like the deletes following '.LL5' and '.LL3'
are duplicates and that the delete at '.LL5' can never be reached (and
if it were to be reached the result would be a double delete).

Here is my thinking:
	1) The only way to reach '.LL5' without having cleared %l1 is
	   for an error to be thrown in the call to the constructor.  

	2) This (if I understand how errorhandling is done) would lead
	   to a jump to '.LL3' which _would_ delete the 'Foo', then
	   jump to the call to __throw at '.LL4'.

	3) If that were to ever return (which I don't think it will)
	   then the delete following '.LL5' would also be called (a
	   double delete of the contents of %l0).

	Is there some unseen way for the system to branch to
'.LLEHE3'?  (through the error handler?) 
	I missing something, or is that truely dead code? 

	I don't pretend to be an expert on the internals of g++, asm,
or gcc's error handling mechanisms, but that duplicate code just looks
suspicious to me.  Any help on this would be greatly appreciated.

	I doubt this would fully account for my 50% code growth but
it's a start.

------------------------------------------------------------------------

reset__Fv:
.LLFB1:
	!#PROLOGUE# 0
	save	%sp, -112, %sp
.LLCFI0:
	!#PROLOGUE# 1
	sethi	%hi(fu8), %o0
	or	%o0, %lo(fu8), %l2
	mov	1, %o0
	call	__builtin_new, 0
	 nop
	mov	%o0, %l0
	mov	1, %l1
.LLEHB3:
	mov	%l0, %o0
	call	__t3Foo1ZUc, 0
	 nop
	mov	0, %l1
	st	%o0, [%l2]
.LLEHE3:
	b	.LL5
	 nop
.LL4:
	call	__throw, 0
	 nop
.LL5:
	cmp	%l1, 0
	be	.LL7
	nop
	mov	%l0, %o0
	call	__builtin_delete, 0
	 nop
	b	.LL7
	 nop
.LL6:
.LL7:
	b	.LL10
	 nop
.LLEHB11:
.LL3:
	cmp	%l1, 0
	be	.LL9
	nop
	mov	%l0, %o0
	call	__builtin_delete, 0
	 nop
	b	.LL9
	 nop
.LL8:
.LL9:
	b	.LL4
	 nop

------------------------------------------------------------------------

I compiled my example with the following line:

g++ -fverbose-asm --verbose Foo.cc -o Foo-295-3.s -S 

Reading specs from /freeware/gnu/gcc-2.95.2/sun/lib/gcc-lib/sparc-sun-solaris2.5.1/2.95.2/specs
gcc version 2.95.2 19991024 (release)
 /freeware/gnu/gcc-2.95.2/sun/lib/gcc-lib/sparc-sun-solaris2.5.1/2.95.2/cpp -lang-c++ -v -D__GNUC__=2 -D__GNUG__=2 -D__GNUC_MINOR__=95 -D__cplusplus -Dsparc -Dsun -Dunix -D__svr4__ -D__SVR4 -D__sparc__ -D__sun__ -D__unix__ -D__svr4__ -D__SVR4 -D__sparc -D__sun -D__unix -Asystem(unix) -Asystem(svr4) -D__EXCEPTIONS -D__GCC_NEW_VARARGS__ -Acpu(sparc) -Amachine(sparc) Foo.cc /home/deweese/tmp/ccIwWesd.ii
GNU CPP version 2.95.2 19991024 (release) (sparc)
[...]
/freeware/gnu/gcc-2.95.2/sun/lib/gcc-lib/sparc-sun-solaris2.5.1/2.95.2/cc1plus /home/deweese/tmp/ccIwWesd.ii -quiet -dumpbase Foo.cc -version -fverbose-asm -o Foo-295-3.s
GNU C++ version 2.95.2 19991024 (release) (sparc-sun-solaris2.5.1) compiled by GNU C version 2.95.2 19991024 (release).

------------------------------------------------------------------------

The generated assembly:

	.file	"Foo.cc"
! GNU C++ version 2.95.2 19991024 (release) (sparc-sun-solaris2.5.1) compiled by GNU C version 2.95.2 19991024 (release).
! options passed:  -fverbose-asm
! options enabled:  -fpeephole -ffunction-cse -fkeep-static-consts
! -fpcc-struct-return -fsched-interblock -fsched-spec -fexceptions -fcommon
! -fverbose-asm -fgnu-linker -fargument-alias -fident -mepilogue -mapp-regs

gcc2_compiled.:
	.global fu8
.section	".data"
	.align 4
	.type	 fu8,#object
	.size	 fu8,4
fu8:
	.uaword	0
	.global __throw
.section	".text"
	.align 4
	.global reset__Fv
	.type	 reset__Fv,#function
	.proc	020
reset__Fv:
.LLFB1:
	!#PROLOGUE# 0
	save	%sp, -112, %sp
.LLCFI0:
	!#PROLOGUE# 1
	sethi	%hi(fu8), %o0
	or	%o0, %lo(fu8), %l2
	mov	1, %o0
	call	__builtin_new, 0
	 nop
	mov	%o0, %l0
	mov	1, %l1
.LLEHB3:
	mov	%l0, %o0
	call	__t3Foo1ZUc, 0
	 nop
	mov	0, %l1
	st	%o0, [%l2]
.LLEHE3:
	b	.LL5
	 nop
.LL4:
	call	__throw, 0
	 nop
.LL5:
	cmp	%l1, 0
	be	.LL7
	nop
	mov	%l0, %o0
	call	__builtin_delete, 0
	 nop
	b	.LL7
	 nop
.LL6:
.LL7:
	b	.LL10
	 nop
.LLEHB11:
.LL3:
	cmp	%l1, 0
	be	.LL9
	nop
	mov	%l0, %o0
	call	__builtin_delete, 0
	 nop
	b	.LL9
	 nop
.LL8:
.LL9:
	b	.LL4
	 nop
.LLEHE11:
	b	.LL11
	 nop
.LL12:
	call	__throw, 0
	 nop
.LL13:
.LL11:
	call	terminate__Fv, 0
	 nop
.LL10:
	b	.LL14
	 nop
	b	.LL2
	 nop
.LL14:
.LL2:
	ret
	restore
.LLFE1:
.LLfe1:
	.size	 reset__Fv,.LLfe1-reset__Fv
.section	".gcc_except_table",#alloc,#write
	.align 4
__EXCEPTION_TABLE__:
	.uaword	.LLEHB3
	.uaword	.LLEHE3
	.uaword	.LL3

	.uaword	.LLEHB11
	.uaword	.LLEHE11
	.uaword	.LL11

.LLRTH1:
	.uaword	-1
	.uaword	-1


.section	".eh_frame",#alloc,#write
__FRAME_BEGIN__:
	.uaword	.LLECIE1-.LLSCIE1
.LLSCIE1:
	.uaword	0x0
	.byte	0x1
	.asciz	"eh"

	.uaword	__EXCEPTION_TABLE__
	.byte	0x1
	.byte	0x7c
	.byte	0x65
	.byte	0xc
	.byte	0xe
	.byte	0x0
	.byte	0x9
	.byte	0x65
	.byte	0xf
	.align 4
.LLECIE1:
	.uaword	.LLEFDE1-.LLSFDE1
.LLSFDE1:
	.uaword	.LLSFDE1-__FRAME_BEGIN__
	.uaword	.LLFB1
	.uaword	.LLFE1-.LLFB1
	.byte	0x4
	.uaword	.LLCFI0-.LLFB1
	.byte	0xd
	.byte	0x1e
	.byte	0x2d
	.byte	0x9
	.byte	0x65
	.byte	0x1f
	.align 4
.LLEFDE1:
	.ident	"GCC: (GNU) 2.95.2 19991024 (release)"

-- 
							Thomas DeWeese
deweese@kodak.com
			"The only difference between theory and practice is
			 that in theory there isn't any." -- unknown

^ permalink raw reply	[flat|nested] 18+ messages in thread
* Re: Useless code generated by gcc 2.95.2????
@ 1999-11-03 14:22 Mike Stump
  1999-11-03 16:06 ` Martin v. Loewis
  1999-11-30 23:37 ` Mike Stump
  0 siblings, 2 replies; 18+ messages in thread
From: Mike Stump @ 1999-11-03 14:22 UTC (permalink / raw)
  To: deweese, martin; +Cc: gcc

LL5 is dead and should be removed.  Region 3 is near trivial and it
might be able to be removed, but it is in some sense, correct.  LL11
is used to protect LL3.  Technically operator delete can't throw, and
if we knew that and used that information then we could get rid of
LL11.  Last time I worked on the code, it didn't have that type of
information at it's disposal (meaning LL11 could not be deleted).

I don't think some of the extra code is caused by a bug, but rather
the addition of a feature.  LL5 non-removal however is a bug, that I
suspect someone introduced.  A binary search of cvs could tell how
broke it and how they broke it.  That would then prompt them into
fixing it (maybe).

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

end of thread, other threads:[~1999-11-30 23:37 UTC | newest]

Thread overview: 18+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1999-11-01 13:43 Useless code generated by gcc 2.95.2???? Thomas E Deweese
1999-11-02 23:46 ` Martin v. Loewis
1999-11-03  4:47   ` Thomas E Deweese
1999-11-03 10:32     ` Richard Henderson
1999-11-03 15:22       ` Joern Rennecke
1999-11-03 15:40         ` Richard Henderson
1999-11-30 23:37           ` Richard Henderson
1999-11-30 23:37         ` Joern Rennecke
1999-11-30 23:37       ` Richard Henderson
1999-11-30 23:37     ` Thomas E Deweese
1999-11-30 23:37   ` Martin v. Loewis
1999-11-30 23:37 ` Thomas E Deweese
1999-11-03 14:22 Mike Stump
1999-11-03 16:06 ` Martin v. Loewis
1999-11-06  7:36   ` Thomas E Deweese
1999-11-30 23:37     ` Thomas E Deweese
1999-11-30 23:37   ` Martin v. Loewis
1999-11-30 23:37 ` Mike Stump

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