public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [Patch] Add microMIPS jraddiusp support
@ 2013-03-04 23:08 Moore, Catherine
  2013-03-05 21:10 ` Richard Sandiford
  0 siblings, 1 reply; 7+ messages in thread
From: Moore, Catherine @ 2013-03-04 23:08 UTC (permalink / raw)
  To: rdsandiford; +Cc: gcc-patches, Moore, Catherine, Rozycki, Maciej

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

Hi Richard,
This patch adds support for the microMIPS jraddiusp instruction to the base microMIPS base.
Is this okay to commit?
Thanks,
Catherine

2013-03-04  Catherine Moore  <clm@codesourcery.com>

	* config/mips/micromips.md (mips_jraddiusp): New insn.
	* config/mips/mips.c (mips_expand_epilogue): Generate JRADDIUSP.

2013-03-04  Catherine Moore  <clm@codesourcery.com>

	* gcc.target/mips/umips-jraddiusp-1.c: New test.
	* gcc.target/mips/umips-jraddiusp-2.c: Likewise.
	* gcc.target/mips/umips-jraddiusp-3.c: Likewise



[-- Attachment #2: jraddiusp.patch --]
[-- Type: application/octet-stream, Size: 5046 bytes --]

Index: testsuite/gcc.target/mips/umips-jraddiusp-1.c
===================================================================
--- testsuite/gcc.target/mips/umips-jraddiusp-1.c	(revision 0)
+++ testsuite/gcc.target/mips/umips-jraddiusp-1.c	(revision 0)
@@ -0,0 +1,15 @@
+/* Check that we can use the jraddiusp instruction.  */
+/* { dg-options "-mabi=32 (-mmicromips)" } */
+
+int bar (int);
+
+MICROMIPS int
+foo (int n, int a, int b, int c, int d)
+{
+  int i, j;
+  i = bar (n);
+  j = bar (n);
+  return i + j;
+}
+
+/* { dg-final { scan-assembler "\tjraddiusp\t32" } } */
Index: testsuite/gcc.target/mips/umips-jraddiusp-2.c
===================================================================
--- testsuite/gcc.target/mips/umips-jraddiusp-2.c	(revision 0)
+++ testsuite/gcc.target/mips/umips-jraddiusp-2.c	(revision 0)
@@ -0,0 +1,23 @@
+/* Check that we do not use the jraddiusp instruction for large frames.  */
+/* { dg-options "-mabi=32 (-mmicromips)" } */
+
+int bar (int);
+
+MICROMIPS int
+foo (int n, int a, int b, int c, int d)
+{
+  int i, j = 0;
+  int temp[150];
+  for (i = 0; i < 150; i++)
+    temp[i] = bar (n);
+
+  for (i = 0; i < 150; i++)
+    temp[i] += bar (temp[i]);
+
+  for (i = 0; i < 150; i++)
+    j += temp[i];
+
+  return j;
+}
+
+/* { dg-final { scan-assembler-not "\tjraddiusp" } } */
Index: testsuite/gcc.target/mips/umips-jraddiusp-3.c
===================================================================
--- testsuite/gcc.target/mips/umips-jraddiusp-3.c	(revision 0)
+++ testsuite/gcc.target/mips/umips-jraddiusp-3.c	(revision 0)
@@ -0,0 +1,13 @@
+/* Check that we do not use the jraddisup instruction in a __builtin_eh_return
+   function.  */
+/* { dg-options "-mabi=32 (-mmicromips)" } */
+
+void bar (void);
+
+MICROMIPS void
+foo (int x)
+{
+  __builtin_unwind_init ();
+  __builtin_eh_return (x, bar);
+}
+/* { dg-final { scan-assembler-not "\tjraddiusp" } } */
Index: config/mips/micromips.md
===================================================================
--- config/mips/micromips.md	(revision 196341)
+++ config/mips/micromips.md	(working copy)
@@ -95,6 +95,19 @@
    (set_attr "mode" "SI")
    (set_attr "can_delay" "no")])
 
+;; For JRADDIUSP.
+(define_insn "jraddiusp"
+  [(parallel [(return)
+              (use (reg:SI 31))
+	      (set (reg:SI 29)
+		   (plus:SI (reg:SI 29)
+			    (match_operand 0 "const_int_operand")))])]
+  "TARGET_MICROMIPS"
+  "jraddiusp\t%0"
+  [(set_attr "type"	"trap")
+   (set_attr "can_delay" "no")
+   (set_attr "mode"	"SI")])
+
 ;; For MOVEP.
 (define_peephole2
   [(set (match_operand:MOVEP1 0 "register_operand" "")
Index: config/mips/mips.c
===================================================================
--- config/mips/mips.c	(revision 196341)
+++ config/mips/mips.c	(working copy)
@@ -11364,6 +11364,7 @@
   const struct mips_frame_info *frame;
   HOST_WIDE_INT step1, step2;
   rtx base, adjust, insn;
+  bool use_jraddiusp_p = false;
 
   if (!sibcall_p && mips_can_use_return_insn ())
     {
@@ -11453,6 +11454,14 @@
       mips_for_each_saved_gpr_and_fpr (frame->total_size - step2,
 				       mips_restore_reg);
 
+      /* Check if we can use JRADDIUSP.  */
+      use_jraddiusp_p = (TARGET_MICROMIPS
+			 && !crtl->calls_eh_return
+			 && !sibcall_p
+			 && step2 > 0
+			 && (step2 & 3) == 0
+			 && step2 <= (31 << 2));
+
       if (cfun->machine->interrupt_handler_p)
 	{
 	  HOST_WIDE_INT offset;
@@ -11480,8 +11489,9 @@
 	  mips_emit_move (gen_rtx_REG (word_mode, K0_REG_NUM), mem);
 	  offset -= UNITS_PER_WORD;
 
-	  /* If we don't use shadow register set, we need to update SP.  */
-	  if (!cfun->machine->use_shadow_register_set_p)
+	  /* If we don't use shadow register set or the microMIPS
+             JRADDIUSP insn, we need to update SP.  */
+	  if (!cfun->machine->use_shadow_register_set_p && !use_jraddiusp_p)
 	    mips_deallocate_stack (stack_pointer_rtx, GEN_INT (step2), 0);
 	  else
 	    /* The choice of position is somewhat arbitrary in this case.  */
@@ -11492,11 +11502,14 @@
 				    gen_rtx_REG (SImode, K0_REG_NUM)));
 	}
       else
-	/* Deallocate the final bit of the frame.  */
-	mips_deallocate_stack (stack_pointer_rtx, GEN_INT (step2), 0);
+	/* Deallocate the final bit of the frame unless using the microMIPS
+           JRADDIUSP insn.  */
+	if (!use_jraddiusp_p)
+	  mips_deallocate_stack (stack_pointer_rtx, GEN_INT (step2), 0);
     }
 
-  gcc_assert (!mips_epilogue.cfa_restores);
+  if (!use_jraddiusp_p)
+    gcc_assert (!mips_epilogue.cfa_restores);
 
   /* Add in the __builtin_eh_return stack adjustment.  We need to
      use a temporary in MIPS16 code.  */
@@ -11546,6 +11559,8 @@
 	      rtx reg = gen_rtx_REG (Pmode, GP_REG_FIRST + 7);
 	      pat = gen_return_internal (reg);
 	    }
+	  else if (use_jraddiusp_p)
+	    pat = gen_jraddiusp (GEN_INT (step2));
 	  else
 	    {
 	      rtx reg = gen_rtx_REG (Pmode, RETURN_ADDR_REGNUM);

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

end of thread, other threads:[~2013-04-24  6:27 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-03-04 23:08 [Patch] Add microMIPS jraddiusp support Moore, Catherine
2013-03-05 21:10 ` Richard Sandiford
2013-03-14 21:07   ` Moore, Catherine
2013-03-14 21:38     ` Richard Sandiford
2013-04-02 17:35       ` Moore, Catherine
2013-04-24 11:02         ` Richard Sandiford
2013-04-03 13:53       ` Moore, Catherine

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