public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* Handle multi-word regsiters in REG_CFA_RESTORE notes
@ 2011-09-15  2:42 Bernd Schmidt
  2011-09-15 20:41 ` Richard Henderson
  0 siblings, 1 reply; 7+ messages in thread
From: Bernd Schmidt @ 2011-09-15  2:42 UTC (permalink / raw)
  To: GCC Patches

[-- Attachment #1: Type: text/plain, Size: 407 bytes --]

While testing the altest iteration of shrink-wrapping on mips-elf, a new
failure showed up in gcc.dg/pr43139.c. When restoring floating-point
registers, we attach REG_CFA_RESTORE notes for DFmode registers, but the
dwarf2cfi code only records a single regno for such a multiword hard reg.

Fixed with this patch, tested with shrink-wrapping on mips-elf (default
multilib plus two with -mips16). Ok?


Bernd

[-- Attachment #2: cfa-multiword.diff --]
[-- Type: text/plain, Size: 865 bytes --]

	* dwarf2cfi.c (dwarf2out_frame_debug_cfa_expression): Handle
	multi-word registers.

Index: gcc/dwarf2cfi.c
===================================================================
--- gcc/dwarf2cfi.c	(revision 178734)
+++ gcc/dwarf2cfi.c	(working copy)
@@ -1236,10 +1236,15 @@ dwarf2out_frame_debug_cfa_expression (rt
 static void
 dwarf2out_frame_debug_cfa_restore (rtx reg)
 {
-  unsigned int regno = dwf_regno (reg);
+  unsigned int orig_regno = REGNO (reg);
+  int nregs = hard_regno_nregs[orig_regno][GET_MODE (reg)];
+  while (nregs-- > 0)
+    {
+      unsigned int regno = DWARF_FRAME_REGNUM (orig_regno + nregs);
 
-  add_cfi_restore (regno);
-  update_row_reg_save (cur_row, regno, NULL);
+      add_cfi_restore (regno);
+      update_row_reg_save (cur_row, regno, NULL);
+    }
 }
 
 /* A subroutine of dwarf2out_frame_debug, process a REG_CFA_WINDOW_SAVE.

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Handle multi-word regsiters in REG_CFA_RESTORE notes
  2011-09-15  2:42 Handle multi-word regsiters in REG_CFA_RESTORE notes Bernd Schmidt
@ 2011-09-15 20:41 ` Richard Henderson
  2011-09-21 15:14   ` Bernd Schmidt
  0 siblings, 1 reply; 7+ messages in thread
From: Richard Henderson @ 2011-09-15 20:41 UTC (permalink / raw)
  To: Bernd Schmidt; +Cc: GCC Patches

On 09/14/2011 06:12 PM, Bernd Schmidt wrote:
> +  unsigned int orig_regno = REGNO (reg);
> +  int nregs = hard_regno_nregs[orig_regno][GET_MODE (reg)];
> +  while (nregs-- > 0)

The rest of the file seems to use targetm.dwarf_register_span.
This probably ought to do the same.


r~

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Handle multi-word regsiters in REG_CFA_RESTORE notes
  2011-09-15 20:41 ` Richard Henderson
@ 2011-09-21 15:14   ` Bernd Schmidt
  2011-09-21 17:47     ` Richard Henderson
  0 siblings, 1 reply; 7+ messages in thread
From: Bernd Schmidt @ 2011-09-21 15:14 UTC (permalink / raw)
  To: Richard Henderson; +Cc: GCC Patches

On 09/15/11 21:42, Richard Henderson wrote:
> On 09/14/2011 06:12 PM, Bernd Schmidt wrote:
>> +  unsigned int orig_regno = REGNO (reg);
>> +  int nregs = hard_regno_nregs[orig_regno][GET_MODE (reg)];
>> +  while (nregs-- > 0)
> 
> The rest of the file seems to use targetm.dwarf_register_span.
> This probably ought to do the same.

I guess I am confused what dwarf_register_span is supposed to accomplish
that a loop over nregs couldn't. For little endian MIPS, it returns
NULL, so I don't think it would solve the problem I'm trying to fix.


Bernd

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Handle multi-word regsiters in REG_CFA_RESTORE notes
  2011-09-21 15:14   ` Bernd Schmidt
@ 2011-09-21 17:47     ` Richard Henderson
  2011-09-22 22:09       ` Bernd Schmidt
  0 siblings, 1 reply; 7+ messages in thread
From: Richard Henderson @ 2011-09-21 17:47 UTC (permalink / raw)
  To: Bernd Schmidt; +Cc: GCC Patches

On 09/21/2011 07:55 AM, Bernd Schmidt wrote:
> On 09/15/11 21:42, Richard Henderson wrote:
>> On 09/14/2011 06:12 PM, Bernd Schmidt wrote:
>>> +  unsigned int orig_regno = REGNO (reg);
>>> +  int nregs = hard_regno_nregs[orig_regno][GET_MODE (reg)];
>>> +  while (nregs-- > 0)
>>
>> The rest of the file seems to use targetm.dwarf_register_span.
>> This probably ought to do the same.
> 
> I guess I am confused what dwarf_register_span is supposed to accomplish
> that a loop over nregs couldn't. For little endian MIPS, it returns
> NULL, so I don't think it would solve the problem I'm trying to fix.

Why, then, is this the only place in dwarf2cfi that needs to handle
registers via a loop over nregs?  It seems to me that we should either
be handling multi-register spans everywhere or nowhere.

Because alternately, this could be a bug in your backend that you
failed to add two RESTORE notes instead of just one...


r~

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Handle multi-word regsiters in REG_CFA_RESTORE notes
  2011-09-21 17:47     ` Richard Henderson
@ 2011-09-22 22:09       ` Bernd Schmidt
  2011-09-25 19:54         ` Richard Sandiford
  0 siblings, 1 reply; 7+ messages in thread
From: Bernd Schmidt @ 2011-09-22 22:09 UTC (permalink / raw)
  To: Richard Henderson; +Cc: GCC Patches, Richard Sandiford

[-- Attachment #1: Type: text/plain, Size: 433 bytes --]

On 09/21/11 19:33, Richard Henderson wrote:
> Why, then, is this the only place in dwarf2cfi that needs to handle
> registers via a loop over nregs?  It seems to me that we should either
> be handling multi-register spans everywhere or nowhere.
> 
> Because alternately, this could be a bug in your backend that you
> failed to add two RESTORE notes instead of just one...

Well, changing the backend works too. Patch below.


Bernd

[-- Attachment #2: mips-ep64.diff --]
[-- Type: text/plain, Size: 1855 bytes --]

	* mips.c (mips_restore_reg): Split multiword registers for
	REG_CFA_RESTORE notes.

Index: gcc/config/mips/mips.c
===================================================================
--- gcc/config/mips/mips.c	(revision 178847)
+++ gcc/config/mips/mips.c	(working copy)
@@ -10286,16 +10286,28 @@ mips_epilogue_set_cfa (rtx reg, HOST_WID
 static void
 mips_restore_reg (rtx reg, rtx mem)
 {
+  enum machine_mode mode = GET_MODE (reg);
+  unsigned regno = REGNO (reg);
+
   /* There's no MIPS16 instruction to load $31 directly.  Load into
      $7 instead and adjust the return insn appropriately.  */
-  if (TARGET_MIPS16 && REGNO (reg) == RETURN_ADDR_REGNUM)
-    reg = gen_rtx_REG (GET_MODE (reg), GP_REG_FIRST + 7);
+  if (TARGET_MIPS16 && regno == RETURN_ADDR_REGNUM)
+    reg = gen_rtx_REG (mode, GP_REG_FIRST + 7);
+  else if (GET_MODE_SIZE (mode) != 8 || !mips_split_64bit_move_p (reg, mem))
+    mips_epilogue.cfa_restores
+      = alloc_reg_note (REG_CFA_RESTORE, reg, mips_epilogue.cfa_restores);
   else
-    mips_epilogue.cfa_restores = alloc_reg_note (REG_CFA_RESTORE, reg,
-						 mips_epilogue.cfa_restores);
+    {
+      rtx word1 = mips_subword (reg, true);
+      rtx word2 = mips_subword (reg, false);
+      mips_epilogue.cfa_restores
+	= alloc_reg_note (REG_CFA_RESTORE, word1, mips_epilogue.cfa_restores);
+      mips_epilogue.cfa_restores
+	= alloc_reg_note (REG_CFA_RESTORE, word2, mips_epilogue.cfa_restores);
+    }
 
-  mips_emit_save_slot_move (reg, mem, MIPS_EPILOGUE_TEMP (GET_MODE (reg)));
-  if (REGNO (reg) == REGNO (mips_epilogue.cfa_reg))
+  mips_emit_save_slot_move (reg, mem, MIPS_EPILOGUE_TEMP (mode));
+  if (regno == REGNO (mips_epilogue.cfa_reg))
     /* The CFA is currently defined in terms of the register whose
        value we have just restored.  Redefine the CFA in terms of
        the stack pointer.  */

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Handle multi-word regsiters in REG_CFA_RESTORE notes
  2011-09-22 22:09       ` Bernd Schmidt
@ 2011-09-25 19:54         ` Richard Sandiford
  2011-09-27 12:57           ` Bernd Schmidt
  0 siblings, 1 reply; 7+ messages in thread
From: Richard Sandiford @ 2011-09-25 19:54 UTC (permalink / raw)
  To: Bernd Schmidt; +Cc: Richard Henderson, GCC Patches

Bernd Schmidt <bernds@codesourcery.com> writes:
> On 09/21/11 19:33, Richard Henderson wrote:
>> Why, then, is this the only place in dwarf2cfi that needs to handle
>> registers via a loop over nregs?  It seems to me that we should either
>> be handling multi-register spans everywhere or nowhere.
>> 
>> Because alternately, this could be a bug in your backend that you
>> failed to add two RESTORE notes instead of just one...
>
> Well, changing the backend works too. Patch below.
>
>
> Bernd
>
> 	* mips.c (mips_restore_reg): Split multiword registers for
> 	REG_CFA_RESTORE notes.
>
> Index: gcc/config/mips/mips.c
> ===================================================================
> --- gcc/config/mips/mips.c	(revision 178847)
> +++ gcc/config/mips/mips.c	(working copy)
> @@ -10286,16 +10286,28 @@ mips_epilogue_set_cfa (rtx reg, HOST_WID
>  static void
>  mips_restore_reg (rtx reg, rtx mem)
>  {
> +  enum machine_mode mode = GET_MODE (reg);
> +  unsigned regno = REGNO (reg);
> +
>    /* There's no MIPS16 instruction to load $31 directly.  Load into
>       $7 instead and adjust the return insn appropriately.  */
> -  if (TARGET_MIPS16 && REGNO (reg) == RETURN_ADDR_REGNUM)
> -    reg = gen_rtx_REG (GET_MODE (reg), GP_REG_FIRST + 7);
> +  if (TARGET_MIPS16 && regno == RETURN_ADDR_REGNUM)
> +    reg = gen_rtx_REG (mode, GP_REG_FIRST + 7);
> +  else if (GET_MODE_SIZE (mode) != 8 || !mips_split_64bit_move_p (reg, mem))
> +    mips_epilogue.cfa_restores
> +      = alloc_reg_note (REG_CFA_RESTORE, reg, mips_epilogue.cfa_restores);
>    else
> -    mips_epilogue.cfa_restores = alloc_reg_note (REG_CFA_RESTORE, reg,
> -						 mips_epilogue.cfa_restores);
> +    {
> +      rtx word1 = mips_subword (reg, true);
> +      rtx word2 = mips_subword (reg, false);
> +      mips_epilogue.cfa_restores
> +	= alloc_reg_note (REG_CFA_RESTORE, word1, mips_epilogue.cfa_restores);
> +      mips_epilogue.cfa_restores
> +	= alloc_reg_note (REG_CFA_RESTORE, word2, mips_epilogue.cfa_restores);
> +    }

I think the condition ought to match that in mips_save_reg:

static void
mips_save_reg (rtx reg, rtx mem)
{
  if (GET_MODE (reg) == DFmode && !TARGET_FLOAT64)
    {
      rtx x1, x2;

      if (mips_split_64bit_move_p (mem, reg))
	mips_split_doubleword_move (mem, reg);
      else
	mips_emit_move (mem, reg);

      x1 = mips_frame_set (mips_subword (mem, false),
			   mips_subword (reg, false));
      x2 = mips_frame_set (mips_subword (mem, true),
			   mips_subword (reg, true));
      mips_set_frame_expr (gen_rtx_PARALLEL (VOIDmode, gen_rtvec (2, x1, x2)));
    }
  else
    mips_emit_save_slot_move (mem, reg, MIPS_PROLOGUE_TEMP (GET_MODE (reg)));
}

The store itself can still be a single SDC1 instruction, so we should
generate the same notes regardless of mips_split_64bit_move_p.

If that's right, then how about the patch below (tested on
mips64-linux-gnu, but without the shrink-wrap patches)?

Richard


gcc/
2011-09-25  Bernd Schmidt  <bernds@codesourcery.com>
	    Richard Sandiford  <rdsandiford@googlemail.com>

	* config/mips/mips.c (mips_add_cfa_restore): New function.
	(mips16e_save_restore_reg): Use it.
	(mips_restore_reg): Likewise.  Split double FPRs for
	REG_CFA_RESTORE notes.

Index: gcc/config/mips/mips.c
===================================================================
--- gcc/config/mips/mips.c	2011-09-25 18:16:38.000000000 +0100
+++ gcc/config/mips/mips.c	2011-09-25 18:19:15.000000000 +0100
@@ -8202,6 +8202,15 @@ mips_frame_set (rtx mem, rtx reg)
 
   return set;
 }
+
+/* Record that the epilogue has restored call-saved register REG.  */
+
+static void
+mips_add_cfa_restore (rtx reg)
+{
+  mips_epilogue.cfa_restores = alloc_reg_note (REG_CFA_RESTORE, reg,
+					       mips_epilogue.cfa_restores);
+}
 \f
 /* If a MIPS16e SAVE or RESTORE instruction saves or restores register
    mips16e_s2_s8_regs[X], it must also save the registers in indexes
@@ -8393,8 +8402,7 @@ mips16e_save_restore_reg (bool restore_p
   reg = gen_rtx_REG (SImode, regno);
   if (restore_p)
     {
-      mips_epilogue.cfa_restores = alloc_reg_note (REG_CFA_RESTORE, reg,
-						   mips_epilogue.cfa_restores);
+      mips_add_cfa_restore (reg);
       return gen_rtx_SET (VOIDmode, reg, mem);
     }
   if (reg_parm_p)
@@ -10290,9 +10298,13 @@ mips_restore_reg (rtx reg, rtx mem)
      $7 instead and adjust the return insn appropriately.  */
   if (TARGET_MIPS16 && REGNO (reg) == RETURN_ADDR_REGNUM)
     reg = gen_rtx_REG (GET_MODE (reg), GP_REG_FIRST + 7);
+  else if (GET_MODE (reg) == DFmode && !TARGET_FLOAT64)
+    {
+      mips_add_cfa_restore (mips_subword (reg, true));
+      mips_add_cfa_restore (mips_subword (reg, false));
+    }
   else
-    mips_epilogue.cfa_restores = alloc_reg_note (REG_CFA_RESTORE, reg,
-						 mips_epilogue.cfa_restores);
+    mips_add_cfa_restore (reg);
 
   mips_emit_save_slot_move (reg, mem, MIPS_EPILOGUE_TEMP (GET_MODE (reg)));
   if (REGNO (reg) == REGNO (mips_epilogue.cfa_reg))

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Handle multi-word regsiters in REG_CFA_RESTORE notes
  2011-09-25 19:54         ` Richard Sandiford
@ 2011-09-27 12:57           ` Bernd Schmidt
  0 siblings, 0 replies; 7+ messages in thread
From: Bernd Schmidt @ 2011-09-27 12:57 UTC (permalink / raw)
  To: Richard Henderson, GCC Patches, rdsandiford

On 09/25/11 19:27, Richard Sandiford wrote:
> The store itself can still be a single SDC1 instruction, so we should
> generate the same notes regardless of mips_split_64bit_move_p.
> 
> If that's right, then how about the patch below (tested on
> mips64-linux-gnu, but without the shrink-wrap patches)?

You know mips better than I do... Tested with shrink-wrapping, and it
seems to work as well. Please go ahead.


Bernd

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2011-09-27 11:59 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-09-15  2:42 Handle multi-word regsiters in REG_CFA_RESTORE notes Bernd Schmidt
2011-09-15 20:41 ` Richard Henderson
2011-09-21 15:14   ` Bernd Schmidt
2011-09-21 17:47     ` Richard Henderson
2011-09-22 22:09       ` Bernd Schmidt
2011-09-25 19:54         ` Richard Sandiford
2011-09-27 12:57           ` Bernd Schmidt

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