public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Richard Biener <rguenther@suse.de>
To: gcc-patches@gcc.gnu.org
Subject: [PATCH] Elide return during inlining when possible
Date: Thu, 28 Nov 2019 12:33:00 -0000	[thread overview]
Message-ID: <nycvar.YFH.7.76.1911281323120.5566@zhemvz.fhfr.qr> (raw)


Also from investigating the abstraction penalty in PR92645 I noticed
we create pointless stmts to copy the return value to the result decl
at the return.  That's not needed if the call doesn't have a LHS.

Bootstrapped and tested on x86_64-unknown-linux-gnu, applied to trunk.

Richard.

2019-11-28  Richard Biener  <rguenther@suse.de>

	PR tree-optimization/92645
	* tree-inline.c (remap_gimple_stmt): When the return value
	is not wanted, elide GIMPLE_RETURN.

	* gcc.dg/tree-ssa/inline-12.c: New testcase.

Index: gcc/tree-inline.c
===================================================================
--- gcc/tree-inline.c	(revision 278765)
+++ gcc/tree-inline.c	(working copy)
@@ -1541,9 +1541,12 @@ remap_gimple_stmt (gimple *stmt, copy_bo
 	 assignment to the equivalent of the original RESULT_DECL.
 	 If RETVAL is just the result decl, the result decl has
 	 already been set (e.g. a recent "foo (&result_decl, ...)");
-	 just toss the entire GIMPLE_RETURN.  */
+	 just toss the entire GIMPLE_RETURN.  Likewise for when the
+	 call doesn't want the return value.  */
       if (retval
 	  && (TREE_CODE (retval) != RESULT_DECL
+	      && (!id->call_stmt
+		  || gimple_call_lhs (id->call_stmt) != NULL_TREE)
 	      && (TREE_CODE (retval) != SSA_NAME
 		  || ! SSA_NAME_VAR (retval)
 		  || TREE_CODE (SSA_NAME_VAR (retval)) != RESULT_DECL)))
Index: gcc/testsuite/gcc.dg/tree-ssa/inline-12.c
===================================================================
--- gcc/testsuite/gcc.dg/tree-ssa/inline-12.c	(nonexistent)
+++ gcc/testsuite/gcc.dg/tree-ssa/inline-12.c	(working copy)
@@ -0,0 +1,22 @@
+/* { dg-do compile } */
+/* { dg-options "-O -fdump-tree-einline" } */
+
+void *foo (void *, int);
+static inline void *mcp (void *src, int i)
+{
+  return foo (src, i);
+}
+void bar()
+{
+  int i;
+  mcp (&i, 0);
+}
+
+/* There should be exactly two assignments, one for both
+   the original foo call and the inlined copy (plus a clobber
+   that doesn't match here).  In particular bar should look like
+     <bb 2> :
+     _4 = foo (&i, 0);
+     i ={v} {CLOBBER};
+     return;  */
+/* { dg-final { scan-tree-dump-times " = " 2 "einline" } } */

                 reply	other threads:[~2019-11-28 12:24 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=nycvar.YFH.7.76.1911281323120.5566@zhemvz.fhfr.qr \
    --to=rguenther@suse.de \
    --cc=gcc-patches@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).