public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug rtl-optimization/19560] New: Adding -g disables -foptimize-sibling-calls optimization in some cases
@ 2005-01-21 10:12 gcc-bugzilla at gcc dot gnu dot org
  2005-01-21 10:47 ` [Bug rtl-optimization/19560] " ebotcazou at gcc dot gnu dot org
  0 siblings, 1 reply; 2+ messages in thread
From: gcc-bugzilla at gcc dot gnu dot org @ 2005-01-21 10:12 UTC (permalink / raw)
  To: gcc-bugs


	With the option -foptimize-sibling-calls tail recursion is
        performed. Adding -g destroys this optimization. In my opinion,
        adding compiler option -g should not change the behaviour of
        the compiled program.

Environment:
System: SunOS rungner.nada.kth.se 5.9 Generic_117171-07 sun4u sparc SUNW,Sun-Fire-280R
Architecture: sun4

	
host: sparc-sun-solaris2.9
build: sparc-sun-solaris2.9
target: sparc-sun-solaris2.9
configured with: /afs/.nada.kth.se/pkg/gcc/src/3.4.2/gcc-3.4.2/configure --prefix=/pkg/gcc/3.4.2/os

How-To-Repeat:
	Compile the following program:

/*
 * In this function, it seems that tail recursion is performed both with
 *
 *   gcc -foptimize-sibling-calls -S tail.c 
 *
 * and with
 *
 *   gcc -g -foptimize-sibling-calls -S tail.c 
 *
 * using gcc 3.4.2 on a SPARC.
 */
void f(int n)
{
    if(n > 0)
	f(--n);
}

/*
 * In this function, it seems that tail recursion is performed with
 *
 *   gcc -foptimize-sibling-calls -S tail.c 
 *
 * but not with
 *
 *   gcc -g -foptimize-sibling-calls -S tail.c 
 *
 * using gcc 3.4.2 on a SPARC.
 */
void g(int n)
{
    if(n > 0)
	f(--n);
    return;
}

int main(int argc, char **argv)
{
    f(10);
    g(10);
}



	(Preprocessor output is included below.)
	For the function f(), the assembler output ends with


	call	f, 0
	 restore
.LL1:
	nop
	ret
	restore
.LLFE2:
	.size	f, .-f


	both with and without compiler option -g. For the function
        g(), however, the assembler output ends with


	call	f, 0
	 restore
.LL3:
	nop
	ret
	restore
	.size	g, .-g


        if "-g" is *not* used, and with


	call	f, 0
	 nop
.LL3:
	nop
	ret
	restore
.LLFE3:
	.size	g, .-g


	if "-g" *is* used. And now the preprocessor output:

# 1 "tail.c"
# 1 "<built-in>"
# 1 "<command line>"
# 1 "tail.c"
# 27 "tail.c"
void f(int n)
{
    if(n > 0)
 f(--n);
}
# 44 "tail.c"
void g(int n)
{
    if(n > 0)
 f(--n);
    return;
}

int main(int argc, char **argv)
{
    f(10);
    g(10);
}
------- Additional Comments From enge at nada dot kth dot se  2005-01-21 10:12 -------
Fix:
	I do not know of a fix.

-- 
           Summary: Adding -g disables -foptimize-sibling-calls optimization
                    in some cases
           Product: gcc
           Version: 3.4.2
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: rtl-optimization
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: enge at nada dot kth dot se
                CC: gcc-bugs at gcc dot gnu dot org
 GCC build triplet: sparc-sun-solaris2.9
  GCC host triplet: sparc-sun-solaris2.9
GCC target triplet: sparc-sun-solaris2.9


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


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

* [Bug rtl-optimization/19560] Adding -g disables -foptimize-sibling-calls optimization in some cases
  2005-01-21 10:12 [Bug rtl-optimization/19560] New: Adding -g disables -foptimize-sibling-calls optimization in some cases gcc-bugzilla at gcc dot gnu dot org
@ 2005-01-21 10:47 ` ebotcazou at gcc dot gnu dot org
  0 siblings, 0 replies; 2+ messages in thread
From: ebotcazou at gcc dot gnu dot org @ 2005-01-21 10:47 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From ebotcazou at gcc dot gnu dot org  2005-01-21 10:47 -------
Fixed in GCC 3.4.3 by

2004-09-14  Richard Henderson  <rth@redhat.com>

	* sibcall.c (call_ends_block_p): Fix thinko finding the
	last real insn in a block.

Thanks for the bug report.


-- 
           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |ebotcazou at gcc dot gnu dot
                   |                            |org
             Status|UNCONFIRMED                 |RESOLVED
         Resolution|                            |FIXED
   Target Milestone|---                         |3.4.3


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


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

end of thread, other threads:[~2005-01-21 10:47 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2005-01-21 10:12 [Bug rtl-optimization/19560] New: Adding -g disables -foptimize-sibling-calls optimization in some cases gcc-bugzilla at gcc dot gnu dot org
2005-01-21 10:47 ` [Bug rtl-optimization/19560] " ebotcazou 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).