This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[patch] function.c: Move USE as far down as possible.


Hi,

Attached is a patch to move USE immediately before an epilogue as far
down as possible.

The motivation for this patch is that I want to write a peephole2 that
applies to a sequece of insns across a USE sitting right before an
epilogue.

Tested on i686-pc-linux-gnu.  OK to apply?

Kazu Hirata

2004-02-02  Kazu Hirata  <kazu@cs.umass.edu>

	* function.c (thread_prologue_and_epilogue_insns): Move USE
	immediately before an epilogue as far down as possible.

Index: function.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/function.c,v
retrieving revision 1.488
diff -u -r1.488 function.c
--- function.c	31 Jan 2004 08:02:47 -0000	1.488
+++ function.c	1 Feb 2004 18:24:05 -0000
@@ -7968,6 +7968,40 @@
 	}
     }
 #endif
+
+  /* If we have a USE, which is most likely that of the return value,
+     move it as far down as possible to create more opportunities for
+     peephole2 to kicks in.  */
+  if (epilogue_end)
+    {
+      rtx use = prev_nonnote_insn (epilogue_end);
+
+      if (use
+	  && INSN_P (use)
+	  && GET_CODE (PATTERN (use)) == USE
+	  && REG_P (XEXP (PATTERN (use), 0)))
+	{
+	  rtx reg = XEXP (PATTERN (use), 0);
+	  rtx insn;
+
+	  for (insn = next_nonnote_insn (use);
+	       insn;
+	       insn = next_nonnote_insn (insn))
+	    {
+	      if (GET_CODE (insn) == JUMP_INSN
+		  || reg_mentioned_p (reg, insn))
+		break;
+	    }
+
+	  if (insn)
+	    {
+	      rtx pat = PATTERN (use);
+
+	      delete_insn (use);
+	      emit_insn_before (pat, insn);
+	    }
+	}
+    }
 }
 
 /* Reposition the prologue-end and epilogue-begin notes after instruction


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]