public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Alexandre Oliva <aoliva@redhat.com>
To: Andreas Schwab <schwab@linux-m68k.org>
Cc: Patrick Marlier <patrick.marlier@gmail.com>,
	Jeff Law <law@redhat.com>,
	       James Greenhalgh <james.greenhalgh@arm.com>,
	       "H.J. Lu" <hjl.tools@gmail.com>,
	       Segher Boessenkool <segher@kernel.crashing.org>,
	       Richard Biener <richard.guenther@gmail.com>,
	       GCC Patches <gcc-patches@gcc.gnu.org>,
	       Christophe Lyon <christophe.lyon@linaro.org>,
	       David Edelsohn <dje.gcc@gmail.com>,
	       Eric Botcazou <ebotcazou@adacore.com>
Subject: Re: [PR64164] drop copyrename, integrate into expand
Date: Mon, 17 Aug 2015 02:57:00 -0000	[thread overview]
Message-ID: <orvbce3ane.fsf@livre.home> (raw)
In-Reply-To: <m2oai78sog.fsf@linux-m68k.org> (Andreas Schwab's message of	"Sun, 16 Aug 2015 11:54:23 +0200")

On Aug 16, 2015, Andreas Schwab <schwab@linux-m68k.org> wrote:

> On m68k:
> FAIL: gcc.c-torture/execute/20050316-1.c   -O0  execution test
> FAIL: gcc.c-torture/execute/20050316-2.c   -O0  execution test
> FAIL: gcc.c-torture/execute/20050316-3.c   -O0  execution test
> FAIL: gcc.c-torture/execute/simd-4.c   -O0  execution test
> FAIL: gcc.c-torture/execute/simd-6.c   -O0  execution test
> FAIL: gcc.dg/compat/vector-1 c_compat_x_tst.o-c_compat_y_tst.o execute

Thanks.  Interesting.  This exposes a more general situation than the
one I covered with the byref params: the general case does not require
the params to be passed by reference, but rather that the params require
a stack address that, if determined by cfgexpand, will cause them to be
computed too late for assign_parms' use.  The following patch appears to
fix the problem, applying the same logic of limited coalescing and
deferred address assignment to all params that can't live in pseudos,
and extending assign_parms' remaining case of copying incoming params to
new stack slots to fill in the blank address with that of the
newly-allocated stack slot.

Would you be so kind as to give it a spin on a m68k native?  TIA,


diff --git a/gcc/cfgexpand.c b/gcc/cfgexpand.c
index 0bc20f6..56571ce 100644
--- a/gcc/cfgexpand.c
+++ b/gcc/cfgexpand.c
@@ -172,17 +172,23 @@ leader_merge (tree cur, tree next)
   return cur;
 }
 
-/* Return true if VAR is a PARM_DECL or a RESULT_DECL of type BLKmode.
+/* Return true if VAR is a PARM_DECL or a RESULT_DECL that ought to be
+   assigned to a stack slot.  We can't have expand_one_ssa_partition
+   choose their address: the pseudo holding the address would be set
+   up too late for assign_params to copy the parameter if needed.
+
    Such parameters are likely passed as a pointer to the value, rather
    than as a value, and so we must not coalesce them, nor allocate
    stack space for them before determining the calling conventions for
-   them.  For their SSA_NAMEs, expand_one_ssa_partition emits RTL as
-   MEMs with pc_rtx as the address, and then it replaces the pc_rtx
-   with NULL so as to make sure the MEM is not used before it is
-   adjusted in assign_parm_setup_reg.  */
+   them.
+
+   For their SSA_NAMEs, expand_one_ssa_partition emits RTL as MEMs
+   with pc_rtx as the address, and then it replaces the pc_rtx with
+   NULL so as to make sure the MEM is not used before it is adjusted
+   in assign_parm_setup_reg.  */
 
 bool
-parm_maybe_byref_p (tree var)
+parm_in_stack_slot_p (tree var)
 {
   if (!var || VAR_P (var))
     return false;
@@ -190,7 +196,7 @@ parm_maybe_byref_p (tree var)
   gcc_assert (TREE_CODE (var) == PARM_DECL
 	      || TREE_CODE (var) == RESULT_DECL);
 
-  return TYPE_MODE (TREE_TYPE (var)) == BLKmode;
+  return !use_register_for_decl (var);
 }
 
 /* Return the partition of the default SSA_DEF for decl VAR.  */
@@ -1343,13 +1349,15 @@ expand_one_ssa_partition (tree var)
 
   if (!use_register_for_decl (var))
     {
-      if (parm_maybe_byref_p (SSA_NAME_VAR (var))
+      /* We can't risk having the parm assigned to a MEM location
+	 whose address references a pseudo, for the pseudo will only
+	 be set up after arguments are copied to the stack slot.  */
+      if (parm_in_stack_slot_p (SSA_NAME_VAR (var))
 	  && ssa_default_def_partition (SSA_NAME_VAR (var)) == part)
 	{
 	  expand_one_stack_var_at (var, pc_rtx, 0, 0);
 	  rtx x = SA.partition_to_pseudo[part];
 	  gcc_assert (GET_CODE (x) == MEM);
-	  gcc_assert (GET_MODE (x) == BLKmode);
 	  gcc_assert (XEXP (x, 0) == pc_rtx);
 	  /* Reset the address, so that any attempt to use it will
 	     ICE.  It will be adjusted in assign_parm_setup_reg.  */
diff --git a/gcc/cfgexpand.h b/gcc/cfgexpand.h
index 987cf356..d168672 100644
--- a/gcc/cfgexpand.h
+++ b/gcc/cfgexpand.h
@@ -22,7 +22,7 @@ along with GCC; see the file COPYING3.  If not see
 
 extern tree gimple_assign_rhs_to_tree (gimple);
 extern HOST_WIDE_INT estimated_stack_frame_size (struct cgraph_node *);
-extern bool parm_maybe_byref_p (tree);
+extern bool parm_in_stack_slot_p (tree);
 extern rtx get_rtl_for_parm_ssa_default_def (tree var);
 
 
diff --git a/gcc/function.c b/gcc/function.c
index 715c19f..eccd8c6 100644
--- a/gcc/function.c
+++ b/gcc/function.c
@@ -2934,6 +2934,16 @@ assign_parm_setup_block_p (struct assign_parm_data_one *data)
   return false;
 }
 
+static bool
+parm_in_unassigned_mem_p (tree decl, rtx from_expand)
+{
+  bool result = MEM_P (from_expand) && !XEXP (from_expand, 0);
+
+  gcc_assert (result == parm_in_stack_slot_p (decl));
+
+  return result;
+}
+
 /* A subroutine of assign_parms.  Arrange for the parameter to be
    present and valid in DATA->STACK_RTL.  */
 
@@ -2956,8 +2966,7 @@ assign_parm_setup_block (struct assign_parm_data_all *all,
     {
       DECL_ALIGN (parm) = MAX (DECL_ALIGN (parm), BITS_PER_WORD);
       rtx from_expand = rtl_for_parm (all, parm);
-      if (from_expand && (!parm_maybe_byref_p (parm)
-			  || XEXP (from_expand, 0) != NULL_RTX))
+      if (from_expand && !parm_in_unassigned_mem_p (parm, from_expand))
 	stack_parm = copy_rtx (from_expand);
       else
 	{
@@ -2968,8 +2977,7 @@ assign_parm_setup_block (struct assign_parm_data_all *all,
 	  if (from_expand)
 	    {
 	      gcc_assert (GET_CODE (stack_parm) == MEM);
-	      gcc_assert (GET_CODE (from_expand) == MEM);
-	      gcc_assert (XEXP (from_expand, 0) == NULL_RTX);
+	      gcc_assert (parm_in_unassigned_mem_p (parm, from_expand));
 	      XEXP (from_expand, 0) = XEXP (stack_parm, 0);
 	      PUT_MODE (from_expand, GET_MODE (stack_parm));
 	      stack_parm = copy_rtx (from_expand);
@@ -3121,7 +3129,7 @@ assign_parm_setup_reg (struct assign_parm_data_all *all, tree parm,
       if (GET_MODE (parmreg) != promoted_nominal_mode)
 	parmreg = gen_lowpart (promoted_nominal_mode, parmreg);
     }
-  else if (!from_expand || parm_maybe_byref_p (parm))
+  else if (!from_expand || parm_in_unassigned_mem_p (parm, from_expand))
     {
       parmreg = gen_reg_rtx (promoted_nominal_mode);
       if (!DECL_ARTIFICIAL (parm))
@@ -3349,7 +3357,7 @@ assign_parm_setup_reg (struct assign_parm_data_all *all, tree parm,
 	  did_conversion = true;
 	}
       else if (GET_MODE (parmreg) == BLKmode)
-	gcc_assert (parm_maybe_byref_p (parm));
+	gcc_assert (parm_in_stack_slot_p (parm));
       else
 	emit_move_insn (parmreg, src);
 
@@ -3455,12 +3463,15 @@ assign_parm_setup_stack (struct assign_parm_data_all *all, tree parm,
   if (data->entry_parm != data->stack_parm)
     {
       rtx src, dest;
+      rtx from_expand = NULL_RTX;
 
       if (data->stack_parm == 0)
 	{
-	  rtx x = data->stack_parm = rtl_for_parm (all, parm);
-	  if (x)
-	    gcc_assert (GET_MODE (x) == GET_MODE (data->entry_parm));
+	  from_expand = rtl_for_parm (all, parm);
+	  if (from_expand)
+	    gcc_assert (GET_MODE (from_expand) == GET_MODE (data->entry_parm));
+	  else if (!parm_in_unassigned_mem_p (parm, from_expand))
+	    data->stack_parm = from_expand;
 	}
 
       if (data->stack_parm == 0)
@@ -3472,7 +3483,16 @@ assign_parm_setup_stack (struct assign_parm_data_all *all, tree parm,
 	    = assign_stack_local (GET_MODE (data->entry_parm),
 				  GET_MODE_SIZE (GET_MODE (data->entry_parm)),
 				  align);
-	  set_mem_attributes (data->stack_parm, parm, 1);
+	  if (!from_expand)
+	    set_mem_attributes (data->stack_parm, parm, 1);
+	  else
+	    {
+	      gcc_assert (GET_CODE (data->stack_parm) == MEM);
+	      gcc_assert (parm_in_unassigned_mem_p (parm, from_expand));
+	      XEXP (from_expand, 0) = XEXP (data->stack_parm, 0);
+	      PUT_MODE (from_expand, GET_MODE (data->stack_parm));
+	      data->stack_parm = copy_rtx (from_expand);
+	    }
 	}
 
       dest = validize_mem (copy_rtx (data->stack_parm));
diff --git a/gcc/tree-ssa-coalesce.c b/gcc/tree-ssa-coalesce.c
index 08ce72c..6468012 100644
--- a/gcc/tree-ssa-coalesce.c
+++ b/gcc/tree-ssa-coalesce.c
@@ -1386,8 +1386,8 @@ gimple_can_coalesce_p (tree name1, tree name2)
 	 because it may be passed by reference.  */
       return ((!var1 || VAR_P (var1)) && (!var2 || VAR_P (var2)))
 	|| (/* The case var1 == var2 is already covered above.  */
-	    !parm_maybe_byref_p (var1)
-	    && !parm_maybe_byref_p (var2)
+	    !parm_in_stack_slot_p (var1)
+	    && !parm_in_stack_slot_p (var2)
 	    && promote_ssa_mode (name1, NULL) == promote_ssa_mode (name2, NULL));
     }
 


-- 
Alexandre Oliva, freedom fighter    http://FSFLA.org/~lxoliva/
You must be the change you wish to see in the world. -- Gandhi
Be Free! -- http://FSFLA.org/   FSF Latin America board member
Free Software Evangelist|Red Hat Brasil GNU Toolchain Engineer

  reply	other threads:[~2015-08-17  2:35 UTC|newest]

Thread overview: 127+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-03-27 18:04 Alexandre Oliva
2015-03-27 18:11 ` Alexandre Oliva
2015-03-28 19:22 ` Alexandre Oliva
2015-03-31  5:11   ` Jeff Law
2015-04-03 13:17     ` Alexandre Oliva
2015-04-06 16:08       ` Jeff Law
2015-04-24  1:56         ` Alexandre Oliva
2015-04-27 11:39           ` Richard Biener
2015-06-06  5:12             ` Alexandre Oliva
2015-06-08  8:16               ` Richard Biener
2015-06-09  8:58                 ` Christophe Lyon
2015-06-10  0:28               ` Alexandre Oliva
2015-06-10 13:36                 ` Richard Biener
2015-07-16  7:58                   ` Alexandre Oliva
2015-07-16  8:50                     ` Richard Biener
2015-07-16 21:33                       ` Alexandre Oliva
2015-07-18  8:26                         ` Alexandre Oliva
2015-07-21 13:25                           ` Richard Biener
2015-07-22 17:13                             ` Alexandre Oliva
2015-07-22 17:43                             ` Alexandre Oliva
2015-07-23 11:04                               ` Richard Biener
2015-07-23 15:42                                 ` Alexandre Oliva
2015-07-23 20:35                                   ` Segher Boessenkool
2015-07-23 21:24                                     ` H.J. Lu
2015-07-23 22:11                                       ` H.J. Lu
2015-07-24  1:31                                         ` David Edelsohn
2015-07-24  5:08                                           ` H.J. Lu
2015-07-24  9:26                                             ` Richard Biener
2015-07-24 12:50                                               ` H.J. Lu
2015-07-24 20:20                                           ` Alexandre Oliva
2015-07-25  2:37                                             ` David Edelsohn
2015-07-27 22:16                                               ` Alexandre Oliva
2015-07-27 22:31                                                 ` H.J. Lu
2015-07-24 18:51                                         ` Alexandre Oliva
2015-07-24 19:12                                           ` H.J. Lu
2015-07-24 19:31                                             ` David Edelsohn
2015-07-24 20:43                                               ` Alexandre Oliva
2015-07-24 20:47                                             ` Alexandre Oliva
2015-07-24 21:53                                               ` H.J. Lu
2015-07-25  7:17                                                 ` Richard Biener
2015-07-29 20:52                                         ` Alexandre Oliva
2015-07-29 21:06                                           ` H.J. Lu
2015-07-30 17:47                                             ` H.J. Lu
2015-08-03 23:46                                               ` Alexandre Oliva
2015-08-04  9:48                                                 ` Richard Biener
2015-08-05  0:39                                                   ` Alexandre Oliva
2015-08-05  9:14                                                     ` Richard Biener
2015-08-05 23:03                                                       ` Alexandre Oliva
2015-08-10  8:24                                                 ` James Greenhalgh
2015-08-10 15:14                                                   ` Jeff Law
2015-08-11  4:53                                                     ` Patrick Marlier
2015-08-14 19:03                                                       ` Alexandre Oliva
2015-08-15  8:57                                                         ` Andreas Schwab
2015-08-16 13:00                                                           ` Alexandre Oliva
     [not found]                                                             ` <m2k2sv8s21.fsf@linux-m68k.org>
2015-08-17  5:05                                                               ` Alexandre Oliva
2015-08-17  9:29                                                                 ` Kyrill Tkachov
2015-08-17 16:23                                                                   ` Andrew Pinski
2015-08-18 16:18                                                                 ` Kyrill Tkachov
2015-08-16 16:42                                                         ` Andreas Schwab
2015-08-17  2:57                                                           ` Alexandre Oliva [this message]
2015-08-17  8:23                                                             ` Andreas Schwab
2015-08-17  9:21                                                               ` Andreas Schwab
2015-08-17 11:58                                                               ` Alexandre Oliva
2015-08-17  7:48                                                         ` Christophe Lyon
2015-08-17 12:43                                                           ` Alexandre Oliva
2015-08-17 13:39                                                             ` Christophe Lyon
2015-08-18  6:53                                                               ` Alexandre Oliva
2015-08-19  6:50                                                                 ` Alexandre Oliva
2015-08-19 10:17                                                                   ` Richard Biener
2015-08-19 13:35                                                                   ` Andreas Schwab
2015-08-19 13:45                                                                     ` Andreas Schwab
2015-08-19 17:48                                                                       ` Alexandre Oliva
2015-08-20  1:44                                                                         ` Alexandre Oliva
2015-08-20 17:03                                                                           ` Jeff Law
2015-08-21  7:57                                                                           ` Alexandre Oliva
2015-08-21  8:38                                                                             ` Richard Biener
2015-08-21 12:17                                                                             ` Andreas Schwab
2015-08-21  8:11                                                                           ` Alexandre Oliva
2015-08-21  8:37                                                                             ` Richard Biener
2015-09-02 17:09                                                         ` Alan Lawrence
2015-09-02 22:34                                                           ` Alexandre Oliva
2015-09-03 10:58                                                             ` Alan Lawrence
2015-09-18 15:49                                                             ` Alan Lawrence
2015-09-23 20:44                                                               ` Alexandre Oliva
2015-09-25 11:39                                                                 ` Richard Biener
2015-10-09  5:26                                                                   ` [PR67828] don't unswitch loops on undefined SSA values (was: Re: [PR64164] drop copyrename, integrate into expand) Alexandre Oliva
2015-10-09  9:35                                                                     ` Richard Biener
2015-10-09  5:36                                                                   ` [PR67766] reorder return value copying from PARALLELs and CONCATs " Alexandre Oliva
2015-10-09  7:33                                                                     ` [PR67891] drop is_gimple_reg test from set_parm_rtl (was: [PR67766] reorder return value copying from PARALLELs and CONCATs) Alexandre Oliva
2015-10-09  9:40                                                                       ` Richard Biener
2015-10-10 13:20                                                                         ` [PR67891] drop is_gimple_reg test from set_parm_rtl Alexandre Oliva
2015-10-12 10:22                                                                           ` Richard Biener
2015-10-14  3:25                                                                             ` Alexandre Oliva
2015-10-14  9:28                                                                               ` Richard Biener
2015-11-03  1:11                                                                                 ` Alexandre Oliva
2015-11-03  3:14                                                                                   ` Jeff Law
2015-11-03  4:29                                                                                     ` Alexandre Oliva
2022-10-17 12:08                                                                                       ` Tag 'gcc/gimple-expr.cc:mark_addressable_2' as 'static' (was: [PR67891] drop is_gimple_reg test from set_parm_rtl) Thomas Schwinge
2015-10-09  9:36                                                                     ` [PR67766] reorder return value copying from PARALLELs and CONCATs (was: Re: [PR64164] drop copyrename, integrate into expand) Richard Biener
2015-09-29 11:31                                                                 ` [PR64164] drop copyrename, integrate into expand Szabolcs Nagy
2015-10-07 22:37                                                                   ` Alexandre Oliva
2015-10-08 10:00                                                                     ` Richard Biener
2015-10-09 21:10                                                                     ` Jeff Law
2015-11-05  5:09                                                                 ` Alexandre Oliva
2015-11-05 13:44                                                                   ` Richard Biener
2015-11-10 15:31                                                                   ` Alan Lawrence
2015-11-10 22:59                                                                     ` Alexandre Oliva
2015-11-10 23:43                                                                       ` Jeff Law
2015-11-11 18:10                                                                         ` Alexandre Oliva
2015-11-13  6:33                                                                           ` Jeff Law
2015-11-17  0:07                                                                             ` Alexandre Oliva
2015-11-24  5:41                                                                               ` Jeff Law
2015-07-24 18:21                                     ` Alexandre Oliva
2015-07-29 20:32                                     ` Alexandre Oliva
2015-04-29  3:51           ` Jeff Law
2015-03-31  6:55   ` Steven Bosscher
2015-03-31 13:30     ` Richard Biener
2015-03-31 14:06   ` Richard Biener
2015-04-03 13:30     ` Alexandre Oliva
2015-04-06 15:57       ` Jeff Law
2015-12-04 12:45 ` Dominik Vogt
2015-06-09 16:19 David Edelsohn
2015-06-09 18:36 ` Alexandre Oliva
2015-06-09 20:24   ` Alexandre Oliva
2015-06-09 20:59     ` Jakub Jelinek
2015-06-09 21:36     ` Eric Botcazou
2015-06-09 21:38       ` David Edelsohn

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=orvbce3ane.fsf@livre.home \
    --to=aoliva@redhat.com \
    --cc=christophe.lyon@linaro.org \
    --cc=dje.gcc@gmail.com \
    --cc=ebotcazou@adacore.com \
    --cc=gcc-patches@gcc.gnu.org \
    --cc=hjl.tools@gmail.com \
    --cc=james.greenhalgh@arm.com \
    --cc=law@redhat.com \
    --cc=patrick.marlier@gmail.com \
    --cc=richard.guenther@gmail.com \
    --cc=schwab@linux-m68k.org \
    --cc=segher@kernel.crashing.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).