This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[PATCH] gcc 8: Implement -felide-function-bodies


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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]