public inbox for gcc@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH] gcc 8: Implement -felide-function-bodies
@ 2017-04-01  4:30 David Malcolm
  2017-04-01  5:56 ` Markus Trippelsdorf
  2017-04-01 16:33 ` Gerald Pfeifer
  0 siblings, 2 replies; 4+ messages in thread
From: David Malcolm @ 2017-04-01  4:30 UTC (permalink / raw)
  To: gcc; +Cc: David Malcolm

The following patch implements a new function-body-elision
optimization, which can dramatically improve performance,
especially under certain benchmarks.

For example, given this test program...

$ cat test.c

int factorial (int i)
{
  if (i > 1)
    return i * factorial (i - 1);
  else
    return 1;
}

int main (int argc, const char *argv[])
{
  return factorial (atoi (argv[1]));
}

...it improves performance:

$ time ./without-elision 50000

real	0m0.007s
user	0m0.003s
sys	0m0.003s

$ time ./with-elision 50000

real	0m0.003s
user	0m0.000s
sys	0m0.002s

and can even bulletproof the code against certain crashes:

$ time ./without-elision 20170401
Segmentation fault (core dumped)

real	0m0.159s
user	0m0.003s
sys	0m0.027s

$ time ./with-elision 20170401

real	0m0.003s
user	0m0.000s
sys	0m0.003s

It should be interesting to see what effect this has on
other benchmarks.

Dave

gcc/ChangeLog:
	* common.opt (felide-function-bodies): New option.
	* gimplify.c (gimplify_body): Implement function-body
	elision.
---
 gcc/common.opt | 4 ++++
 gcc/gimplify.c | 3 +++
 2 files changed, 7 insertions(+)

diff --git a/gcc/common.opt b/gcc/common.opt
index 4021622..a32a56d 100644
--- a/gcc/common.opt
+++ b/gcc/common.opt
@@ -1299,6 +1299,10 @@ fipa-sra
 Common Report Var(flag_ipa_sra) Init(0) Optimization
 Perform interprocedural reduction of aggregates.
 
+felide-function-bodies
+Common Optimization Var(flag_elide_function_bodies)
+Perform function body elision optimization
+
 feliminate-unused-debug-symbols
 Common Report Var(flag_debug_only_used_symbols)
 Perform unused symbol elimination in debug info.
diff --git a/gcc/gimplify.c b/gcc/gimplify.c
index fbf136f..4853953 100644
--- a/gcc/gimplify.c
+++ b/gcc/gimplify.c
@@ -12390,6 +12390,9 @@ gimplify_body (tree fndecl, bool do_parms)
      the body so that DECL_VALUE_EXPR gets processed correctly.  */
   parm_stmts = do_parms ? gimplify_parameters () : NULL;
 
+  if (flag_elide_function_bodies)
+    DECL_SAVED_TREE (fndecl) = NULL_TREE;
+
   /* Gimplify the function's body.  */
   seq = NULL;
   gimplify_stmt (&DECL_SAVED_TREE (fndecl), &seq);
-- 
1.8.5.3

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

end of thread, other threads:[~2017-04-01 22:07 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-04-01  4:30 [PATCH] gcc 8: Implement -felide-function-bodies David Malcolm
2017-04-01  5:56 ` Markus Trippelsdorf
2017-04-01 16:33 ` Gerald Pfeifer
2017-04-01 22:07   ` David Malcolm

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