From afbc2905362a947be1724eff9e8a26e90b62540a Mon Sep 17 00:00:00 2001
From: "J\"orn Rennecke" <amylaar@cygnus.co.uk>
Date: Thu, 24 Feb 2000 20:09:30 +0000
Subject: [PATCH] Fix breakage from 6th Feb thread_prologue_and_epilogue_insns
 change:

	* sh-protos.h (sh_need_epilogue): Declare.
	* sh.c (sh_need_epilogue_known): New static variable.
	(sh_need_epilogue): New function.
	(function_epilogue): Clear need_epilogue_known.
	* sh.md (return): Split into expander / insn pattern.
	Make the expander conditional on ! sh_need_epilogue ().

From-SVN: r32136
---
 gcc/ChangeLog             | 10 ++++++++++
 gcc/config/sh/sh-protos.h |  1 +
 gcc/config/sh/sh.c        | 21 +++++++++++++++++++++
 gcc/config/sh/sh.md       | 12 ++++++------
 4 files changed, 38 insertions(+), 6 deletions(-)

diff --git a/gcc/ChangeLog b/gcc/ChangeLog
index 225b3bcae343..8194605cf6f2 100644
--- a/gcc/ChangeLog
+++ b/gcc/ChangeLog
@@ -1,3 +1,13 @@
+Thu Feb 24 20:04:11 2000  J"orn Rennecke <amylaar@cygnus.co.uk>
+
+	Fix breakage from 6th Feb thread_prologue_and_epilogue_insns change:
+	* sh-protos.h (sh_need_epilogue): Declare.
+	* sh.c (sh_need_epilogue_known): New static variable.
+	(sh_need_epilogue): New function.
+	(function_epilogue): Clear need_epilogue_known.
+	* sh.md (return): Split into expander / insn pattern.
+	Make the expander conditional on ! sh_need_epilogue ().
+
 2000-02-24  Nathan Sidwell  <nathan@codesourcery.com>
 
 	* machmode.h (get_mode_alignment): Declare.
diff --git a/gcc/config/sh/sh-protos.h b/gcc/config/sh/sh-protos.h
index 273444b2c6de..402bf6068ab0 100644
--- a/gcc/config/sh/sh-protos.h
+++ b/gcc/config/sh/sh-protos.h
@@ -107,6 +107,7 @@ extern struct rtx_def *get_fpscr_rtx PARAMS ((void));
 extern void output_file_start PARAMS ((FILE *));
 extern void sh_expand_prologue PARAMS ((void));
 extern void sh_expand_epilogue PARAMS ((void));
+extern int sh_need_epilogue PARAMS ((void));
 extern void function_epilogue PARAMS ((FILE *, int));
 extern int initial_elimination_offset PARAMS ((int, int));
 extern void emit_fpscr_use PARAMS ((void));
diff --git a/gcc/config/sh/sh.c b/gcc/config/sh/sh.c
index 8c10ca55ee97..c90fdb373b4e 100644
--- a/gcc/config/sh/sh.c
+++ b/gcc/config/sh/sh.c
@@ -3919,6 +3919,26 @@ sh_expand_epilogue ()
     emit_insn (gen_sp_switch_2 ());
 }
 
+static int sh_need_epilogue_known = 0;
+
+int
+sh_need_epilogue ()
+{
+  if (! sh_need_epilogue_known)
+    {
+      rtx epilogue;
+
+      start_sequence ();
+      sh_expand_epilogue ();
+      epilogue = gen_sequence ();
+      end_sequence ();
+      sh_need_epilogue_known
+	= (GET_CODE (epilogue) == SEQUENCE && XVECLEN (epilogue, 0) == 0
+	   ? -1 : 1);
+    }
+  return sh_need_epilogue_known > 0;
+}
+
 /* Clear variables at function end.  */
 
 void
@@ -3927,6 +3947,7 @@ function_epilogue (stream, size)
      int size ATTRIBUTE_UNUSED;
 {
   trap_exit = pragma_interrupt = pragma_trapa = pragma_nosave_low_regs = 0;
+  sh_need_epilogue_known = 0;
   sp_switch = NULL_RTX;
 }
 
diff --git a/gcc/config/sh/sh.md b/gcc/config/sh/sh.md
index 903199e119bf..62aac30d9c99 100644
--- a/gcc/config/sh/sh.md
+++ b/gcc/config/sh/sh.md
@@ -3484,12 +3484,12 @@
 }"
   [(set_attr "length" "4")])
 
-;; ??? This is not the proper place to invoke another compiler pass;
-;; Alas, there is no proper place to put it.
-;; ??? This is also an odd place for the call to emit_fpscr_use.  It
-;; would be all right if it were for an define_expand for return, but
-;; that doesn't mix with emitting a prologue.
-(define_insn "return"
+(define_expand "return"
+  [(return)]
+  "reload_completed && ! sh_need_epilogue ()"
+  "")
+
+(define_insn "*return_i"
   [(return)]
   "reload_completed"
   "%@	%#"
-- 
GitLab