public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/19661] New: many redundant atexit calls emitted into the executable for static objects with empty destructors
@ 2005-01-27 22:24 yuri at tsoft dot com
  2005-01-28  1:08 ` [Bug c++/19661] unnecessary atexit calls emitted " bangerth at dealii dot org
                   ` (7 more replies)
  0 siblings, 8 replies; 9+ messages in thread
From: yuri at tsoft dot com @ 2005-01-27 22:24 UTC (permalink / raw)
  To: gcc-bugs

When some object having empty destructor is declared as static in the local
context of some function g++ still inserts <atexit> call with the empty handler
like <__tcf_0> below.

It may seem like minor issue but redundant instructions increase chances for
I-cache misses and worthen processor pipeline.

Yuri


08048800 <__tcf_0>:
 8048800:       55                      push   %ebp
 8048801:       89 e5                   mov    %esp,%ebp
 8048803:       5d                      pop    %ebp
 8048804:       c3                      ret


--testcase--
begin 644 case-empty-atexit.tgz
M'XL(`.1G^4$``^V6VVJ#0!"&O=ZG&-*;))!D/:Q>)!1"GV31:2.83=`U&$KZ
M[!U-BI)#<U%)"YT/85?\]Z#C/[.Q+G""ZZW=3[3%*K4SIW>D#&2D%+5*JLBG
M5DHW4$U[PG&E&X5>Z(>^YTC7#X/(`=7_5BXI"ZMS`&=?YNEWN@1WF&VVC]C2
M(XDOXE]-7WI>0[I2AD%P,_X4^:_XUW\`Z0//"QV0/>_C*O\\_D(\I2;.R@1A
M4$U7`R&PLI@;V&W2!,H"AZ.Y$/2-;!K#$C3=B+5.S7`$[P(@WI06%@L8H*%1
M@[J+)LGF].@TMJ/)4.^PHSF(WWY[YIK_5SVO<<__7NM_GZ2-_U7$_G\$'?\O
MTDUA<]3K9U$6J7D#H]=8;'6,4-BDR0)Y&5O*`K7SEW4&:+V]I*XY"C!I/0X'
MDC:IY-6<#Z`$<:[\.,XZ&W=D"5Y..YZ1_##G_/%CKOA_0H'I]0QPM_Y+U=;_
M*"*]HHO]_PANE?]CJ6\/`8WGN\<``#VM/<UEG&$8AF$8AF$8AF$8AF$8AF$8
-AF'^#)_;GM5=`"@`````
`
end

-- 
           Summary: many redundant atexit calls emitted into the executable
                    for static objects with empty destructors
           Product: gcc
           Version: 3.4.2
            Status: UNCONFIRMED
          Severity: normal
          Priority: P2
         Component: c++
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: yuri at tsoft dot com
                CC: gcc-bugs at gcc dot gnu dot org
 GCC build triplet: n/a
GCC target triplet: n/a


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


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

* [Bug c++/19661] unnecessary atexit calls emitted for static objects with empty destructors
  2005-01-27 22:24 [Bug c++/19661] New: many redundant atexit calls emitted into the executable for static objects with empty destructors yuri at tsoft dot com
@ 2005-01-28  1:08 ` bangerth at dealii dot org
  2005-01-28  1:22 ` [Bug middle-end/19661] " pinskia at gcc dot gnu dot org
                   ` (6 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: bangerth at dealii dot org @ 2005-01-28  1:08 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From bangerth at dealii dot org  2005-01-28 01:08 -------
Confirmed, although I consider this to be a rather minor point since 
the code is actually run only once. Here's a small test: 
-------------------- 
struct A { 
    A(); 
    ~A() {} 
}; 
 
void foo () { 
  static A a; 
} 
------------------------- 
 
g/x> /home/bangerth/bin/gcc-4.0-pre/bin/c++ -S -O3 x.cc 
g/x> cat x.s | c++filt > x.ss 
 
.... 
foo(): 
.LFB5: 
	pushl	%ebp 
.LCFI2: 
	movl	%esp, %ebp 
.LCFI3: 
	pushl	%ebx 
.LCFI4: 
	subl	$20, %esp 
.LCFI5: 
	cmpb	$0, guard variable for foo()::a 
	je	.L12 
.L9: 
	addl	$20, %esp 
	popl	%ebx 
	popl	%ebp 
	ret 
	.p2align 4,,7 
.L12: 
	movl	guard variable for foo()::a, (%esp) 
	call	__cxa_guard_acquire 
	testl	%eax, %eax 
	je	.L9 
	movl	foo()::a, (%esp) 
.LEHB0: 
	call	A::A() 
.LEHE0: 
	movl	guard variable for foo()::a, (%esp) 
	call	__cxa_guard_release 
	movl	$__tcf_0, (%esp) 
	call	atexit 
	addl	$20, %esp 
	popl	%ebx 
	popl	%ebp 
	ret 
... 
 
W. 

-- 
           What    |Removed                     |Added
----------------------------------------------------------------------------
           Severity|normal                      |enhancement
             Status|UNCONFIRMED                 |NEW
     Ever Confirmed|                            |1
   Last reconfirmed|0000-00-00 00:00:00         |2005-01-28 01:08:27
               date|                            |
            Summary|many redundant atexit calls |unnecessary atexit calls
                   |emitted into the executable |emitted for static objects
                   |for static objects with     |with empty destructors
                   |empty destructors           |


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


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

* [Bug middle-end/19661] unnecessary atexit calls emitted for static objects with empty destructors
  2005-01-27 22:24 [Bug c++/19661] New: many redundant atexit calls emitted into the executable for static objects with empty destructors yuri at tsoft dot com
  2005-01-28  1:08 ` [Bug c++/19661] unnecessary atexit calls emitted " bangerth at dealii dot org
@ 2005-01-28  1:22 ` pinskia at gcc dot gnu dot org
  2005-01-28  1:26 ` [Bug c++/19661] " yuri at tsoft dot com
                   ` (5 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2005-01-28  1:22 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From pinskia at gcc dot gnu dot org  2005-01-28 01:22 -------
This is related to PR 17736 which is for empty global variables with empty constructors.

-- 
           What    |Removed                     |Added
----------------------------------------------------------------------------
          Component|c++                         |middle-end
           Keywords|                            |missed-optimization


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


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

* [Bug c++/19661] unnecessary atexit calls emitted for static objects with empty destructors
  2005-01-27 22:24 [Bug c++/19661] New: many redundant atexit calls emitted into the executable for static objects with empty destructors yuri at tsoft dot com
  2005-01-28  1:08 ` [Bug c++/19661] unnecessary atexit calls emitted " bangerth at dealii dot org
  2005-01-28  1:22 ` [Bug middle-end/19661] " pinskia at gcc dot gnu dot org
@ 2005-01-28  1:26 ` yuri at tsoft dot com
  2005-01-28  1:46 ` [Bug middle-end/19661] " pinskia at gcc dot gnu dot org
                   ` (4 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: yuri at tsoft dot com @ 2005-01-28  1:26 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From yuri at tsoft dot com  2005-01-28 01:26 -------
(In reply to comment #1)
> Confirmed, although I consider this to be a rather minor point since 
> the code is actually run only once. Here's a small test: 

I agree, but it bloats the code, therefore reducing potential for inlining and
pipeline trashing.

-- 
           What    |Removed                     |Added
----------------------------------------------------------------------------
           Severity|enhancement                 |normal
          Component|middle-end                  |c++


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


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

* [Bug middle-end/19661] unnecessary atexit calls emitted for static objects with empty destructors
  2005-01-27 22:24 [Bug c++/19661] New: many redundant atexit calls emitted into the executable for static objects with empty destructors yuri at tsoft dot com
                   ` (2 preceding siblings ...)
  2005-01-28  1:26 ` [Bug c++/19661] " yuri at tsoft dot com
@ 2005-01-28  1:46 ` pinskia at gcc dot gnu dot org
  2005-01-28 17:02 ` [Bug c++/19661] " bangerth at dealii dot org
                   ` (3 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2005-01-28  1:46 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From pinskia at gcc dot gnu dot org  2005-01-28 01:45 -------
But it is still an enhancement because any missed optimization that does not happen before is.
Also this is a middle-end bug since the middle-end and not the front-end figure out that the function 
is empty and remove the call to atexit.

-- 
           What    |Removed                     |Added
----------------------------------------------------------------------------
           Severity|normal                      |enhancement
          Component|c++                         |middle-end


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


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

* [Bug c++/19661] unnecessary atexit calls emitted for static objects with empty destructors
  2005-01-27 22:24 [Bug c++/19661] New: many redundant atexit calls emitted into the executable for static objects with empty destructors yuri at tsoft dot com
                   ` (3 preceding siblings ...)
  2005-01-28  1:46 ` [Bug middle-end/19661] " pinskia at gcc dot gnu dot org
@ 2005-01-28 17:02 ` bangerth at dealii dot org
  2005-01-28 18:53 ` [Bug middle-end/19661] " pinskia at gcc dot gnu dot org
                   ` (2 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: bangerth at dealii dot org @ 2005-01-28 17:02 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From bangerth at dealii dot org  2005-01-28 17:01 -------
atexit only takes a pointer to a function to be run on exit of the 
program. The fact that this is an empty function is unbeknownst to 
it, and probably the code in the middle-end that has to deal with 
that. I therefore believe that the front-end has to take care of the 
fact that we have may run an empty function; it would also logically 
make sense to guard the call to atexit with a check whether the 
destructor is empty or not. 
 
I'll move this bug back to the C++ component. 
 
W. 

-- 
           What    |Removed                     |Added
----------------------------------------------------------------------------
          Component|middle-end                  |c++


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


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

* [Bug middle-end/19661] unnecessary atexit calls emitted for static objects with empty destructors
  2005-01-27 22:24 [Bug c++/19661] New: many redundant atexit calls emitted into the executable for static objects with empty destructors yuri at tsoft dot com
                   ` (4 preceding siblings ...)
  2005-01-28 17:02 ` [Bug c++/19661] " bangerth at dealii dot org
@ 2005-01-28 18:53 ` pinskia at gcc dot gnu dot org
  2005-01-28 19:11 ` bangerth at dealii dot org
  2005-09-24 17:43 ` [Bug tree-optimization/19661] " pinskia at gcc dot gnu dot org
  7 siblings, 0 replies; 9+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2005-01-28 18:53 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From pinskia at gcc dot gnu dot org  2005-01-28 18:53 -------
(In reply to comment #5)
> I'll move this bug back to the C++ component. 
Consider the following C++ code:
struct Foo { ~Foo() {} int i; };
struct A { Foo foo[2]; };
void foo () { 
  static A a; 
} 

We don't know the deconstructor for A is empty until we remove the empry loop and do optimizations 
on it.  So this is again a job for the midde-end/tree-optimizations.  We can then mark the function as 
empty and then have a pass (or really fold or something like that) remove calls to atexit (and similar 
functions) which just references empty functions.  This is the correct way of doing this.

-- 
           What    |Removed                     |Added
----------------------------------------------------------------------------
          Component|c++                         |middle-end
  GCC build triplet|n/a                         |
 GCC target triplet|n/a                         |


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


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

* [Bug middle-end/19661] unnecessary atexit calls emitted for static objects with empty destructors
  2005-01-27 22:24 [Bug c++/19661] New: many redundant atexit calls emitted into the executable for static objects with empty destructors yuri at tsoft dot com
                   ` (5 preceding siblings ...)
  2005-01-28 18:53 ` [Bug middle-end/19661] " pinskia at gcc dot gnu dot org
@ 2005-01-28 19:11 ` bangerth at dealii dot org
  2005-09-24 17:43 ` [Bug tree-optimization/19661] " pinskia at gcc dot gnu dot org
  7 siblings, 0 replies; 9+ messages in thread
From: bangerth at dealii dot org @ 2005-01-28 19:11 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From bangerth at dealii dot org  2005-01-28 19:11 -------
Why do you think the front-end doesn't know that the destructor is empty? 
It sees its definition, and it knows about potential destructors of 
member objects and base classes, so it should have all the information. 
That being said, I don't consider this to be such an important case as 
to pour a lot of passion into this discussion :-) 
 
W. 

-- 


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


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

* [Bug tree-optimization/19661] unnecessary atexit calls emitted for static objects with empty destructors
  2005-01-27 22:24 [Bug c++/19661] New: many redundant atexit calls emitted into the executable for static objects with empty destructors yuri at tsoft dot com
                   ` (6 preceding siblings ...)
  2005-01-28 19:11 ` bangerth at dealii dot org
@ 2005-09-24 17:43 ` pinskia at gcc dot gnu dot org
  7 siblings, 0 replies; 9+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2005-09-24 17:43 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From pinskia at gcc dot gnu dot org  2005-09-24 17:42 -------
Hmm, the easy way to to have a pass which finds all the atexit calls and sees if the function which is 
passed is a const function and if it is, then just remove the atexit call.

-- 
           What    |Removed                     |Added
----------------------------------------------------------------------------
          Component|middle-end                  |tree-optimization


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


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

end of thread, other threads:[~2005-09-24 17:43 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2005-01-27 22:24 [Bug c++/19661] New: many redundant atexit calls emitted into the executable for static objects with empty destructors yuri at tsoft dot com
2005-01-28  1:08 ` [Bug c++/19661] unnecessary atexit calls emitted " bangerth at dealii dot org
2005-01-28  1:22 ` [Bug middle-end/19661] " pinskia at gcc dot gnu dot org
2005-01-28  1:26 ` [Bug c++/19661] " yuri at tsoft dot com
2005-01-28  1:46 ` [Bug middle-end/19661] " pinskia at gcc dot gnu dot org
2005-01-28 17:02 ` [Bug c++/19661] " bangerth at dealii dot org
2005-01-28 18:53 ` [Bug middle-end/19661] " pinskia at gcc dot gnu dot org
2005-01-28 19:11 ` bangerth at dealii dot org
2005-09-24 17:43 ` [Bug tree-optimization/19661] " pinskia at gcc dot gnu dot 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).