]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
re PR target/13585 (Incorrect optimisation of call to sfunc)
authorJ"orn Rennecke <joern.rennecke@superh.com>
Mon, 12 Jan 2004 17:03:25 +0000 (17:03 +0000)
committerJoern Rennecke <amylaar@gcc.gnu.org>
Mon, 12 Jan 2004 17:03:25 +0000 (17:03 +0000)
PR target/13585
* sh-protos.h (check_use_sfunc_addr): Declare.
* sh.c (extract_sfunc_addr, check_use_sfunc_addr): New functions.
* sh.md (use_sfunc_addr): Use check_use_sfunc_addr in insn predicate.

From-SVN: r75736

gcc/ChangeLog
gcc/config/sh/sh-protos.h
gcc/config/sh/sh.c
gcc/config/sh/sh.md

index 85568bc64622c7a64ca8972489a3a758e0973f67..d6a2c907d6b989936ca89949986b784dee1319f9 100644 (file)
@@ -1,3 +1,10 @@
+2004-01-12  J"orn Rennecke <joern.rennecke@superh.com>
+
+       PR target/13585
+       * sh-protos.h (check_use_sfunc_addr): Declare.
+       * sh.c (extract_sfunc_addr, check_use_sfunc_addr): New functions.
+       * sh.md (use_sfunc_addr): Use check_use_sfunc_addr in insn predicate.
+
 2004-01-12  Matthias Klose  <doko@debian.org>
 
        Backport from mainline
index 70d0ade0787300655c89fa5c09374239f6cbfa00..7c294625330e2ace0ff7492dfb1aaffe346fc8a0 100644 (file)
@@ -1,5 +1,5 @@
 /* Definitions of target machine for GNU compiler for Hitachi / SuperH SH.
-   Copyright (C) 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000
+   Copyright (C) 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2004
    Free Software Foundation, Inc.
    Contributed by Steve Chamberlain (sac@cygnus.com).
    Improved by Jim Wilson (wilson@cygnus.com).
@@ -131,6 +131,7 @@ extern bool sh_cannot_change_mode_class
 extern void sh_mark_label PARAMS ((rtx, int));
 extern int sh_register_move_cost
   PARAMS ((enum machine_mode mode, enum reg_class, enum reg_class));
+extern int check_use_sfunc_addr (rtx, rtx);
 
 #ifdef HARD_CONST
 extern void fpscr_set_from_mem PARAMS ((int, HARD_REG_SET));
index 04a67ef1f098c4771c57ebbd64c78332718e068d..b5db0d18bd7b31e2fa37ff841e0fd4dd20f7148c 100644 (file)
@@ -1,6 +1,6 @@
 /* Output routines for GCC for Hitachi / SuperH SH.
-   Copyright (C) 1993, 1994, 1995, 1997, 1997, 1998, 1999, 2000, 2001, 2002
-   Free Software Foundation, Inc.
+   Copyright (C) 1993, 1994, 1995, 1997, 1997, 1998, 1999, 2000, 2001, 2002,
+   2004 Free Software Foundation, Inc.
    Contributed by Steve Chamberlain (sac@cygnus.com).
    Improved by Jim Wilson (wilson@cygnus.com). 
 
@@ -7857,4 +7857,51 @@ sh_register_operand (op, mode)
   return register_operand (op, mode);
 }
 
+/* INSN is an sfunc; return the rtx that describes the address used.  */
+static rtx
+extract_sfunc_addr (rtx insn)
+{
+  rtx pattern, part = NULL_RTX;
+  int len, i;
+
+  pattern = PATTERN (insn);
+  len = XVECLEN (pattern, 0);
+  for (i = 0; i < len; i++)
+    {
+      part = XVECEXP (pattern, 0, i);
+      if (GET_CODE (part) == USE && GET_MODE (XEXP (part, 0)) == Pmode
+         && GENERAL_REGISTER_P (true_regnum (XEXP (part, 0))))
+       return XEXP (part, 0);
+    }
+  if (GET_CODE (XVECEXP (pattern, 0, 0)) == UNSPEC_VOLATILE)
+    return XVECEXP (XVECEXP (pattern, 0, 0), 0, 1);
+  abort ();
+}
+
+/* Verify that the register in use_sfunc_addr still agrees with the address
+   used in the sfunc.  This prevents fill_slots_from_thread from changing
+   use_sfunc_addr.
+   INSN is the use_sfunc_addr instruction, and REG is the register it
+   guards.  */
+int
+check_use_sfunc_addr (rtx insn, rtx reg)
+{
+  /* Search for the sfunc.  It should really come right after INSN.  */
+  while ((insn = NEXT_INSN (insn)))
+    {
+      if (GET_CODE (insn) == CODE_LABEL || GET_CODE (insn) == JUMP_INSN)
+       break;
+      if (! INSN_P (insn))
+       continue;
+       
+      if (GET_CODE (PATTERN (insn)) == SEQUENCE)
+       insn = XVECEXP (PATTERN (insn), 0, 0);
+      if (GET_CODE (PATTERN (insn)) != PARALLEL
+         || get_attr_type (insn) != TYPE_SFUNC)
+       continue;
+      return rtx_equal_p (extract_sfunc_addr (insn), reg);
+    }
+  abort ();
+}
+
 #include "gt-sh.h"
index 56f93cc14c8cd8d2dab8e0099be9bfe30a75bfba..21dca6e7ecf3092d12ad23a2caf98feb97f63cc0 100644 (file)
@@ -1,6 +1,6 @@
 ;;- Machine description for Hitachi / SuperH SH.
-;;  Copyright (C) 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002
-;;  Free Software Foundation, Inc.
+;;  Copyright (C) 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002,
+;;  2004 Free Software Foundation, Inc.
 ;;  Contributed by Steve Chamberlain (sac@cygnus.com).
 ;;  Improved by Jim Wilson (wilson@cygnus.com).
 
 (define_insn "use_sfunc_addr"
   [(set (reg:SI PR_REG)
        (unspec:SI [(match_operand:SI 0 "register_operand" "r")] UNSPEC_SFUNC))]
-  "TARGET_SH1"
+  "TARGET_SH1 && check_use_sfunc_addr (insn, operands[0])"
   ""
   [(set_attr "length" "0")])