reload1: detect chained reloads

DJ Delorie dj@redhat.com
Wed Mar 1 17:46:00 GMT 2006


This patch attempts to detect when two RELOAD_FOR_OPERAND_ADDRESS
reloads are chained; that is, the output of one is the input of the
other, and the intermediate is not used otherwise.  In such cases, the
two reloads should be able to use the same reload register, which is
required for ports with small numbers of base registers and small
frame displacements.  Bootstrap/regression tested on x86_64 linux,
also tested with m32c-elf (m32c needs this to build, with some other
m32c-specific patches I've got pending).  Ok?

	* reload1.c (reloads_unique_chain): New.
	(reloads_conflict): Call it.

Index: gcc/reload1.c
===================================================================
--- gcc/reload1.c	(revision 111581)
+++ gcc/reload1.c	(working copy)
@@ -4715,6 +4715,24 @@ reload_reg_reaches_end_p (unsigned int r
     }
 }
 
+/* Returns 1 if the reloads denoted by R1 and R2 are uniquely chained
+   - the output of one is the input of the other, and that
+   intermediate is not used by any other reload for this insn.  */
+static int
+reloads_unique_chain (int r1, int r2)
+{
+  int i;
+  if (! reg_mentioned_p (rld[r1].in, rld[r2].in))
+    return 0;
+  for (i=0; i<n_reloads; i++)
+    if (i != r1 && i != r2)
+      {
+	if (reg_mentioned_p (rld[r1].in, rld[i].in))
+	  return 0;
+      }
+  return 1;
+}
+
 /* Return 1 if the reloads denoted by R1 and R2 cannot share a register.
    Return 0 otherwise.
 
@@ -4763,7 +4781,8 @@ reloads_conflict (int r1, int r2)
 
     case RELOAD_FOR_OPERAND_ADDRESS:
       return (r2_type == RELOAD_FOR_INPUT || r2_type == RELOAD_FOR_INSN
-	      || r2_type == RELOAD_FOR_OPERAND_ADDRESS);
+	      || (r2_type == RELOAD_FOR_OPERAND_ADDRESS
+		  && !reloads_unique_chain (r1, r2)));
 
     case RELOAD_FOR_OPADDR_ADDR:
       return (r2_type == RELOAD_FOR_INPUT
@@ -6083,6 +6102,7 @@ deallocate_reload_reg (int r)
    This will not increase the number of spill registers needed and will
    prevent redundant code.  */
 
+extern const char *const reload_when_needed_name[];
 static void
 merge_assigned_reloads (rtx insn)
 {



More information about the Gcc-patches mailing list