From c8a14e0e9aa678c6bd3eb62fe658eea8424432ba Mon Sep 17 00:00:00 2001
From: Richard Henderson <rth@redhat.com>
Date: Thu, 8 Nov 2001 11:20:38 -0800
Subject: [PATCH] mips.c (save_restore_insns): Remove GP from the restore
 registers mask early instead of special casing it...

        * config/mips/mips.c (save_restore_insns): Remove GP from the
        restore registers mask early instead of special casing it inside
        the loop.

From-SVN: r46853
---
 gcc/ChangeLog          |  6 +++
 gcc/config/mips/mips.c | 85 ++++++++++++++++++++++--------------------
 2 files changed, 51 insertions(+), 40 deletions(-)

diff --git a/gcc/ChangeLog b/gcc/ChangeLog
index b410b511bf04..7c5c124ba63b 100644
--- a/gcc/ChangeLog
+++ b/gcc/ChangeLog
@@ -1,3 +1,9 @@
+2001-11-08  Richard Henderson  <rth@redhat.com>
+
+	* config/mips/mips.c (save_restore_insns): Remove GP from the
+	restore registers mask early instead of special casing it inside
+	the loop.
+
 2001-11-08  Neil Booth  <neil@daikokuya.demon.co.uk>
 
 	* cp/decl.c (shadow_warning): New function.
diff --git a/gcc/config/mips/mips.c b/gcc/config/mips/mips.c
index 8fac84cffc12..284ed92389af 100644
--- a/gcc/config/mips/mips.c
+++ b/gcc/config/mips/mips.c
@@ -6659,6 +6659,7 @@ save_restore_insns (store_p, large_reg, large_offset, file)
 {
   long mask = current_frame_info.mask;
   long fmask = current_frame_info.fmask;
+  long real_mask = mask;
   int regno;
   rtx base_reg_rtx;
   HOST_WIDE_INT base_offset;
@@ -6671,6 +6672,12 @@ save_restore_insns (store_p, large_reg, large_offset, file)
       && ! BITSET_P (mask, HARD_FRAME_POINTER_REGNUM - GP_REG_FIRST))
     abort ();
 
+  /* Do not restore GP under certain conditions.  */
+  if (! store_p
+      && TARGET_ABICALLS
+      && (mips_abi == ABI_32 || mips_abi == ABI_O64))
+    mask &= ~(1 << (PIC_OFFSET_TABLE_REGNUM - GP_REG_FIRST));
+
   if (mask == 0 && fmask == 0)
     return;
 
@@ -6785,9 +6792,7 @@ save_restore_insns (store_p, large_reg, large_offset, file)
 
 		if (store_p)
 		  mips_emit_frame_related_store (mem_rtx, reg_rtx, gp_offset);
-		else if (!TARGET_ABICALLS
-			 || (mips_abi != ABI_32 && mips_abi != ABI_O64)
-			 || regno != (PIC_OFFSET_TABLE_REGNUM - GP_REG_FIRST))
+		else
 		  {
 		    emit_move_insn (reg_rtx, mem_rtx);
 		    if (TARGET_MIPS16
@@ -6799,50 +6804,50 @@ save_restore_insns (store_p, large_reg, large_offset, file)
 	      }
 	    else
 	      {
-		if (store_p || !TARGET_ABICALLS
-		    || (mips_abi != ABI_32 && mips_abi != ABI_O64)
-		    || regno != (PIC_OFFSET_TABLE_REGNUM - GP_REG_FIRST))
+		int r = regno;
+
+		/* The mips16 does not have an instruction to
+		   load $31, so we load $7 instead, and work
+		   things out in the caller.  */
+		if (TARGET_MIPS16 && ! store_p && r == GP_REG_FIRST + 31)
+		  r = GP_REG_FIRST + 7;
+		/* The mips16 sometimes needs to save $18.  */
+		if (TARGET_MIPS16
+		    && regno != GP_REG_FIRST + 31
+		    && ! M16_REG_P (regno))
 		  {
-		    int r = regno;
-
-		    /* The mips16 does not have an instruction to
-                       load $31, so we load $7 instead, and work
-                       things out in the caller.  */
-		    if (TARGET_MIPS16 && ! store_p && r == GP_REG_FIRST + 31)
-		      r = GP_REG_FIRST + 7;
-		      /* The mips16 sometimes needs to save $18.  */
-		    if (TARGET_MIPS16
-			&& regno != GP_REG_FIRST + 31
-			&& ! M16_REG_P (regno))
+		    if (! store_p)
+		      r = GP_REG_FIRST + 6;
+		    else
 		      {
-			if (! store_p)
-			  r = GP_REG_FIRST + 6;
-			else
-			  {
-			    r = GP_REG_FIRST + 3;
-			    fprintf (file, "\tmove\t%s,%s\n",
-				     reg_names[r], reg_names[regno]);
-			  }
+			r = GP_REG_FIRST + 3;
+			fprintf (file, "\tmove\t%s,%s\n",
+				 reg_names[r], reg_names[regno]);
 		      }
-		    fprintf (file, "\t%s\t%s,",
-			     (TARGET_64BIT
-			      ? (store_p) ? "sd" : "ld"
-			      : (store_p) ? "sw" : "lw"),
-			     reg_names[r]);
-		    fprintf (file, HOST_WIDE_INT_PRINT_DEC,
-			     gp_offset - base_offset);
-		    fprintf (file, "(%s)\n", reg_names[REGNO(base_reg_rtx)]);
-		    if (! store_p
-			&& TARGET_MIPS16
-			&& regno != GP_REG_FIRST + 31
-			&& ! M16_REG_P (regno))
-		      fprintf (file, "\tmove\t%s,%s\n",
-			       reg_names[regno], reg_names[r]);
 		  }
-
+		fprintf (file, "\t%s\t%s,",
+			 (TARGET_64BIT
+			  ? (store_p) ? "sd" : "ld"
+			  : (store_p) ? "sw" : "lw"),
+			 reg_names[r]);
+		fprintf (file, HOST_WIDE_INT_PRINT_DEC,
+			 gp_offset - base_offset);
+		fprintf (file, "(%s)\n", reg_names[REGNO(base_reg_rtx)]);
+		if (! store_p
+		    && TARGET_MIPS16
+		    && regno != GP_REG_FIRST + 31
+		    && ! M16_REG_P (regno))
+		  fprintf (file, "\tmove\t%s,%s\n",
+			   reg_names[regno], reg_names[r]);
 	      }
 	    gp_offset -= GET_MODE_SIZE (gpr_mode);
 	  }
+        /* If the restore is being supressed, still take into account
+	   the offset at which it is stored.  */
+ 	else if (BITSET_P (real_mask, regno - GP_REG_FIRST))
+ 	  {
+	    gp_offset -= GET_MODE_SIZE (gpr_mode);
+	  }
     }
   else
     base_reg_rtx = 0, base_offset  = 0;
-- 
GitLab