public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc r12-1702] expand: empty class return optimization [PR88529]
@ 2021-06-21 14:50 Jason Merrill
  0 siblings, 0 replies; only message in thread
From: Jason Merrill @ 2021-06-21 14:50 UTC (permalink / raw)
  To: gcc-cvs

https://gcc.gnu.org/g:7232f7c4c2d727431096a7ecfcf4ad4db71dcf2a

commit r12-1702-g7232f7c4c2d727431096a7ecfcf4ad4db71dcf2a
Author: Jason Merrill <jason@redhat.com>
Date:   Sun Jun 13 14:00:12 2021 -0400

    expand: empty class return optimization [PR88529]
    
    The x86_64 psABI says that an empty class isn't passed or returned in memory
    or registers, so we shouldn't set %eax in this function.
    
    The df-scan hunk catches the case where we look at a 0-length reg and build
    a range the length of unsigned int, which happened before I changed
    assign_parms to match expand_function_end.
    
            PR target/88529
    
    gcc/ChangeLog:
    
            * df-scan.c (df_ref_record): Check that regno < endregno.
            * function.c (assign_parms, expand_function_end): Do nothing with a
            TYPE_EMPTY_P result.
    
    gcc/testsuite/ChangeLog:
    
            * g++.target/i386/empty-class1.C: New test.

Diff:
---
 gcc/df-scan.c                                |  2 ++
 gcc/function.c                               | 16 ++++++++++------
 gcc/testsuite/g++.target/i386/empty-class1.C |  9 +++++++++
 3 files changed, 21 insertions(+), 6 deletions(-)

diff --git a/gcc/df-scan.c b/gcc/df-scan.c
index 1268536b3f0..e9da64ff3df 100644
--- a/gcc/df-scan.c
+++ b/gcc/df-scan.c
@@ -2595,6 +2595,8 @@ df_ref_record (enum df_ref_class cl,
 	    ref_flags |= DF_REF_PARTIAL;
 	  ref_flags |= DF_REF_MW_HARDREG;
 
+	  gcc_assert (regno < endregno);
+
 	  hardreg = problem_data->mw_reg_pool->allocate ();
 	  hardreg->type = ref_type;
 	  hardreg->flags = ref_flags;
diff --git a/gcc/function.c b/gcc/function.c
index 67576950983..6abaf3d116f 100644
--- a/gcc/function.c
+++ b/gcc/function.c
@@ -3821,9 +3821,11 @@ assign_parms (tree fndecl)
       tree decl_result = DECL_RESULT (fndecl);
       rtx decl_rtl = DECL_RTL (decl_result);
 
-      if (REG_P (decl_rtl)
-	  ? REGNO (decl_rtl) >= FIRST_PSEUDO_REGISTER
-	  : DECL_REGISTER (decl_result))
+      if ((REG_P (decl_rtl)
+	   ? REGNO (decl_rtl) >= FIRST_PSEUDO_REGISTER
+	   : DECL_REGISTER (decl_result))
+	  /* Unless the psABI says not to.  */
+	  && !TYPE_EMPTY_P (TREE_TYPE (decl_result)))
 	{
 	  rtx real_decl_rtl;
 
@@ -5410,9 +5412,11 @@ expand_function_end (void)
       tree decl_result = DECL_RESULT (current_function_decl);
       rtx decl_rtl = DECL_RTL (decl_result);
 
-      if (REG_P (decl_rtl)
-	  ? REGNO (decl_rtl) >= FIRST_PSEUDO_REGISTER
-	  : DECL_REGISTER (decl_result))
+      if ((REG_P (decl_rtl)
+	   ? REGNO (decl_rtl) >= FIRST_PSEUDO_REGISTER
+	   : DECL_REGISTER (decl_result))
+	  /* Unless the psABI says not to.  */
+	  && !TYPE_EMPTY_P (TREE_TYPE (decl_result)))
 	{
 	  rtx real_decl_rtl = crtl->return_rtx;
 	  complex_mode cmode;
diff --git a/gcc/testsuite/g++.target/i386/empty-class1.C b/gcc/testsuite/g++.target/i386/empty-class1.C
new file mode 100644
index 00000000000..c1992772d26
--- /dev/null
+++ b/gcc/testsuite/g++.target/i386/empty-class1.C
@@ -0,0 +1,9 @@
+// PR target/88529
+// { dg-do compile { target { c++11 && x86_64-*-* } } }
+// { dg-additional-options -fdump-rtl-expand }
+// { dg-final { scan-rtl-dump-not "set" "expand" } }
+// The x86_64 psABI says that f() doesn't put the return value anywhere.
+
+class A{};
+
+A f() { return {}; }


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2021-06-21 14:50 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-06-21 14:50 [gcc r12-1702] expand: empty class return optimization [PR88529] Jason Merrill

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