public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug tree-optimization/30927]  New: tree-nested creates pointless static chains and trampolines when the callgraph is non-trivial
@ 2007-02-22 17:33 baldrick at gcc dot gnu dot org
  2007-02-22 17:40 ` [Bug tree-optimization/30927] " ebotcazou at gcc dot gnu dot org
                   ` (8 more replies)
  0 siblings, 9 replies; 10+ messages in thread
From: baldrick at gcc dot gnu dot org @ 2007-02-22 17:33 UTC (permalink / raw)
  To: gcc-bugs

If a nested subroutine calls another nested subroutine that follows it
lexically, then convert_all_function_calls will force the called function to
take a static chain even though it may not need one.  The most trivial example
of this is a recursive nested subroutine, as in example n1.c:

void n1(void) { void a(void) { a(); } }

$ gcc -c n1.c -fdump-tree-nested
$ grep chain n1.c.*nested
  a () [static-chain: CHAIN.1];
A pointless static chain has been created.

Here's an example n2.c in which the caller and callee disagree about whether a
static chain is needed or not: the caller thinks it is needed, the callee does
not.

void n2(void) {
  auto void a(void);
  void b(void) { a(); }
  void a(void) {}
}

This might seem fairly harmless, but can become expensive when trampolines are
needlessly created.  Example n3.c:

void n3(void) {
  auto void a(void *);
  void b(void) { a(b); }
  void a(void *f) {}
}
$ gcc -c n3.c -fdump-tree-nested
$ grep trampoline n3.c.*nested
  struct __builtin_trampoline * D.1631;
  D.1632 = __builtin_adjust_trampoline (D.1631);
  __builtin_init_trampoline (&FRAME.0.b, b, &FRAME.0);

In Ada, nested subroutines are widely used, and unneeded static chains are
frequently being created by gcc: I first noticed this problem while
bootstrapping the compiler with a patch that happened to print a warning in
case n2.c: the warning fired hundreds of times during the Ada build.  The most
common reason for this seems to be due to the instantiation of generic packages
inside library level procedures.


-- 
           Summary: tree-nested creates pointless static chains and
                    trampolines when the callgraph is non-trivial
           Product: gcc
           Version: 4.3.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: tree-optimization
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: baldrick at gcc dot gnu dot org


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


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

end of thread, other threads:[~2009-09-16 18:55 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2007-02-22 17:33 [Bug tree-optimization/30927] New: tree-nested creates pointless static chains and trampolines when the callgraph is non-trivial baldrick at gcc dot gnu dot org
2007-02-22 17:40 ` [Bug tree-optimization/30927] " ebotcazou at gcc dot gnu dot org
2007-03-15 14:49 ` baldrick at gcc dot gnu dot org
2007-03-15 15:12 ` ebotcazou at gcc dot gnu dot org
2007-03-15 15:16 ` baldrick at free dot fr
2007-03-15 15:35 ` baldrick at free dot fr
2007-03-15 19:45 ` baldrick at gcc dot gnu dot org
2007-03-21  9:31 ` ebotcazou at gcc dot gnu dot org
2008-01-10 19:12 ` baldrick at gcc dot gnu dot org
2009-09-16 18:55 ` rth 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).