public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH] PR target/89828 Inernal compiler error on -fno-omit-frame-pointer
@ 2023-01-05 13:05 Yoshinori Sato
  2023-03-11 16:59 ` Jeff Law
  0 siblings, 1 reply; 5+ messages in thread
From: Yoshinori Sato @ 2023-01-05 13:05 UTC (permalink / raw)
  To: gcc-patches; +Cc: Yoshinori Sato

The problem was caused by an erroneous note about creating a stack frame,
which caused the cur_cfa reg to fail to assert with a value other than
the frame pointer.

This fix will generate notes that correctly update cur_cfa.

gcc/config/rx/
	* rx.cc (add_pop_cfi_notes): Release the frame pointer if it is used.
	(rx_expand_prologue): Redesigned stack pointer and frame pointer update process.

Signed-off-by: Yoshinori Sato <ysato@users.sourceforge.jp>
---
 gcc/config/rx/rx.cc | 50 +++++++++++++++------------------------------
 1 file changed, 17 insertions(+), 33 deletions(-)

diff --git a/gcc/config/rx/rx.cc b/gcc/config/rx/rx.cc
index 412a3a354b0..8c246d42cd8 100644
--- a/gcc/config/rx/rx.cc
+++ b/gcc/config/rx/rx.cc
@@ -1647,16 +1647,20 @@ mark_frame_related (rtx insn)
 static void
 add_pop_cfi_notes (rtx_insn *insn, unsigned int high, unsigned int low)
 {
-  rtx t = plus_constant (Pmode, stack_pointer_rtx,
-                        (high - low + 1) * UNITS_PER_WORD);
+  rtx src = stack_pointer_rtx;
+  rtx t;
+  for (unsigned int i = low; i <= high; i++)
+    {
+      add_reg_note (insn, REG_CFA_RESTORE, gen_rtx_REG (word_mode, i));
+      if (i == FRAME_POINTER_REGNUM)
+	src = frame_pointer_rtx;
+    }
+  t = plus_constant (Pmode, src, (high - low + 1) * UNITS_PER_WORD);
   t = gen_rtx_SET (stack_pointer_rtx, t);
   add_reg_note (insn, REG_CFA_ADJUST_CFA, t);
   RTX_FRAME_RELATED_P (insn) = 1;
-  for (unsigned int i = low; i <= high; i++)
-    add_reg_note (insn, REG_CFA_RESTORE, gen_rtx_REG (word_mode, i));
 }
 
-
 static bool
 ok_for_max_constant (HOST_WIDE_INT val)
 {
@@ -1815,37 +1819,17 @@ rx_expand_prologue (void)
 	}
     }
 
-  /* If needed, set up the frame pointer.  */
-  if (frame_pointer_needed)
-    gen_safe_add (frame_pointer_rtx, stack_pointer_rtx,
-		  GEN_INT (- (HOST_WIDE_INT) frame_size), true);
-
-  /* Allocate space for the outgoing args.
-     If the stack frame has not already been set up then handle this as well.  */
-  if (stack_size)
+  if (stack_size || frame_size)
     {
-      if (frame_size)
-	{
-	  if (frame_pointer_needed)
-	    gen_safe_add (stack_pointer_rtx, frame_pointer_rtx,
-			  GEN_INT (- (HOST_WIDE_INT) stack_size), true);
-	  else
-	    gen_safe_add (stack_pointer_rtx, stack_pointer_rtx,
-			  GEN_INT (- (HOST_WIDE_INT) (frame_size + stack_size)),
-			  true);
-	}
-      else
-	gen_safe_add (stack_pointer_rtx, stack_pointer_rtx,
-		      GEN_INT (- (HOST_WIDE_INT) stack_size), true);
+      gen_safe_add (stack_pointer_rtx, stack_pointer_rtx,
+		    GEN_INT (- (HOST_WIDE_INT) (stack_size + frame_size)),
+		    true);
     }
-  else if (frame_size)
+  if (frame_pointer_needed)
     {
-      if (! frame_pointer_needed)
-	gen_safe_add (stack_pointer_rtx, stack_pointer_rtx,
-		      GEN_INT (- (HOST_WIDE_INT) frame_size), true);
-      else
-	gen_safe_add (stack_pointer_rtx, frame_pointer_rtx, NULL_RTX,
-		      false /* False because the epilogue will use the FP not the SP.  */);
+      gen_safe_add (frame_pointer_rtx, stack_pointer_rtx,
+		    GEN_INT ((HOST_WIDE_INT) stack_size),
+		    true);
     }
 }
 
-- 
2.30.2


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

* Re: [PATCH] PR target/89828 Inernal compiler error on -fno-omit-frame-pointer
  2023-01-05 13:05 [PATCH] PR target/89828 Inernal compiler error on -fno-omit-frame-pointer Yoshinori Sato
@ 2023-03-11 16:59 ` Jeff Law
  2023-03-15  7:51   ` [PATCH v2] " Yoshinori Sato
  0 siblings, 1 reply; 5+ messages in thread
From: Jeff Law @ 2023-03-11 16:59 UTC (permalink / raw)
  To: Yoshinori Sato, gcc-patches



On 1/5/23 06:05, Yoshinori Sato wrote:
> Subject:
> [PATCH] PR target/89828 Inernal compiler error on -fno-omit-frame-pointer
> From:
> Yoshinori Sato <ysato@users.sourceforge.jp>
> Date:
> 1/5/23, 06:05
> 
> To:
> gcc-patches@gcc.gnu.org
> CC:
> Yoshinori Sato <ysato@users.sourceforge.jp>
> 
> 
> The problem was caused by an erroneous note about creating a stack frame,
> which caused the cur_cfa reg to fail to assert with a value other than
> the frame pointer.
> 
> This fix will generate notes that correctly update cur_cfa.
> 
> gcc/config/rx/
> 	* rx.cc (add_pop_cfi_notes): Release the frame pointer if it is used.
> 	(rx_expand_prologue): Redesigned stack pointer and frame pointer update process.
This seems to be taking a step backwards in that it's causing multiple 
internal errors when compiling newlib.

The failures are here:

static void
dwarf2out_frame_debug_adjust_cfa (rtx pat)
{
   rtx src, dest;

   gcc_assert (GET_CODE (pat) == SET);
   dest = XEXP (pat, 0);
   src = XEXP (pat, 1);

   switch (GET_CODE (src))
     {
     case PLUS:
       gcc_assert (cur_cfa->reg == XEXP (src, 0));
       cur_cfa->offset -= rtx_to_poly_int64 (XEXP (src, 1));
       break;

     case REG:
       break;

     default:
       gcc_unreachable ();
     }

   cur_cfa->reg = dwf_cfa_reg (dest);
   gcc_assert (cur_cfa->indirect == 0);
}

In particular it's tripping the gcc_assert in the PLUS case above. 
Which is a pretty good indicator the contents of the note and the insn's 
pattern are different WRT the expected registers.

jeff

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

* [PATCH v2] PR target/89828 Inernal compiler error on -fno-omit-frame-pointer
  2023-03-11 16:59 ` Jeff Law
@ 2023-03-15  7:51   ` Yoshinori Sato
  2023-03-15 22:07     ` Jeff Law
  2023-03-19 16:48     ` Jeff Law
  0 siblings, 2 replies; 5+ messages in thread
From: Yoshinori Sato @ 2023-03-15  7:51 UTC (permalink / raw)
  To: gcc-patches; +Cc: Yoshinori Sato

What about this?
It no longer occurs for me.

gcc/config/rx/
	* rx.cc (add_pop_cfi_notes): Release the frame pointer if it is used.
	(rx_expand_prologue): Redesigned stack pointer and frame pointer update process.

Signed-off-by: Yoshinori Sato <ysato@users.sourceforge.jp>
---
 gcc/config/rx/rx.cc | 50 +++++++++++++++------------------------------
 1 file changed, 17 insertions(+), 33 deletions(-)

diff --git a/gcc/config/rx/rx.cc b/gcc/config/rx/rx.cc
index 412a3a354b0..51ef4a6be34 100644
--- a/gcc/config/rx/rx.cc
+++ b/gcc/config/rx/rx.cc
@@ -1647,16 +1647,20 @@ mark_frame_related (rtx insn)
 static void
 add_pop_cfi_notes (rtx_insn *insn, unsigned int high, unsigned int low)
 {
-  rtx t = plus_constant (Pmode, stack_pointer_rtx,
-                        (high - low + 1) * UNITS_PER_WORD);
+  rtx src = stack_pointer_rtx;
+  rtx t;
+  for (unsigned int i = low; i <= high; i++)
+    {
+      add_reg_note (insn, REG_CFA_RESTORE, gen_rtx_REG (word_mode, i));
+      if (i == FRAME_POINTER_REGNUM && frame_pointer_needed)
+	src = frame_pointer_rtx;
+    }
+  t = plus_constant (Pmode, src, (high - low + 1) * UNITS_PER_WORD);
   t = gen_rtx_SET (stack_pointer_rtx, t);
   add_reg_note (insn, REG_CFA_ADJUST_CFA, t);
   RTX_FRAME_RELATED_P (insn) = 1;
-  for (unsigned int i = low; i <= high; i++)
-    add_reg_note (insn, REG_CFA_RESTORE, gen_rtx_REG (word_mode, i));
 }
 
-
 static bool
 ok_for_max_constant (HOST_WIDE_INT val)
 {
@@ -1815,37 +1819,17 @@ rx_expand_prologue (void)
 	}
     }
 
-  /* If needed, set up the frame pointer.  */
-  if (frame_pointer_needed)
-    gen_safe_add (frame_pointer_rtx, stack_pointer_rtx,
-		  GEN_INT (- (HOST_WIDE_INT) frame_size), true);
-
-  /* Allocate space for the outgoing args.
-     If the stack frame has not already been set up then handle this as well.  */
-  if (stack_size)
+  if (stack_size || frame_size)
     {
-      if (frame_size)
-	{
-	  if (frame_pointer_needed)
-	    gen_safe_add (stack_pointer_rtx, frame_pointer_rtx,
-			  GEN_INT (- (HOST_WIDE_INT) stack_size), true);
-	  else
-	    gen_safe_add (stack_pointer_rtx, stack_pointer_rtx,
-			  GEN_INT (- (HOST_WIDE_INT) (frame_size + stack_size)),
-			  true);
-	}
-      else
-	gen_safe_add (stack_pointer_rtx, stack_pointer_rtx,
-		      GEN_INT (- (HOST_WIDE_INT) stack_size), true);
+      gen_safe_add (stack_pointer_rtx, stack_pointer_rtx,
+		    GEN_INT (- (HOST_WIDE_INT) (stack_size + frame_size)),
+		    true);
     }
-  else if (frame_size)
+  if (frame_pointer_needed)
     {
-      if (! frame_pointer_needed)
-	gen_safe_add (stack_pointer_rtx, stack_pointer_rtx,
-		      GEN_INT (- (HOST_WIDE_INT) frame_size), true);
-      else
-	gen_safe_add (stack_pointer_rtx, frame_pointer_rtx, NULL_RTX,
-		      false /* False because the epilogue will use the FP not the SP.  */);
+      gen_safe_add (frame_pointer_rtx, stack_pointer_rtx,
+		    GEN_INT ((HOST_WIDE_INT) stack_size),
+		    true);
     }
 }
 
-- 
2.30.2


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

* Re: [PATCH v2] PR target/89828 Inernal compiler error on -fno-omit-frame-pointer
  2023-03-15  7:51   ` [PATCH v2] " Yoshinori Sato
@ 2023-03-15 22:07     ` Jeff Law
  2023-03-19 16:48     ` Jeff Law
  1 sibling, 0 replies; 5+ messages in thread
From: Jeff Law @ 2023-03-15 22:07 UTC (permalink / raw)
  To: Yoshinori Sato, gcc-patches



On 3/15/23 01:51, Yoshinori Sato wrote:
> What about this?
> It no longer occurs for me.
> 
> gcc/config/rx/
> 	* rx.cc (add_pop_cfi_notes): Release the frame pointer if it is used.
> 	(rx_expand_prologue): Redesigned stack pointer and frame pointer update process.
That fixes the problems building newlib.  It also fixes roughly 300 
failures in the testsuite (primarily fixing ICEs in 
dwarf2out_frame_debug_adjust_cfa).

So the next step is to sit down with the code  and review it :-)

jeff

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

* Re: [PATCH v2] PR target/89828 Inernal compiler error on -fno-omit-frame-pointer
  2023-03-15  7:51   ` [PATCH v2] " Yoshinori Sato
  2023-03-15 22:07     ` Jeff Law
@ 2023-03-19 16:48     ` Jeff Law
  1 sibling, 0 replies; 5+ messages in thread
From: Jeff Law @ 2023-03-19 16:48 UTC (permalink / raw)
  To: Yoshinori Sato, gcc-patches



On 3/15/23 01:51, Yoshinori Sato wrote:
> What about this?
> It no longer occurs for me.
> 
> gcc/config/rx/
> 	* rx.cc (add_pop_cfi_notes): Release the frame pointer if it is used.
> 	(rx_expand_prologue): Redesigned stack pointer and frame pointer update process.
So I think the ChangeLog entry needs a bit of work.   I don't see how 
the ChangeLog entry for add_pop_cfi_notes relates to the changes at all.

This might be better:

	* config/rx/rx.cc (add_pop_cfi_notes): Attach CFA_RESTORE notes
	first, then the CFA_ADJUST_CFA note.  If restoring the frame
	pointer, use (fp + offset) for the CFA_ADJUST_CFA note.



> @@ -1815,37 +1819,17 @@ rx_expand_prologue (void)
>   	}
>       }
>   
> -  /* If needed, set up the frame pointer.  */
> -  if (frame_pointer_needed)
> -    gen_safe_add (frame_pointer_rtx, stack_pointer_rtx,
> -		  GEN_INT (- (HOST_WIDE_INT) frame_size), true);
> -
> -  /* Allocate space for the outgoing args.
> -     If the stack frame has not already been set up then handle this as well.  */
> -  if (stack_size)
> +  if (stack_size || frame_size)
>       {
> -      if (frame_size)
> -	{
> -	  if (frame_pointer_needed)
> -	    gen_safe_add (stack_pointer_rtx, frame_pointer_rtx,
> -			  GEN_INT (- (HOST_WIDE_INT) stack_size), true);
> -	  else
> -	    gen_safe_add (stack_pointer_rtx, stack_pointer_rtx,
> -			  GEN_INT (- (HOST_WIDE_INT) (frame_size + stack_size)),
> -			  true);
> -	}
> -      else
> -	gen_safe_add (stack_pointer_rtx, stack_pointer_rtx,
> -		      GEN_INT (- (HOST_WIDE_INT) stack_size), true);
> +      gen_safe_add (stack_pointer_rtx, stack_pointer_rtx,
> +		    GEN_INT (- (HOST_WIDE_INT) (stack_size + frame_size)),
> +		    true);
>       }
> -  else if (frame_size)
> +  if (frame_pointer_needed)
>       {
> -      if (! frame_pointer_needed)
> -	gen_safe_add (stack_pointer_rtx, stack_pointer_rtx,
> -		      GEN_INT (- (HOST_WIDE_INT) frame_size), true);
> -      else
> -	gen_safe_add (stack_pointer_rtx, frame_pointer_rtx, NULL_RTX,
> -		      false /* False because the epilogue will use the FP not the SP.  */);
> +      gen_safe_add (frame_pointer_rtx, stack_pointer_rtx,
> +		    GEN_INT ((HOST_WIDE_INT) stack_size),
> +		    true);
It looks like we're emitting;

(set (sp) (plus (sp) (stack_size + frame_size)

Then  we emit

(set (fp) (plus (sp) (stack_size))

Unless I missing something important, that seems wrong and results in 
stack_size being added to FP twice.


jeff

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

end of thread, other threads:[~2023-03-19 16:48 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-01-05 13:05 [PATCH] PR target/89828 Inernal compiler error on -fno-omit-frame-pointer Yoshinori Sato
2023-03-11 16:59 ` Jeff Law
2023-03-15  7:51   ` [PATCH v2] " Yoshinori Sato
2023-03-15 22:07     ` Jeff Law
2023-03-19 16:48     ` Jeff Law

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