public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Jakub Jelinek <jakub@redhat.com>
To: Richard Biener <rguenther@suse.de>, Jan Hubicka <jh@suse.cz>
Cc: gcc-patches@gcc.gnu.org
Subject: [PATCH] symtab-thunks: Use aggregate_value_p even on is_gimple_reg_type returns [PR112941]
Date: Fri, 22 Dec 2023 09:21:30 +0100	[thread overview]
Message-ID: <ZYVHCsf63PsOhpIS@tucnak> (raw)

Hi!

Large/huge _BitInt types are returned in memory and the bitint lowering
pass right now relies on that.
The gimplification etc. use aggregate_value_p to see if it should be
returned in memory or not and use
  <retval> = _123;
  return <retval>;
rather than
  return _123;
But expand_thunk used e.g. by IPA-ICF was performing an optimization,
assuming is_gimple_reg_type is always passed in registers and not calling
aggregate_value_p in that case.  The following patch changes it to match
what the gimplification etc. are doing.

Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk?

2023-12-22  Jakub Jelinek  <jakub@redhat.com>

	PR tree-optimization/112941
	* symtab-thunks.cc (expand_thunk): Check aggregate_value_p regardless
	of whether is_gimple_reg_type (restype) or not.

	* gcc.dg/bitint-60.c: New test.

--- gcc/symtab-thunks.cc.jj	2023-08-24 15:37:28.698418172 +0200
+++ gcc/symtab-thunks.cc	2023-12-21 16:42:41.406127267 +0100
@@ -479,21 +479,15 @@ expand_thunk (cgraph_node *node, bool ou
 				 resdecl,
 				 build_int_cst (TREE_TYPE (resdecl), 0));
 	    }
-	  else if (!is_gimple_reg_type (restype))
+	  else if (aggregate_value_p (resdecl, TREE_TYPE (thunk_fndecl)))
 	    {
-	      if (aggregate_value_p (resdecl, TREE_TYPE (thunk_fndecl)))
-		{
-		  restmp = resdecl;
+	      restmp = resdecl;
 
-		  if (VAR_P (restmp))
-		    {
-		      add_local_decl (cfun, restmp);
-		      BLOCK_VARS (DECL_INITIAL (current_function_decl))
-			= restmp;
-		    }
+	      if (VAR_P (restmp))
+		{
+		  add_local_decl (cfun, restmp);
+		  BLOCK_VARS (DECL_INITIAL (current_function_decl)) = restmp;
 		}
-	      else
-		restmp = create_tmp_var (restype, "retval");
 	    }
 	  else
 	    restmp = create_tmp_reg (restype, "retval");
--- gcc/testsuite/gcc.dg/bitint-60.c.jj	2023-12-21 16:49:41.289298560 +0100
+++ gcc/testsuite/gcc.dg/bitint-60.c	2023-12-21 16:49:09.061746003 +0100
@@ -0,0 +1,20 @@
+/* PR tree-optimization/112941 */
+/* { dg-do compile { target bitint575 } } */
+/* { dg-options "-O2 -std=c23" } */
+
+unsigned _BitInt(495) f1 (signed _BitInt(381) x) { unsigned _BitInt(539) y = x; return y; }
+unsigned _BitInt(495) f2 (unsigned _BitInt(381) x) { unsigned _BitInt(539) y = x; return y; }
+unsigned _BitInt(495) f3 (signed _BitInt(381) x) { _BitInt(539) y = x; return y; }
+unsigned _BitInt(495) f4 (unsigned _BitInt(381) x) { _BitInt(539) y = x; return y; }
+_BitInt(495) f5 (signed _BitInt(381) x) { unsigned _BitInt(539) y = x; return y; }
+_BitInt(495) f6 (unsigned _BitInt(381) x) { unsigned _BitInt(539) y = x; return y; }
+_BitInt(495) f7 (signed _BitInt(381) x) { _BitInt(539) y = x; return y; }
+_BitInt(495) f8 (unsigned _BitInt(381) x) { _BitInt(539) y = x; return y; }
+unsigned _BitInt(495) f9 (signed _BitInt(381) x) { return (unsigned _BitInt(539)) x; }
+unsigned _BitInt(495) f10 (unsigned _BitInt(381) x) { return (unsigned _BitInt(539)) x; }
+unsigned _BitInt(495) f11 (signed _BitInt(381) x) { return (_BitInt(539)) x; }
+unsigned _BitInt(495) f12 (unsigned _BitInt(381) x) { return (_BitInt(539)) x; }
+_BitInt(495) f13 (signed _BitInt(381) x) { return (unsigned _BitInt(539)) x; }
+_BitInt(495) f14 (unsigned _BitInt(381) x) { return (unsigned _BitInt(539)) x; }
+_BitInt(495) f15 (signed _BitInt(381) x) { return (_BitInt(539)) x; }
+_BitInt(495) f16 (unsigned _BitInt(381) x) { return (_BitInt(539)) x; }

	Jakub


             reply	other threads:[~2023-12-22  8:21 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-12-22  8:21 Jakub Jelinek [this message]
2023-12-22 10:09 ` Richard Biener

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=ZYVHCsf63PsOhpIS@tucnak \
    --to=jakub@redhat.com \
    --cc=gcc-patches@gcc.gnu.org \
    --cc=jh@suse.cz \
    --cc=rguenther@suse.de \
    /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).