OSDN Git Service

* pa.md (addvdi3, addvsi3, subvdi3, subvsi3, negvdi2, negvsi2): New
[pf3gnuchains/gcc-fork.git] / gcc / config / pa / pa.md
index 9a434a6..0adfe3f 100644 (file)
@@ -1,6 +1,6 @@
 ;;- Machine description for HP PA-RISC architecture for GCC compiler
 ;;   Copyright (C) 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001,
-;;   2002, 2003, 2004, 2005 Free Software Foundation, Inc.
+;;   2002, 2003, 2004, 2005, 2006 Free Software Foundation, Inc.
 ;;   Contributed by the Center for Software Science at the University
 ;;   of Utah.
 
@@ -18,8 +18,8 @@
 
 ;; You should have received a copy of the GNU General Public License
 ;; along with GCC; see the file COPYING.  If not, write to
-;; the Free Software Foundation, 59 Temple Place - Suite 330,
-;; Boston, MA 02111-1307, USA.
+;; the Free Software Foundation, 51 Franklin Street, Fifth Floor,
+;; Boston, MA 02110-1301, USA.
 
 ;; This gcc Version 2 machine description is inspired by sparc.md and
 ;; mips.md.
   [(UNSPEC_CFFC                0)      ; canonicalize_funcptr_for_compare
    (UNSPEC_GOTO                1)      ; indirect_goto
    (UNSPEC_DLTIND14R   2)      ; 
+   (UNSPEC_TP          3)
+   (UNSPEC_TLSGD       4)
+   (UNSPEC_TLSLDM      5)
+   (UNSPEC_TLSLDO      6)
+   (UNSPEC_TLSLDBASE   7)
+   (UNSPEC_TLSIE       8)
+   (UNSPEC_TLSLE       9)
   ])
 
 ;; UNSPEC_VOLATILE:
    (UNSPECV_LONGJMP    5)      ; builtin_longjmp
   ])
 
+;; Maximum pc-relative branch offsets.
+
+;; These numbers are a bit smaller than the maximum allowable offsets
+;; so that a few instructions may be inserted before the actual branch.
+
+(define_constants
+  [(MAX_12BIT_OFFSET     8184) ; 12-bit branch
+   (MAX_17BIT_OFFSET   262100) ; 17-bit branch
+  ])
+
 ;; Insn type.  Used to default other attribute values.
 
 ;; type "unary" insns have one input operand (1) and one output operand (0)
 (define_delay (eq_attr "type" "btable_branch,branch,parallel_branch")
   [(eq_attr "in_branch_delay" "true") (nil) (nil)])
 
-;; Floating point conditional branch delay slot description and
+;; Floating point conditional branch delay slot description.
 (define_delay (eq_attr "type" "fbranch")
   [(eq_attr "in_branch_delay" "true")
    (eq_attr "in_nullified_branch_delay" "true")
    (eq_attr "cpu" "8000"))
  "inm_8000,fdivsqrt_8000*6,rnm_8000")
 
-
+(include "predicates.md")
 \f
 ;; Compare instructions.
 ;; This controls RTL generation and register allocation.
   ""
   "*
 {
-  return output_cbranch (operands, INSN_ANNULLED_BRANCH_P (insn),
-                        get_attr_length (insn), 0, insn);
+  return output_cbranch (operands, 0, insn);
 }"
 [(set_attr "type" "cbranch")
  (set (attr "length")
     (cond [(lt (abs (minus (match_dup 0) (plus (pc) (const_int 8))))
-              (const_int 8184))
+              (const_int MAX_12BIT_OFFSET))
           (const_int 4)
           (lt (abs (minus (match_dup 0) (plus (pc) (const_int 8))))
-              (const_int 262100))
+              (const_int MAX_17BIT_OFFSET))
           (const_int 8)
+          (ne (symbol_ref "TARGET_PORTABLE_RUNTIME") (const_int 0))
+          (const_int 24)
           (eq (symbol_ref "flag_pic") (const_int 0))
           (const_int 20)]
          (const_int 28)))])
   ""
   "*
 {
-  return output_cbranch (operands, INSN_ANNULLED_BRANCH_P (insn),
-                        get_attr_length (insn), 1, insn);
+  return output_cbranch (operands, 1, insn);
 }"
 [(set_attr "type" "cbranch")
  (set (attr "length")
     (cond [(lt (abs (minus (match_dup 0) (plus (pc) (const_int 8))))
-              (const_int 8184))
+              (const_int MAX_12BIT_OFFSET))
           (const_int 4)
           (lt (abs (minus (match_dup 0) (plus (pc) (const_int 8))))
-              (const_int 262100))
+              (const_int MAX_17BIT_OFFSET))
           (const_int 8)
+          (ne (symbol_ref "TARGET_PORTABLE_RUNTIME") (const_int 0))
+          (const_int 24)
           (eq (symbol_ref "flag_pic") (const_int 0))
           (const_int 20)]
          (const_int 28)))])
   "TARGET_64BIT"
   "*
 {
-  return output_cbranch (operands, INSN_ANNULLED_BRANCH_P (insn),
-                        get_attr_length (insn), 0, insn);
+  return output_cbranch (operands, 0, insn);
 }"
 [(set_attr "type" "cbranch")
  (set (attr "length")
     (cond [(lt (abs (minus (match_dup 0) (plus (pc) (const_int 8))))
-              (const_int 8184))
+              (const_int MAX_12BIT_OFFSET))
           (const_int 4)
           (lt (abs (minus (match_dup 0) (plus (pc) (const_int 8))))
-              (const_int 262100))
+              (const_int MAX_17BIT_OFFSET))
           (const_int 8)
+          (ne (symbol_ref "TARGET_PORTABLE_RUNTIME") (const_int 0))
+          (const_int 24)
           (eq (symbol_ref "flag_pic") (const_int 0))
           (const_int 20)]
          (const_int 28)))])
   "TARGET_64BIT"
   "*
 {
-  return output_cbranch (operands, INSN_ANNULLED_BRANCH_P (insn),
-                        get_attr_length (insn), 1, insn);
+  return output_cbranch (operands, 1, insn);
 }"
 [(set_attr "type" "cbranch")
  (set (attr "length")
     (cond [(lt (abs (minus (match_dup 0) (plus (pc) (const_int 8))))
-              (const_int 8184))
+              (const_int MAX_12BIT_OFFSET))
           (const_int 4)
           (lt (abs (minus (match_dup 0) (plus (pc) (const_int 8))))
-              (const_int 262100))
+              (const_int MAX_17BIT_OFFSET))
           (const_int 8)
+          (ne (symbol_ref "TARGET_PORTABLE_RUNTIME") (const_int 0))
+          (const_int 24)
           (eq (symbol_ref "flag_pic") (const_int 0))
           (const_int 20)]
          (const_int 28)))])
   "TARGET_64BIT"
   "*
 {
-  return output_cbranch (operands, INSN_ANNULLED_BRANCH_P (insn),
-                        get_attr_length (insn), 0, insn);
+  return output_cbranch (operands, 0, insn);
 }"
 [(set_attr "type" "cbranch")
  (set (attr "length")
     (cond [(lt (abs (minus (match_dup 0) (plus (pc) (const_int 8))))
-              (const_int 8184))
+              (const_int MAX_12BIT_OFFSET))
           (const_int 4)
           (lt (abs (minus (match_dup 0) (plus (pc) (const_int 8))))
-              (const_int 262100))
+              (const_int MAX_17BIT_OFFSET))
           (const_int 8)
+          (ne (symbol_ref "TARGET_PORTABLE_RUNTIME") (const_int 0))
+          (const_int 24)
           (eq (symbol_ref "flag_pic") (const_int 0))
           (const_int 20)]
          (const_int 28)))])
   "TARGET_64BIT"
   "*
 {
-  return output_cbranch (operands, INSN_ANNULLED_BRANCH_P (insn),
-                        get_attr_length (insn), 1, insn);
+  return output_cbranch (operands, 1, insn);
 }"
 [(set_attr "type" "cbranch")
  (set (attr "length")
     (cond [(lt (abs (minus (match_dup 0) (plus (pc) (const_int 8))))
-              (const_int 8184))
+              (const_int MAX_12BIT_OFFSET))
           (const_int 4)
           (lt (abs (minus (match_dup 0) (plus (pc) (const_int 8))))
-              (const_int 262100))
+              (const_int MAX_17BIT_OFFSET))
           (const_int 8)
+          (ne (symbol_ref "TARGET_PORTABLE_RUNTIME") (const_int 0))
+          (const_int 24)
           (eq (symbol_ref "flag_pic") (const_int 0))
           (const_int 20)]
          (const_int 28)))])
   ""
   "*
 {
-  return output_bb (operands, INSN_ANNULLED_BRANCH_P (insn),
-                        get_attr_length (insn), 0, insn, 0);
+  return output_bb (operands, 0, insn, 0);
 }"
 [(set_attr "type" "cbranch")
  (set (attr "length")
-    (if_then_else (lt (abs (minus (match_dup 2) (plus (pc) (const_int 8))))
-                     (const_int 8184))
-           (const_int 4)
-          (const_int 8)))])
+    (cond [(lt (abs (minus (match_dup 2) (plus (pc) (const_int 8))))
+              (const_int MAX_12BIT_OFFSET))
+          (const_int 4)
+          (lt (abs (minus (match_dup 2) (plus (pc) (const_int 8))))
+              (const_int MAX_17BIT_OFFSET))
+          (const_int 8)
+          (ne (symbol_ref "TARGET_PORTABLE_RUNTIME") (const_int 0))
+          (const_int 24)
+          (eq (symbol_ref "flag_pic") (const_int 0))
+          (const_int 20)]
+         (const_int 28)))])
 
 (define_insn ""
   [(set (pc)
   "TARGET_64BIT"
   "*
 {
-  return output_bb (operands, INSN_ANNULLED_BRANCH_P (insn),
-                        get_attr_length (insn), 0, insn, 0);
+  return output_bb (operands, 0, insn, 0);
 }"
 [(set_attr "type" "cbranch")
  (set (attr "length")
-    (if_then_else (lt (abs (minus (match_dup 2) (plus (pc) (const_int 8))))
-                     (const_int 8184))
-           (const_int 4)
-          (const_int 8)))])
+    (cond [(lt (abs (minus (match_dup 2) (plus (pc) (const_int 8))))
+              (const_int MAX_12BIT_OFFSET))
+          (const_int 4)
+          (lt (abs (minus (match_dup 2) (plus (pc) (const_int 8))))
+              (const_int MAX_17BIT_OFFSET))
+          (const_int 8)
+          (ne (symbol_ref "TARGET_PORTABLE_RUNTIME") (const_int 0))
+          (const_int 24)
+          (eq (symbol_ref "flag_pic") (const_int 0))
+          (const_int 20)]
+         (const_int 28)))])
 
 (define_insn ""
   [(set (pc)
   ""
   "*
 {
-  return output_bb (operands, INSN_ANNULLED_BRANCH_P (insn),
-                        get_attr_length (insn), 1, insn, 0);
+  return output_bb (operands, 1, insn, 0);
 }"
 [(set_attr "type" "cbranch")
  (set (attr "length")
-    (if_then_else (lt (abs (minus (match_dup 2) (plus (pc) (const_int 8))))
-                     (const_int 8184))
-           (const_int 4)
-          (const_int 8)))])
+    (cond [(lt (abs (minus (match_dup 2) (plus (pc) (const_int 8))))
+              (const_int MAX_12BIT_OFFSET))
+          (const_int 4)
+          (lt (abs (minus (match_dup 2) (plus (pc) (const_int 8))))
+              (const_int MAX_17BIT_OFFSET))
+          (const_int 8)
+          (ne (symbol_ref "TARGET_PORTABLE_RUNTIME") (const_int 0))
+          (const_int 24)
+          (eq (symbol_ref "flag_pic") (const_int 0))
+          (const_int 20)]
+         (const_int 28)))])
 
 (define_insn ""
   [(set (pc)
   "TARGET_64BIT"
   "*
 {
-  return output_bb (operands, INSN_ANNULLED_BRANCH_P (insn),
-                        get_attr_length (insn), 1, insn, 0);
+  return output_bb (operands, 1, insn, 0);
 }"
 [(set_attr "type" "cbranch")
  (set (attr "length")
-    (if_then_else (lt (abs (minus (match_dup 2) (plus (pc) (const_int 8))))
-                     (const_int 8184))
-           (const_int 4)
-          (const_int 8)))])
+    (cond [(lt (abs (minus (match_dup 2) (plus (pc) (const_int 8))))
+              (const_int MAX_12BIT_OFFSET))
+          (const_int 4)
+          (lt (abs (minus (match_dup 2) (plus (pc) (const_int 8))))
+              (const_int MAX_17BIT_OFFSET))
+          (const_int 8)
+          (ne (symbol_ref "TARGET_PORTABLE_RUNTIME") (const_int 0))
+          (const_int 24)
+          (eq (symbol_ref "flag_pic") (const_int 0))
+          (const_int 20)]
+         (const_int 28)))])
 
 (define_insn ""
   [(set (pc)
   ""
   "*
 {
-  return output_bb (operands, INSN_ANNULLED_BRANCH_P (insn),
-                        get_attr_length (insn), 0, insn, 1);
+  return output_bb (operands, 0, insn, 1);
 }"
 [(set_attr "type" "cbranch")
  (set (attr "length")
-    (if_then_else (lt (abs (minus (match_dup 2) (plus (pc) (const_int 8))))
-                     (const_int 8184))
-           (const_int 4)
-          (const_int 8)))])
+    (cond [(lt (abs (minus (match_dup 2) (plus (pc) (const_int 8))))
+              (const_int MAX_12BIT_OFFSET))
+          (const_int 4)
+          (lt (abs (minus (match_dup 2) (plus (pc) (const_int 8))))
+              (const_int MAX_17BIT_OFFSET))
+          (const_int 8)
+          (ne (symbol_ref "TARGET_PORTABLE_RUNTIME") (const_int 0))
+          (const_int 24)
+          (eq (symbol_ref "flag_pic") (const_int 0))
+          (const_int 20)]
+         (const_int 28)))])
 
 (define_insn ""
   [(set (pc)
   "TARGET_64BIT"
   "*
 {
-  return output_bb (operands, INSN_ANNULLED_BRANCH_P (insn),
-                        get_attr_length (insn), 0, insn, 1);
+  return output_bb (operands, 0, insn, 1);
 }"
 [(set_attr "type" "cbranch")
  (set (attr "length")
-    (if_then_else (lt (abs (minus (match_dup 2) (plus (pc) (const_int 8))))
-                     (const_int 8184))
-           (const_int 4)
-          (const_int 8)))])
+    (cond [(lt (abs (minus (match_dup 2) (plus (pc) (const_int 8))))
+              (const_int MAX_12BIT_OFFSET))
+          (const_int 4)
+          (lt (abs (minus (match_dup 2) (plus (pc) (const_int 8))))
+              (const_int MAX_17BIT_OFFSET))
+          (const_int 8)
+          (ne (symbol_ref "TARGET_PORTABLE_RUNTIME") (const_int 0))
+          (const_int 24)
+          (eq (symbol_ref "flag_pic") (const_int 0))
+          (const_int 20)]
+         (const_int 28)))])
 
 (define_insn ""
   [(set (pc)
   ""
   "*
 {
-  return output_bb (operands, INSN_ANNULLED_BRANCH_P (insn),
-                        get_attr_length (insn), 1, insn, 1);
+  return output_bb (operands, 1, insn, 1);
 }"
 [(set_attr "type" "cbranch")
  (set (attr "length")
-    (if_then_else (lt (abs (minus (match_dup 2) (plus (pc) (const_int 8))))
-                     (const_int 8184))
-           (const_int 4)
-          (const_int 8)))])
+    (cond [(lt (abs (minus (match_dup 2) (plus (pc) (const_int 8))))
+              (const_int MAX_12BIT_OFFSET))
+          (const_int 4)
+          (lt (abs (minus (match_dup 2) (plus (pc) (const_int 8))))
+              (const_int MAX_17BIT_OFFSET))
+          (const_int 8)
+          (ne (symbol_ref "TARGET_PORTABLE_RUNTIME") (const_int 0))
+          (const_int 24)
+          (eq (symbol_ref "flag_pic") (const_int 0))
+          (const_int 20)]
+         (const_int 28)))])
 
 (define_insn ""
   [(set (pc)
   "TARGET_64BIT"
   "*
 {
-  return output_bb (operands, INSN_ANNULLED_BRANCH_P (insn),
-                        get_attr_length (insn), 1, insn, 1);
+  return output_bb (operands, 1, insn, 1);
 }"
 [(set_attr "type" "cbranch")
  (set (attr "length")
-    (if_then_else (lt (abs (minus (match_dup 2) (plus (pc) (const_int 8))))
-                     (const_int 8184))
-           (const_int 4)
-          (const_int 8)))])
+    (cond [(lt (abs (minus (match_dup 2) (plus (pc) (const_int 8))))
+              (const_int MAX_12BIT_OFFSET))
+          (const_int 4)
+          (lt (abs (minus (match_dup 2) (plus (pc) (const_int 8))))
+              (const_int MAX_17BIT_OFFSET))
+          (const_int 8)
+          (ne (symbol_ref "TARGET_PORTABLE_RUNTIME") (const_int 0))
+          (const_int 24)
+          (eq (symbol_ref "flag_pic") (const_int 0))
+          (const_int 20)]
+         (const_int 28)))])
 
 ;; Branch on Variable Bit patterns.
 (define_insn ""
   ""
   "*
 {
-  return output_bvb (operands, INSN_ANNULLED_BRANCH_P (insn),
-                    get_attr_length (insn), 0, insn, 0);
+  return output_bvb (operands, 0, insn, 0);
 }"
 [(set_attr "type" "cbranch")
  (set (attr "length")
-    (if_then_else (lt (abs (minus (match_dup 2) (plus (pc) (const_int 8))))
-                     (const_int 8184))
-           (const_int 4)
-          (const_int 8)))])
+    (cond [(lt (abs (minus (match_dup 2) (plus (pc) (const_int 8))))
+              (const_int MAX_12BIT_OFFSET))
+          (const_int 4)
+          (lt (abs (minus (match_dup 2) (plus (pc) (const_int 8))))
+              (const_int MAX_17BIT_OFFSET))
+          (const_int 8)
+          (ne (symbol_ref "TARGET_PORTABLE_RUNTIME") (const_int 0))
+          (const_int 24)
+          (eq (symbol_ref "flag_pic") (const_int 0))
+          (const_int 20)]
+         (const_int 28)))])
 
 (define_insn ""
   [(set (pc)
   "TARGET_64BIT"
   "*
 {
-  return output_bvb (operands, INSN_ANNULLED_BRANCH_P (insn),
-                    get_attr_length (insn), 0, insn, 0);
+  return output_bvb (operands, 0, insn, 0);
 }"
 [(set_attr "type" "cbranch")
  (set (attr "length")
-    (if_then_else (lt (abs (minus (match_dup 2) (plus (pc) (const_int 8))))
-                     (const_int 8184))
-           (const_int 4)
-          (const_int 8)))])
+    (cond [(lt (abs (minus (match_dup 2) (plus (pc) (const_int 8))))
+              (const_int MAX_12BIT_OFFSET))
+          (const_int 4)
+          (lt (abs (minus (match_dup 2) (plus (pc) (const_int 8))))
+              (const_int MAX_17BIT_OFFSET))
+          (const_int 8)
+          (ne (symbol_ref "TARGET_PORTABLE_RUNTIME") (const_int 0))
+          (const_int 24)
+          (eq (symbol_ref "flag_pic") (const_int 0))
+          (const_int 20)]
+         (const_int 28)))])
 
 (define_insn ""
   [(set (pc)
   ""
   "*
 {
-  return output_bvb (operands, INSN_ANNULLED_BRANCH_P (insn),
-                    get_attr_length (insn), 1, insn, 0);
+  return output_bvb (operands, 1, insn, 0);
 }"
 [(set_attr "type" "cbranch")
  (set (attr "length")
-    (if_then_else (lt (abs (minus (match_dup 2) (plus (pc) (const_int 8))))
-                     (const_int 8184))
-           (const_int 4)
-          (const_int 8)))])
+    (cond [(lt (abs (minus (match_dup 2) (plus (pc) (const_int 8))))
+              (const_int MAX_12BIT_OFFSET))
+          (const_int 4)
+          (lt (abs (minus (match_dup 2) (plus (pc) (const_int 8))))
+              (const_int MAX_17BIT_OFFSET))
+          (const_int 8)
+          (ne (symbol_ref "TARGET_PORTABLE_RUNTIME") (const_int 0))
+          (const_int 24)
+          (eq (symbol_ref "flag_pic") (const_int 0))
+          (const_int 20)]
+         (const_int 28)))])
 
 (define_insn ""
   [(set (pc)
   "TARGET_64BIT"
   "*
 {
-  return output_bvb (operands, INSN_ANNULLED_BRANCH_P (insn),
-                    get_attr_length (insn), 1, insn, 0);
+  return output_bvb (operands, 1, insn, 0);
 }"
 [(set_attr "type" "cbranch")
  (set (attr "length")
-    (if_then_else (lt (abs (minus (match_dup 2) (plus (pc) (const_int 8))))
-                     (const_int 8184))
-           (const_int 4)
-          (const_int 8)))])
+    (cond [(lt (abs (minus (match_dup 2) (plus (pc) (const_int 8))))
+              (const_int MAX_12BIT_OFFSET))
+          (const_int 4)
+          (lt (abs (minus (match_dup 2) (plus (pc) (const_int 8))))
+              (const_int MAX_17BIT_OFFSET))
+          (const_int 8)
+          (ne (symbol_ref "TARGET_PORTABLE_RUNTIME") (const_int 0))
+          (const_int 24)
+          (eq (symbol_ref "flag_pic") (const_int 0))
+          (const_int 20)]
+         (const_int 28)))])
 
 (define_insn ""
   [(set (pc)
   ""
   "*
 {
-  return output_bvb (operands, INSN_ANNULLED_BRANCH_P (insn),
-                    get_attr_length (insn), 0, insn, 1);
+  return output_bvb (operands, 0, insn, 1);
 }"
 [(set_attr "type" "cbranch")
  (set (attr "length")
-    (if_then_else (lt (abs (minus (match_dup 2) (plus (pc) (const_int 8))))
-                     (const_int 8184))
-           (const_int 4)
-          (const_int 8)))])
+    (cond [(lt (abs (minus (match_dup 2) (plus (pc) (const_int 8))))
+              (const_int MAX_12BIT_OFFSET))
+          (const_int 4)
+          (lt (abs (minus (match_dup 2) (plus (pc) (const_int 8))))
+              (const_int MAX_17BIT_OFFSET))
+          (const_int 8)
+          (ne (symbol_ref "TARGET_PORTABLE_RUNTIME") (const_int 0))
+          (const_int 24)
+          (eq (symbol_ref "flag_pic") (const_int 0))
+          (const_int 20)]
+         (const_int 28)))])
 
 (define_insn ""
   [(set (pc)
   "TARGET_64BIT"
   "*
 {
-  return output_bvb (operands, INSN_ANNULLED_BRANCH_P (insn),
-                    get_attr_length (insn), 0, insn, 1);
+  return output_bvb (operands, 0, insn, 1);
 }"
 [(set_attr "type" "cbranch")
  (set (attr "length")
-    (if_then_else (lt (abs (minus (match_dup 2) (plus (pc) (const_int 8))))
-                     (const_int 8184))
-           (const_int 4)
-          (const_int 8)))])
+    (cond [(lt (abs (minus (match_dup 2) (plus (pc) (const_int 8))))
+              (const_int MAX_12BIT_OFFSET))
+          (const_int 4)
+          (lt (abs (minus (match_dup 2) (plus (pc) (const_int 8))))
+              (const_int MAX_17BIT_OFFSET))
+          (const_int 8)
+          (ne (symbol_ref "TARGET_PORTABLE_RUNTIME") (const_int 0))
+          (const_int 24)
+          (eq (symbol_ref "flag_pic") (const_int 0))
+          (const_int 20)]
+         (const_int 28)))])
 
 (define_insn ""
   [(set (pc)
   ""
   "*
 {
-  return output_bvb (operands, INSN_ANNULLED_BRANCH_P (insn),
-                    get_attr_length (insn), 1, insn, 1);
+  return output_bvb (operands, 1, insn, 1);
 }"
 [(set_attr "type" "cbranch")
  (set (attr "length")
-    (if_then_else (lt (abs (minus (match_dup 2) (plus (pc) (const_int 8))))
-                     (const_int 8184))
-           (const_int 4)
-          (const_int 8)))])
+    (cond [(lt (abs (minus (match_dup 2) (plus (pc) (const_int 8))))
+              (const_int MAX_12BIT_OFFSET))
+          (const_int 4)
+          (lt (abs (minus (match_dup 2) (plus (pc) (const_int 8))))
+              (const_int MAX_17BIT_OFFSET))
+          (const_int 8)
+          (ne (symbol_ref "TARGET_PORTABLE_RUNTIME") (const_int 0))
+          (const_int 24)
+          (eq (symbol_ref "flag_pic") (const_int 0))
+          (const_int 20)]
+         (const_int 28)))])
 
 (define_insn ""
   [(set (pc)
   "TARGET_64BIT"
   "*
 {
-  return output_bvb (operands, INSN_ANNULLED_BRANCH_P (insn),
-                    get_attr_length (insn), 1, insn, 1);
+  return output_bvb (operands, 1, insn, 1);
 }"
 [(set_attr "type" "cbranch")
  (set (attr "length")
-    (if_then_else (lt (abs (minus (match_dup 2) (plus (pc) (const_int 8))))
-                     (const_int 8184))
-           (const_int 4)
-          (const_int 8)))])
+    (cond [(lt (abs (minus (match_dup 2) (plus (pc) (const_int 8))))
+              (const_int MAX_12BIT_OFFSET))
+          (const_int 4)
+          (lt (abs (minus (match_dup 2) (plus (pc) (const_int 8))))
+              (const_int MAX_17BIT_OFFSET))
+          (const_int 8)
+          (ne (symbol_ref "TARGET_PORTABLE_RUNTIME") (const_int 0))
+          (const_int 24)
+          (eq (symbol_ref "flag_pic") (const_int 0))
+          (const_int 20)]
+         (const_int 28)))])
 
 ;; Floating point branches
+
+;; ??? Nullification is handled differently from other branches.
+;; If nullification is specified, the delay slot is nullified on any
+;; taken branch regardless of branch direction.
 (define_insn ""
   [(set (pc) (if_then_else (ne (reg:CCFP 0) (const_int 0))
                           (label_ref (match_operand 0 "" ""))
                           (pc)))]
-  "! TARGET_SOFT_FLOAT"
+  "!TARGET_SOFT_FLOAT"
   "*
 {
-  if (INSN_ANNULLED_BRANCH_P (insn))
-    return \"ftest\;b,n %0\";
+  int length = get_attr_length (insn);
+  rtx xoperands[1];
+  int nullify, xdelay;
+
+  if (length < 16)
+    return \"ftest\;b%* %l0\";
+
+  if (dbr_sequence_length () == 0 || INSN_ANNULLED_BRANCH_P (insn))
+    {
+      nullify = 1;
+      xdelay = 0;
+      xoperands[0] = GEN_INT (length - 8);
+    }
+  else
+    {
+      nullify = 0;
+      xdelay = 1;
+      xoperands[0] = GEN_INT (length - 4);
+    }
+
+  if (nullify)
+    output_asm_insn (\"ftest\;add,tr %%r0,%%r0,%%r0\;b,n .+%0\", xoperands);
   else
-    return \"ftest\;b%* %0\";
+    output_asm_insn (\"ftest\;add,tr %%r0,%%r0,%%r0\;b .+%0\", xoperands);
+  return output_lbranch (operands[0], insn, xdelay);
 }"
-  [(set_attr "type" "fbranch")
-   (set_attr "length" "8")])
+[(set_attr "type" "fbranch")
+ (set (attr "length")
+    (cond [(lt (abs (minus (match_dup 0) (plus (pc) (const_int 8))))
+              (const_int MAX_17BIT_OFFSET))
+          (const_int 8)
+          (ne (symbol_ref "TARGET_PORTABLE_RUNTIME") (const_int 0))
+          (const_int 32)
+          (eq (symbol_ref "flag_pic") (const_int 0))
+          (const_int 28)]
+         (const_int 36)))])
 
 (define_insn ""
   [(set (pc) (if_then_else (ne (reg:CCFP 0) (const_int 0))
                           (pc)
                           (label_ref (match_operand 0 "" ""))))]
-  "! TARGET_SOFT_FLOAT"
+  "!TARGET_SOFT_FLOAT"
   "*
 {
-  if (INSN_ANNULLED_BRANCH_P (insn))
-    return \"ftest\;add,tr %%r0,%%r0,%%r0\;b,n %0\";
-  else
+  int length = get_attr_length (insn);
+  rtx xoperands[1];
+  int nullify, xdelay;
+
+  if (length < 16)
     return \"ftest\;add,tr %%r0,%%r0,%%r0\;b%* %0\";
+
+  if (dbr_sequence_length () == 0 || INSN_ANNULLED_BRANCH_P (insn))
+    {
+      nullify = 1;
+      xdelay = 0;
+      xoperands[0] = GEN_INT (length - 4);
+    }
+  else
+    {
+      nullify = 0;
+      xdelay = 1;
+      xoperands[0] = GEN_INT (length);
+    }
+
+  if (nullify)
+    output_asm_insn (\"ftest\;b,n .+%0\", xoperands);
+  else
+    output_asm_insn (\"ftest\;b .+%0\", xoperands);
+  return output_lbranch (operands[0], insn, xdelay);
 }"
-  [(set_attr "type" "fbranch")
-   (set_attr "length" "12")])
+[(set_attr "type" "fbranch")
+ (set (attr "length")
+    (cond [(lt (abs (minus (match_dup 0) (plus (pc) (const_int 8))))
+              (const_int MAX_17BIT_OFFSET))
+          (const_int 12)
+          (ne (symbol_ref "TARGET_PORTABLE_RUNTIME") (const_int 0))
+          (const_int 28)
+          (eq (symbol_ref "flag_pic") (const_int 0))
+          (const_int 24)]
+         (const_int 32)))])
 
 ;; Move instructions
 
     DONE;
 }")
 
-;; Reloading an SImode or DImode value requires a scratch register if
-;; going in to or out of float point registers.
+;; Handle SImode input reloads requiring %r1 as a scratch register.
+(define_expand "reload_insi_r1"
+  [(set (match_operand:SI 0 "register_operand" "=Z")
+       (match_operand:SI 1 "non_hard_reg_operand" ""))
+   (clobber (match_operand:SI 2 "register_operand" "=&a"))]
+  ""
+  "
+{
+  if (emit_move_sequence (operands, SImode, operands[2]))
+    DONE;
 
+  /* We don't want the clobber emitted, so handle this ourselves.  */
+  emit_insn (gen_rtx_SET (VOIDmode, operands[0], operands[1]));
+  DONE;
+}")
+
+;; Handle SImode input reloads requiring a general register as a
+;; scratch register.
 (define_expand "reload_insi"
   [(set (match_operand:SI 0 "register_operand" "=Z")
        (match_operand:SI 1 "non_hard_reg_operand" ""))
   DONE;
 }")
 
+;; Handle SImode output reloads requiring a general register as a
+;; scratch register.
 (define_expand "reload_outsi"
   [(set (match_operand:SI 0 "non_hard_reg_operand" "")
        (match_operand:SI 1  "register_operand" "Z"))
 
 (define_insn ""
   [(set (match_operand:SI 0 "move_dest_operand"
+                         "=r,r,r,r,r,r,Q,!*q,!r,!*f,*f,T,!r,!f")
+       (match_operand:SI 1 "move_src_operand"
+                         "A,r,J,N,K,RQ,rM,!rM,!*q,!*fM,RT,*f,!f,!r"))]
+  "(register_operand (operands[0], SImode)
+    || reg_or_0_operand (operands[1], SImode))
+   && !TARGET_SOFT_FLOAT
+   && !TARGET_64BIT"
+  "@
+   ldw RT'%A1,%0
+   copy %1,%0
+   ldi %1,%0
+   ldil L'%1,%0
+   {zdepi|depwi,z} %Z1,%0
+   ldw%M1 %1,%0
+   stw%M0 %r1,%0
+   mtsar %r1
+   {mfctl|mfctl,w} %%sar,%0
+   fcpy,sgl %f1,%0
+   fldw%F1 %1,%0
+   fstw%F0 %1,%0
+   {fstws|fstw} %1,-16(%%sp)\n\t{ldws|ldw} -16(%%sp),%0
+   {stws|stw} %1,-16(%%sp)\n\t{fldws|fldw} -16(%%sp),%0"
+  [(set_attr "type" "load,move,move,move,shift,load,store,move,move,fpalu,fpload,fpstore,move,move")
+   (set_attr "pa_combine_type" "addmove")
+   (set_attr "length" "4,4,4,4,4,4,4,4,4,4,4,4,8,8")])
+
+(define_insn ""
+  [(set (match_operand:SI 0 "move_dest_operand"
                          "=r,r,r,r,r,r,Q,!*q,!r,!*f,*f,T")
        (match_operand:SI 1 "move_src_operand"
                          "A,r,J,N,K,RQ,rM,!rM,!*q,!*fM,RT,*f"))]
   "(register_operand (operands[0], SImode)
     || reg_or_0_operand (operands[1], SImode))
-   && !TARGET_SOFT_FLOAT"
+   && !TARGET_SOFT_FLOAT
+   && TARGET_64BIT"
   "@
    ldw RT'%A1,%0
    copy %1,%0
         (match_operand:SI 3 "register_operand" ""))]
   "!TARGET_SOFT_FLOAT
    && !TARGET_DISABLE_INDEXING
-   && REG_OK_FOR_BASE_P (operands[1])
-   && (TARGET_NO_SPACE_REGS
-       || (!REG_POINTER (operands[1]) && REG_POINTER (operands[2])))
+   && TARGET_NO_SPACE_REGS
+   && REG_OK_FOR_INDEX_P (operands[1])
+   && REG_OK_FOR_BASE_P (operands[2])
    && FP_REGNO_P (REGNO (operands[3]))"
   [(set (mem:SI (plus:SI (match_dup 1) (match_dup 2)))
        (match_dup 3))
         (match_operand:SI 3 "register_operand" ""))]
   "!TARGET_SOFT_FLOAT
    && !TARGET_DISABLE_INDEXING
-   && REG_OK_FOR_BASE_P (operands[2])
-   && (TARGET_NO_SPACE_REGS
-       || (REG_POINTER (operands[1]) && !REG_POINTER (operands[2])))
+   && TARGET_NO_SPACE_REGS
+   && REG_OK_FOR_BASE_P (operands[1])
+   && REG_OK_FOR_INDEX_P (operands[2])
    && FP_REGNO_P (REGNO (operands[3]))"
   [(set (mem:SI (plus:SI (match_dup 2) (match_dup 1)))
        (match_dup 3))
   "!TARGET_SOFT_FLOAT
    && !TARGET_DISABLE_INDEXING
    && TARGET_64BIT
-   && REG_OK_FOR_BASE_P (operands[1])
-   && (TARGET_NO_SPACE_REGS
-       || (!REG_POINTER (operands[1]) && REG_POINTER (operands[2])))
+   && TARGET_NO_SPACE_REGS
+   && REG_OK_FOR_INDEX_P (operands[1])
+   && REG_OK_FOR_BASE_P (operands[2])
    && FP_REGNO_P (REGNO (operands[3]))"
   [(set (mem:SI (plus:DI (match_dup 1) (match_dup 2)))
        (match_dup 3))
   "!TARGET_SOFT_FLOAT
    && !TARGET_DISABLE_INDEXING
    && TARGET_64BIT
-   && REG_OK_FOR_BASE_P (operands[2])
-   && (TARGET_NO_SPACE_REGS
-       || (REG_POINTER (operands[1]) && !REG_POINTER (operands[2])))
+   && TARGET_NO_SPACE_REGS
+   && REG_OK_FOR_BASE_P (operands[1])
+   && REG_OK_FOR_INDEX_P (operands[2])
    && FP_REGNO_P (REGNO (operands[3]))"
   [(set (mem:SI (plus:DI (match_dup 2) (match_dup 1)))
        (match_dup 3))
   "!is_function_label_plus_const (operands[2])"
   "*
 {
-  if (flag_pic && symbolic_operand (operands[2], Pmode))
-    abort ();
-  else if (symbolic_operand (operands[2], Pmode))
+  gcc_assert (!flag_pic || !symbolic_operand (operands[2], Pmode));
+  
+  if (symbolic_operand (operands[2], Pmode))
     return \"ldo RR'%G2(%1),%0\";
   else
     return \"ldo R'%G2(%1),%0\";
 
 (define_insn ""
   [(set (match_operand:HI 0 "move_dest_operand"
+                         "=r,r,r,r,r,Q,!*q,!r,!*f,!r,!f")
+       (match_operand:HI 1 "move_src_operand"
+                         "r,J,N,K,RQ,rM,!rM,!*q,!*fM,!f,!r"))]
+  "(register_operand (operands[0], HImode)
+    || reg_or_0_operand (operands[1], HImode))
+   && !TARGET_SOFT_FLOAT
+   && !TARGET_64BIT"
+  "@
+   copy %1,%0
+   ldi %1,%0
+   ldil L'%1,%0
+   {zdepi|depwi,z} %Z1,%0
+   ldh%M1 %1,%0
+   sth%M0 %r1,%0
+   mtsar %r1
+   {mfctl|mfctl,w} %sar,%0
+   fcpy,sgl %f1,%0
+   {fstws|fstw} %1,-16(%%sp)\n\t{ldws|ldw} -16(%%sp),%0
+   {stws|stw} %1,-16(%%sp)\n\t{fldws|fldw} -16(%%sp),%0"
+  [(set_attr "type" "move,move,move,shift,load,store,move,move,move,move,move")
+   (set_attr "pa_combine_type" "addmove")
+   (set_attr "length" "4,4,4,4,4,4,4,4,4,8,8")])
+
+(define_insn ""
+  [(set (match_operand:HI 0 "move_dest_operand"
                          "=r,r,r,r,r,Q,!*q,!r,!*f")
        (match_operand:HI 1 "move_src_operand"
                          "r,J,N,K,RQ,rM,!rM,!*q,!*fM"))]
-  "register_operand (operands[0], HImode)
-   || reg_or_0_operand (operands[1], HImode)"
+  "(register_operand (operands[0], HImode)
+    || reg_or_0_operand (operands[1], HImode))
+   && !TARGET_SOFT_FLOAT
+   && TARGET_64BIT"
   "@
    copy %1,%0
    ldi %1,%0
    mtsar %r1
    {mfctl|mfctl,w} %sar,%0
    fcpy,sgl %f1,%0"
-  [(set_attr "type" "move,move,move,shift,load,store,move,move,fpalu")
+  [(set_attr "type" "move,move,move,shift,load,store,move,move,move")
    (set_attr "pa_combine_type" "addmove")
    (set_attr "length" "4,4,4,4,4,4,4,4,4")])
 
 (define_insn ""
+  [(set (match_operand:HI 0 "move_dest_operand"
+                         "=r,r,r,r,r,Q,!*q,!r")
+       (match_operand:HI 1 "move_src_operand"
+                         "r,J,N,K,RQ,rM,!rM,!*q"))]
+  "(register_operand (operands[0], HImode)
+    || reg_or_0_operand (operands[1], HImode))
+   && TARGET_SOFT_FLOAT"
+  "@
+   copy %1,%0
+   ldi %1,%0
+   ldil L'%1,%0
+   {zdepi|depwi,z} %Z1,%0
+   ldh%M1 %1,%0
+   sth%M0 %r1,%0
+   mtsar %r1
+   {mfctl|mfctl,w} %sar,%0"
+  [(set_attr "type" "move,move,move,shift,load,store,move,move")
+   (set_attr "pa_combine_type" "addmove")
+   (set_attr "length" "4,4,4,4,4,4,4,4")])
+
+(define_insn ""
   [(set (match_operand:HI 0 "register_operand" "=r")
        (mem:HI (plus:SI (match_operand:SI 1 "register_operand" "+r")
                         (match_operand:SI 2 "int5_operand" "L"))))
 
 (define_insn ""
   [(set (match_operand:QI 0 "move_dest_operand"
+                         "=r,r,r,r,r,Q,!*q,!r,!*f,!r,!f")
+       (match_operand:QI 1 "move_src_operand"
+                         "r,J,N,K,RQ,rM,!rM,!*q,!*fM,!f,!r"))]
+  "(register_operand (operands[0], QImode)
+    || reg_or_0_operand (operands[1], QImode))
+   && !TARGET_SOFT_FLOAT
+   && !TARGET_64BIT"
+  "@
+   copy %1,%0
+   ldi %1,%0
+   ldil L'%1,%0
+   {zdepi|depwi,z} %Z1,%0
+   ldb%M1 %1,%0
+   stb%M0 %r1,%0
+   mtsar %r1
+   {mfctl|mfctl,w} %%sar,%0
+   fcpy,sgl %f1,%0
+   {fstws|fstw} %1,-16(%%sp)\n\t{ldws|ldw} -16(%%sp),%0
+   {stws|stw} %1,-16(%%sp)\n\t{fldws|fldw} -16(%%sp),%0"
+  [(set_attr "type" "move,move,move,shift,load,store,move,move,move,move,move")
+   (set_attr "pa_combine_type" "addmove")
+   (set_attr "length" "4,4,4,4,4,4,4,4,4,8,8")])
+
+(define_insn ""
+  [(set (match_operand:QI 0 "move_dest_operand"
                          "=r,r,r,r,r,Q,!*q,!r,!*f")
        (match_operand:QI 1 "move_src_operand"
                          "r,J,N,K,RQ,rM,!rM,!*q,!*fM"))]
-  "register_operand (operands[0], QImode)
-   || reg_or_0_operand (operands[1], QImode)"
+  "(register_operand (operands[0], QImode)
+    || reg_or_0_operand (operands[1], QImode))
+   && !TARGET_SOFT_FLOAT
+   && TARGET_64BIT"
   "@
    copy %1,%0
    ldi %1,%0
    mtsar %r1
    {mfctl|mfctl,w} %%sar,%0
    fcpy,sgl %f1,%0"
-  [(set_attr "type" "move,move,move,shift,load,store,move,move,fpalu")
+  [(set_attr "type" "move,move,move,shift,load,store,move,move,move")
    (set_attr "pa_combine_type" "addmove")
    (set_attr "length" "4,4,4,4,4,4,4,4,4")])
 
 (define_insn ""
+  [(set (match_operand:QI 0 "move_dest_operand"
+                         "=r,r,r,r,r,Q,!*q,!r")
+       (match_operand:QI 1 "move_src_operand"
+                         "r,J,N,K,RQ,rM,!rM,!*q"))]
+  "(register_operand (operands[0], QImode)
+    || reg_or_0_operand (operands[1], QImode))
+   && TARGET_SOFT_FLOAT"
+  "@
+   copy %1,%0
+   ldi %1,%0
+   ldil L'%1,%0
+   {zdepi|depwi,z} %Z1,%0
+   ldb%M1 %1,%0
+   stb%M0 %r1,%0
+   mtsar %r1
+   {mfctl|mfctl,w} %%sar,%0"
+  [(set_attr "type" "move,move,move,shift,load,store,move,move")
+   (set_attr "pa_combine_type" "addmove")
+   (set_attr "length" "4,4,4,4,4,4,4,4")])
+
+(define_insn ""
   [(set (match_operand:QI 0 "register_operand" "=r")
        (mem:QI (plus:SI (match_operand:SI 1 "register_operand" "+r")
                         (match_operand:SI 2 "int5_operand" "L"))))
   "* return output_block_move (operands, !which_alternative);"
   [(set_attr "type" "multi,multi")])
 
-(define_expand "clrmemsi"
+(define_expand "setmemsi"
   [(parallel [(set (match_operand:BLK 0 "" "")
-                  (const_int 0))
-             (clobber (match_dup 3))
+                  (match_operand 2 "const_int_operand" ""))
              (clobber (match_dup 4))
+             (clobber (match_dup 5))
              (use (match_operand:SI 1 "arith_operand" ""))
-             (use (match_operand:SI 2 "const_int_operand" ""))])]
+             (use (match_operand:SI 3 "const_int_operand" ""))])]
   "!TARGET_64BIT && optimize > 0"
   "
 {
   int size, align;
 
+  /* If value to set is not zero, use the library routine.  */
+  if (operands[2] != const0_rtx)
+    FAIL;
+
   /* Undetermined size, use the library routine.  */
   if (GET_CODE (operands[1]) != CONST_INT)
     FAIL;
 
   size = INTVAL (operands[1]);
-  align = INTVAL (operands[2]);
+  align = INTVAL (operands[3]);
   align = align > 4 ? 4 : align;
 
   /* If size/alignment is large, then use the library routines.  */
   operands[0]
     = replace_equiv_address (operands[0],
                             copy_to_mode_reg (SImode, XEXP (operands[0], 0)));
-  operands[3] = gen_reg_rtx (SImode);
   operands[4] = gen_reg_rtx (SImode);
+  operands[5] = gen_reg_rtx (SImode);
 }")
 
 (define_insn "clrmemsi_prereload"
   "* return output_block_clear (operands, !which_alternative);"
   [(set_attr "type" "multi,multi")])
 
-(define_expand "clrmemdi"
+(define_expand "setmemdi"
   [(parallel [(set (match_operand:BLK 0 "" "")
-                  (const_int 0))
-             (clobber (match_dup 3))
+                  (match_operand 2 "const_int_operand" ""))
              (clobber (match_dup 4))
+             (clobber (match_dup 5))
              (use (match_operand:DI 1 "arith_operand" ""))
-             (use (match_operand:DI 2 "const_int_operand" ""))])]
+             (use (match_operand:DI 3 "const_int_operand" ""))])]
   "TARGET_64BIT && optimize > 0"
   "
 {
   int size, align;
 
+  /* If value to set is not zero, use the library routine.  */
+  if (operands[2] != const0_rtx)
+    FAIL;
+
   /* Undetermined size, use the library routine.  */
   if (GET_CODE (operands[1]) != CONST_INT)
     FAIL;
 
   size = INTVAL (operands[1]);
-  align = INTVAL (operands[2]);
+  align = INTVAL (operands[3]);
   align = align > 8 ? 8 : align;
 
   /* If size/alignment is large, then use the library routines.  */
   operands[0]
     = replace_equiv_address (operands[0],
                             copy_to_mode_reg (DImode, XEXP (operands[0], 0)));
-  operands[3] = gen_reg_rtx (DImode);
   operands[4] = gen_reg_rtx (DImode);
+  operands[5] = gen_reg_rtx (DImode);
 }")
 
 (define_insn "clrmemdi_prereload"
     DONE;
 }")
 
-;; Reloading an SImode or DImode value requires a scratch register if
-;; going in to or out of float point registers.
-
+;; Handle DFmode input reloads requiring a general register as a
+;; scratch register.
 (define_expand "reload_indf"
   [(set (match_operand:DF 0 "register_operand" "=Z")
        (match_operand:DF 1 "non_hard_reg_operand" ""))
   DONE;
 }")
 
+;; Handle DFmode output reloads requiring a general register as a
+;; scratch register.
 (define_expand "reload_outdf" 
  [(set (match_operand:DF 0 "non_hard_reg_operand" "")
        (match_operand:DF 1  "register_operand" "Z"))
 
 (define_insn ""
   [(set (match_operand:DF 0 "move_dest_operand"
-                         "=f,*r,Q,?o,?Q,f,*r,*r")
+                         "=f,*r,Q,?o,?Q,f,*r,*r,!r,!f")
        (match_operand:DF 1 "reg_or_0_or_nonsymb_mem_operand"
-                         "fG,*rG,f,*r,*r,RQ,o,RQ"))]
+                         "fG,*rG,f,*r,*r,RQ,o,RQ,!f,!r"))]
   "(register_operand (operands[0], DFmode)
     || reg_or_0_operand (operands[1], DFmode))
    && !(GET_CODE (operands[1]) == CONST_DOUBLE
    && !TARGET_SOFT_FLOAT"
   "*
 {
-  if (FP_REG_P (operands[0]) || FP_REG_P (operands[1])
-      || operands[1] == CONST0_RTX (DFmode))
+  if ((FP_REG_P (operands[0]) || FP_REG_P (operands[1])
+       || operands[1] == CONST0_RTX (DFmode))
+      && !(REG_P (operands[0]) && REG_P (operands[1])
+          && FP_REG_P (operands[0]) ^ FP_REG_P (operands[1])))
     return output_fp_move_double (operands);
   return output_move_double (operands);
 }"
-  [(set_attr "type" "fpalu,move,fpstore,store,store,fpload,load,load")
-   (set_attr "length" "4,8,4,8,16,4,8,16")])
+  [(set_attr "type" "fpalu,move,fpstore,store,store,fpload,load,load,move,move")
+   (set_attr "length" "4,8,4,8,16,4,8,16,12,12")])
 
 (define_insn ""
   [(set (match_operand:DF 0 "indexed_memory_operand" "=R")
         (match_operand:DF 3 "register_operand" ""))]
   "!TARGET_SOFT_FLOAT
    && !TARGET_DISABLE_INDEXING
-   && REG_OK_FOR_BASE_P (operands[1])
-   && (TARGET_NO_SPACE_REGS
-       || (!REG_POINTER (operands[1]) && REG_POINTER (operands[2])))
+   && TARGET_NO_SPACE_REGS
+   && REG_OK_FOR_INDEX_P (operands[1])
+   && REG_OK_FOR_BASE_P (operands[2])
    && FP_REGNO_P (REGNO (operands[3]))"
   [(set (mem:DF (plus:SI (match_dup 1) (match_dup 2)))
        (match_dup 3))
         (match_operand:DF 3 "register_operand" ""))]
   "!TARGET_SOFT_FLOAT
    && !TARGET_DISABLE_INDEXING
-   && REG_OK_FOR_BASE_P (operands[2])
-   && (TARGET_NO_SPACE_REGS
-       || (REG_POINTER (operands[1]) && !REG_POINTER (operands[2])))
+   && TARGET_NO_SPACE_REGS
+   && REG_OK_FOR_BASE_P (operands[1])
+   && REG_OK_FOR_INDEX_P (operands[2])
    && FP_REGNO_P (REGNO (operands[3]))"
   [(set (mem:DF (plus:SI (match_dup 2) (match_dup 1)))
        (match_dup 3))
   "!TARGET_SOFT_FLOAT
    && !TARGET_DISABLE_INDEXING
    && TARGET_64BIT
-   && REG_OK_FOR_BASE_P (operands[1])
-   && (TARGET_NO_SPACE_REGS
-       || (!REG_POINTER (operands[1]) && REG_POINTER (operands[2])))
+   && TARGET_NO_SPACE_REGS
+   && REG_OK_FOR_INDEX_P (operands[1])
+   && REG_OK_FOR_BASE_P (operands[2])
    && FP_REGNO_P (REGNO (operands[3]))"
   [(set (mem:DF (plus:DI (match_dup 1) (match_dup 2)))
        (match_dup 3))
   "!TARGET_SOFT_FLOAT
    && !TARGET_DISABLE_INDEXING
    && TARGET_64BIT
-   && REG_OK_FOR_BASE_P (operands[2])
-   && (TARGET_NO_SPACE_REGS
-       || (REG_POINTER (operands[1]) && !REG_POINTER (operands[2])))
+   && TARGET_NO_SPACE_REGS
+   && REG_OK_FOR_BASE_P (operands[1])
+   && REG_OK_FOR_INDEX_P (operands[2])
    && FP_REGNO_P (REGNO (operands[3]))"
   [(set (mem:DF (plus:DI (match_dup 2) (match_dup 1)))
        (match_dup 3))
 
 (define_insn ""
   [(set (match_operand:DF 0 "move_dest_operand"
-                         "=r,?o,?Q,r,r")
+                         "=r,?o,?Q,r,r,!r,!f")
        (match_operand:DF 1 "reg_or_0_or_nonsymb_mem_operand"
-                         "rG,r,r,o,RQ"))]
+                         "rG,r,r,o,RQ,!f,!r"))]
   "(register_operand (operands[0], DFmode)
     || reg_or_0_operand (operands[1], DFmode))
    && !TARGET_64BIT
 {
   return output_move_double (operands);
 }"
-  [(set_attr "type" "move,store,store,load,load")
-   (set_attr "length" "8,8,16,8,16")])
+  [(set_attr "type" "move,store,store,load,load,move,move")
+   (set_attr "length" "8,8,16,8,16,12,12")])
 
 (define_insn ""
   [(set (match_operand:DF 0 "move_dest_operand"
     DONE;
 }")
 
+;; Handle DImode input reloads requiring %r1 as a scratch register.
+(define_expand "reload_indi_r1"
+  [(set (match_operand:DI 0 "register_operand" "=Z")
+       (match_operand:DI 1 "non_hard_reg_operand" ""))
+   (clobber (match_operand:SI 2 "register_operand" "=&a"))]
+  ""
+  "
+{
+  if (emit_move_sequence (operands, DImode, operands[2]))
+    DONE;
+
+  /* We don't want the clobber emitted, so handle this ourselves.  */
+  emit_insn (gen_rtx_SET (VOIDmode, operands[0], operands[1]));
+  DONE;
+}")
+
+;; Handle DImode input reloads requiring a general register as a
+;; scratch register.
 (define_expand "reload_indi"
   [(set (match_operand:DI 0 "register_operand" "=Z")
        (match_operand:DI 1 "non_hard_reg_operand" ""))
   DONE;
 }")
 
+;; Handle DImode output reloads requiring a general register as a
+;; scratch register.
 (define_expand "reload_outdi"
   [(set (match_operand:DI 0 "non_hard_reg_operand" "")
        (match_operand:DI 1 "register_operand" "Z"))
   rtx op0 = operands[0];
   rtx op1 = operands[1];
 
-  if (GET_CODE (op1) == CONST_INT)
+  switch (GET_CODE (op1))
     {
+    case CONST_INT:
+#if HOST_BITS_PER_WIDE_INT <= 32
       operands[0] = operand_subword (op0, 1, 0, DImode);
       output_asm_insn (\"ldil L'%1,%0\", operands);
 
        output_asm_insn (\"ldi -1,%0\", operands);
       else
        output_asm_insn (\"ldi 0,%0\", operands);
-      return \"\";
-    }
-  else if (GET_CODE (op1) == CONST_DOUBLE)
-    {
+#else
+      operands[0] = operand_subword (op0, 1, 0, DImode);
+      operands[1] = GEN_INT (INTVAL (op1) & 0xffffffff);
+      output_asm_insn (\"ldil L'%1,%0\", operands);
+
+      operands[0] = operand_subword (op0, 0, 0, DImode);
+      operands[1] = GEN_INT (INTVAL (op1) >> 32);
+      output_asm_insn (singlemove_string (operands), operands);
+#endif
+      break;
+
+    case CONST_DOUBLE:
       operands[0] = operand_subword (op0, 1, 0, DImode);
       operands[1] = GEN_INT (CONST_DOUBLE_LOW (op1));
       output_asm_insn (\"ldil L'%1,%0\", operands);
       operands[0] = operand_subword (op0, 0, 0, DImode);
       operands[1] = GEN_INT (CONST_DOUBLE_HIGH (op1));
       output_asm_insn (singlemove_string (operands), operands);
-      return \"\";
+      break;
+
+    default:
+      gcc_unreachable ();
     }
-  else
-    abort ();
+  return \"\";
 }"
   [(set_attr "type" "move")
-   (set_attr "length" "8")])
+   (set_attr "length" "12")])
 
 (define_insn ""
   [(set (match_operand:DI 0 "move_dest_operand"
-                         "=r,o,Q,r,r,r,*f,*f,T")
+                         "=r,o,Q,r,r,r,*f,*f,T,!r,!f")
        (match_operand:DI 1 "general_operand"
-                         "rM,r,r,o*R,Q,i,*fM,RT,*f"))]
+                         "rM,r,r,o*R,Q,i,*fM,RT,*f,!f,!r"))]
   "(register_operand (operands[0], DImode)
     || reg_or_0_operand (operands[1], DImode))
    && !TARGET_64BIT
    && !TARGET_SOFT_FLOAT"
   "*
 {
-  if (FP_REG_P (operands[0]) || FP_REG_P (operands[1])
-      || (operands[1] == CONST0_RTX (DImode)))
+  if ((FP_REG_P (operands[0]) || FP_REG_P (operands[1])
+       || operands[1] == CONST0_RTX (DFmode))
+      && !(REG_P (operands[0]) && REG_P (operands[1])
+          && FP_REG_P (operands[0]) ^ FP_REG_P (operands[1])))
     return output_fp_move_double (operands);
   return output_move_double (operands);
 }"
-  [(set_attr "type" "move,store,store,load,load,multi,fpalu,fpload,fpstore")
-   (set_attr "length" "8,8,16,8,16,16,4,4,4")])
+  [(set_attr "type"
+    "move,store,store,load,load,multi,fpalu,fpload,fpstore,move,move")
+   (set_attr "length" "8,8,16,8,16,16,4,4,4,12,12")])
 
 (define_insn ""
   [(set (match_operand:DI 0 "move_dest_operand"
   "!TARGET_SOFT_FLOAT
    && !TARGET_DISABLE_INDEXING
    && TARGET_64BIT
-   && REG_OK_FOR_BASE_P (operands[1])
-   && (TARGET_NO_SPACE_REGS
-       || (!REG_POINTER (operands[1]) && REG_POINTER (operands[2])))
+   && TARGET_NO_SPACE_REGS
+   && REG_OK_FOR_INDEX_P (operands[1])
+   && REG_OK_FOR_BASE_P (operands[2])
    && FP_REGNO_P (REGNO (operands[3]))"
   [(set (mem:DI (plus:DI (match_dup 1) (match_dup 2)))
        (match_dup 3))
   "!TARGET_SOFT_FLOAT
    && !TARGET_DISABLE_INDEXING
    && TARGET_64BIT
-   && REG_OK_FOR_BASE_P (operands[2])
-   && (TARGET_NO_SPACE_REGS
-       || (REG_POINTER (operands[1]) && !REG_POINTER (operands[2])))
+   && TARGET_NO_SPACE_REGS
+   && REG_OK_FOR_BASE_P (operands[1])
+   && REG_OK_FOR_INDEX_P (operands[2])
    && FP_REGNO_P (REGNO (operands[3]))"
   [(set (mem:DI (plus:DI (match_dup 2) (match_dup 1)))
        (match_dup 3))
      handle it correctly.  */
   if (GET_CODE (operands[2]) == CONST_DOUBLE)
     operands[2] = GEN_INT (CONST_DOUBLE_LOW (operands[2]));
+  else if (HOST_BITS_PER_WIDE_INT > 32
+          && GET_CODE (operands[2]) == CONST_INT)
+    operands[2] = GEN_INT (INTVAL (operands[2]) & 0xffffffff);
   if (which_alternative == 1)
     output_asm_insn (\"copy %1,%0\", operands);
   return \"ldo R'%G2(%R1),%R0\";
     DONE;
 }")
 
-;; Reloading an SImode or DImode value requires a scratch register if
-;; going in to or out of float point registers.
-
+;; Handle SFmode input reloads requiring a general register as a
+;; scratch register.
 (define_expand "reload_insf"
   [(set (match_operand:SF 0 "register_operand" "=Z")
        (match_operand:SF 1 "non_hard_reg_operand" ""))
   DONE;
 }")
 
+;; Handle SFmode output reloads requiring a general register as a
+;; scratch register.
 (define_expand "reload_outsf"
   [(set (match_operand:SF 0 "non_hard_reg_operand" "")
        (match_operand:SF 1  "register_operand" "Z"))
 
 (define_insn ""
   [(set (match_operand:SF 0 "move_dest_operand"
+                         "=f,!*r,f,*r,Q,Q,!r,!f")
+       (match_operand:SF 1 "reg_or_0_or_nonsymb_mem_operand"
+                         "fG,!*rG,RQ,RQ,f,*rG,!f,!r"))]
+  "(register_operand (operands[0], SFmode)
+    || reg_or_0_operand (operands[1], SFmode))
+   && !TARGET_SOFT_FLOAT
+   && !TARGET_64BIT"
+  "@
+   fcpy,sgl %f1,%0
+   copy %r1,%0
+   fldw%F1 %1,%0
+   ldw%M1 %1,%0
+   fstw%F0 %1,%0
+   stw%M0 %r1,%0
+   {fstws|fstw} %1,-16(%%sp)\n\t{ldws|ldw} -16(%%sp),%0
+   {stws|stw} %1,-16(%%sp)\n\t{fldws|fldw} -16(%%sp),%0"
+  [(set_attr "type" "fpalu,move,fpload,load,fpstore,store,move,move")
+   (set_attr "pa_combine_type" "addmove")
+   (set_attr "length" "4,4,4,4,4,4,8,8")])
+
+(define_insn ""
+  [(set (match_operand:SF 0 "move_dest_operand"
                          "=f,!*r,f,*r,Q,Q")
        (match_operand:SF 1 "reg_or_0_or_nonsymb_mem_operand"
                          "fG,!*rG,RQ,RQ,f,*rG"))]
   "(register_operand (operands[0], SFmode)
     || reg_or_0_operand (operands[1], SFmode))
-   && !TARGET_SOFT_FLOAT"
+   && !TARGET_SOFT_FLOAT
+   && TARGET_64BIT"
   "@
    fcpy,sgl %f1,%0
    copy %r1,%0
         (match_operand:SF 3 "register_operand" ""))]
   "!TARGET_SOFT_FLOAT
    && !TARGET_DISABLE_INDEXING
-   && REG_OK_FOR_BASE_P (operands[1])
-   && (TARGET_NO_SPACE_REGS
-       || (!REG_POINTER (operands[1]) && REG_POINTER (operands[2])))
+   && TARGET_NO_SPACE_REGS
+   && REG_OK_FOR_INDEX_P (operands[1])
+   && REG_OK_FOR_BASE_P (operands[2])
    && FP_REGNO_P (REGNO (operands[3]))"
   [(set (mem:SF (plus:SI (match_dup 1) (match_dup 2)))
        (match_dup 3))
         (match_operand:SF 3 "register_operand" ""))]
   "!TARGET_SOFT_FLOAT
    && !TARGET_DISABLE_INDEXING
-   && REG_OK_FOR_BASE_P (operands[2])
-   && (TARGET_NO_SPACE_REGS
-       || (REG_POINTER (operands[1]) && !REG_POINTER (operands[2])))
+   && TARGET_NO_SPACE_REGS
+   && REG_OK_FOR_BASE_P (operands[1])
+   && REG_OK_FOR_INDEX_P (operands[2])
    && FP_REGNO_P (REGNO (operands[3]))"
   [(set (mem:SF (plus:SI (match_dup 2) (match_dup 1)))
        (match_dup 3))
   "!TARGET_SOFT_FLOAT
    && !TARGET_DISABLE_INDEXING
    && TARGET_64BIT
-   && REG_OK_FOR_BASE_P (operands[1])
-   && (TARGET_NO_SPACE_REGS
-       || (!REG_POINTER (operands[1]) && REG_POINTER (operands[2])))
+   && TARGET_NO_SPACE_REGS
+   && REG_OK_FOR_INDEX_P (operands[1])
+   && REG_OK_FOR_BASE_P (operands[2])
    && FP_REGNO_P (REGNO (operands[3]))"
   [(set (mem:SF (plus:DI (match_dup 1) (match_dup 2)))
        (match_dup 3))
   "!TARGET_SOFT_FLOAT
    && !TARGET_DISABLE_INDEXING
    && TARGET_64BIT
-   && REG_OK_FOR_BASE_P (operands[2])
-   && (TARGET_NO_SPACE_REGS
-       || (REG_POINTER (operands[1]) && !REG_POINTER (operands[2])))
+   && TARGET_NO_SPACE_REGS
+   && REG_OK_FOR_BASE_P (operands[1])
+   && REG_OK_FOR_INDEX_P (operands[2])
    && FP_REGNO_P (REGNO (operands[3]))"
   [(set (mem:SF (plus:DI (match_dup 2) (match_dup 1)))
        (match_dup 3))
   [(set_attr "type" "binary")
    (set_attr "length" "4")])
 
+(define_expand "addvdi3"
+  [(parallel [(set (match_operand:DI 0 "register_operand" "")
+                  (plus:DI (match_operand:DI 1 "reg_or_0_operand" "")
+                           (match_operand:DI 2 "arith11_operand" "")))
+             (trap_if (ne (plus:TI (sign_extend:TI (match_dup 1))
+                                   (sign_extend:TI (match_dup 2)))
+                          (sign_extend:TI (plus:DI (match_dup 1)
+                                                   (match_dup 2))))
+                      (const_int 0))])]
+  ""
+  "")
+
+(define_insn ""
+  [(set (match_operand:DI 0 "register_operand" "=r,r")
+       (plus:DI (match_operand:DI 1 "reg_or_0_operand" "%rM,rM")
+                (match_operand:DI 2 "arith11_operand" "r,I")))
+   (trap_if (ne (plus:TI (sign_extend:TI (match_dup 1))
+                        (sign_extend:TI (match_dup 2)))
+               (sign_extend:TI (plus:DI (match_dup 1)
+                                        (match_dup 2))))
+           (const_int 0))]
+  "TARGET_64BIT"
+  "@
+  add,tsv,* %2,%1,%0
+  addi,tsv,* %2,%1,%0"
+  [(set_attr "type" "binary,binary")
+   (set_attr "length" "4,4")])
+
+(define_insn ""
+  [(set (match_operand:DI 0 "register_operand" "=r")
+       (plus:DI (match_operand:DI 1 "reg_or_0_operand" "%rM")
+                (match_operand:DI 2 "arith11_operand" "rI")))
+   (trap_if (ne (plus:TI (sign_extend:TI (match_dup 1))
+                        (sign_extend:TI (match_dup 2)))
+               (sign_extend:TI (plus:DI (match_dup 1)
+                                        (match_dup 2))))
+           (const_int 0))]
+  "!TARGET_64BIT"
+  "*
+{
+  if (GET_CODE (operands[2]) == CONST_INT)
+    {
+      if (INTVAL (operands[2]) >= 0)
+       return \"addi %2,%R1,%R0\;{addco|add,c,tsv} %1,%%r0,%0\";
+      else
+       return \"addi %2,%R1,%R0\;{subbo|sub,b,tsv} %1,%%r0,%0\";
+    }
+  else
+    return \"add %R2,%R1,%R0\;{addco|add,c,tsv} %2,%1,%0\";
+}"
+  [(set_attr "type" "binary")
+   (set_attr "length" "8")])
+
 ;; define_splits to optimize cases of adding a constant integer
 ;; to a register when the constant does not fit in 14 bits.  */
 (define_split
    (set_attr "pa_combine_type" "addmove")
    (set_attr "length" "4,4")])
 
+(define_insn "addvsi3"
+  [(set (match_operand:SI 0 "register_operand" "=r,r")
+       (plus:SI (match_operand:SI 1 "reg_or_0_operand" "%rM,rM")
+                (match_operand:SI 2 "arith11_operand" "r,I")))
+   (trap_if (ne (plus:DI (sign_extend:DI (match_dup 1))
+                        (sign_extend:DI (match_dup 2)))
+               (sign_extend:DI (plus:SI (match_dup 1)
+                                        (match_dup 2))))
+           (const_int 0))]
+  ""
+  "@
+  {addo|add,tsv} %2,%1,%0
+  {addio|addi,tsv} %2,%1,%0"
+  [(set_attr "type" "binary,binary")
+   (set_attr "length" "4,4")])
+
 (define_expand "subdi3"
   [(set (match_operand:DI 0 "register_operand" "")
-       (minus:DI (match_operand:DI 1 "register_operand" "")
-                 (match_operand:DI 2 "register_operand" "")))]
+       (minus:DI (match_operand:DI 1 "arith11_operand" "")
+                 (match_operand:DI 2 "reg_or_0_operand" "")))]
   ""
   "")
 
 (define_insn ""
-  [(set (match_operand:DI 0 "register_operand" "=r")
-       (minus:DI (match_operand:DI 1 "register_operand" "r")
-                 (match_operand:DI 2 "register_operand" "r")))]
-  "!TARGET_64BIT"
-  "sub %R1,%R2,%R0\;{subb|sub,b} %1,%2,%0"
-  [(set_attr "type" "binary")
-  (set_attr "length" "8")])
-
-(define_insn ""
   [(set (match_operand:DI 0 "register_operand" "=r,r,!q")
        (minus:DI (match_operand:DI 1 "arith11_operand" "r,I,!U")
-                 (match_operand:DI 2 "register_operand" "r,r,!r")))]
+                 (match_operand:DI 2 "reg_or_0_operand" "rM,rM,!rM")))]
   "TARGET_64BIT"
   "@
    sub %1,%2,%0
   [(set_attr "type" "binary,binary,move")
   (set_attr "length" "4,4,4")])
 
+(define_insn ""
+  [(set (match_operand:DI 0 "register_operand" "=r,&r")
+       (minus:DI (match_operand:DI 1 "arith11_operand" "r,I")
+                 (match_operand:DI 2 "reg_or_0_operand" "rM,rM")))]
+  "!TARGET_64BIT"
+  "*
+{
+  if (GET_CODE (operands[1]) == CONST_INT)
+    {
+      if (INTVAL (operands[1]) >= 0)
+       return \"subi %1,%R2,%R0\;{subb|sub,b} %%r0,%2,%0\";
+      else
+       return \"ldi -1,%0\;subi %1,%R2,%R0\;{subb|sub,b} %0,%2,%0\";
+    }
+  else
+    return \"sub %R1,%R2,%R0\;{subb|sub,b} %1,%2,%0\";
+}"
+  [(set_attr "type" "binary")
+   (set (attr "length")
+       (if_then_else (eq_attr "alternative" "0")
+         (const_int 8)
+         (if_then_else (ge (symbol_ref "INTVAL (operands[1])")
+                           (const_int 0))
+           (const_int 8)
+           (const_int 12))))])
+
+(define_expand "subvdi3"
+  [(parallel [(set (match_operand:DI 0 "register_operand" "")
+                  (minus:DI (match_operand:DI 1 "arith11_operand" "")
+                            (match_operand:DI 2 "reg_or_0_operand" "")))
+             (trap_if (ne (minus:TI (sign_extend:TI (match_dup 1))
+                                    (sign_extend:TI (match_dup 2)))
+                          (sign_extend:TI (minus:DI (match_dup 1)
+                                                    (match_dup 2))))
+                      (const_int 0))])]
+  ""
+  "")
+
+(define_insn ""
+  [(set (match_operand:DI 0 "register_operand" "=r,r")
+       (minus:DI (match_operand:DI 1 "arith11_operand" "r,I")
+                 (match_operand:DI 2 "reg_or_0_operand" "rM,rM")))
+   (trap_if (ne (minus:TI (sign_extend:TI (match_dup 1))
+                         (sign_extend:TI (match_dup 2)))
+               (sign_extend:TI (minus:DI (match_dup 1)
+                                         (match_dup 2))))
+           (const_int 0))]
+  "TARGET_64BIT"
+  "@
+  {subo|sub,tsv} %1,%2,%0
+  {subio|subi,tsv} %1,%2,%0"
+  [(set_attr "type" "binary,binary")
+   (set_attr "length" "4,4")])
+
+(define_insn ""
+  [(set (match_operand:DI 0 "register_operand" "=r,&r")
+       (minus:DI (match_operand:DI 1 "arith11_operand" "r,I")
+                 (match_operand:DI 2 "reg_or_0_operand" "rM,rM")))
+   (trap_if (ne (minus:TI (sign_extend:TI (match_dup 1))
+                         (sign_extend:TI (match_dup 2)))
+               (sign_extend:TI (minus:DI (match_dup 1)
+                                         (match_dup 2))))
+           (const_int 0))]
+  "!TARGET_64BIT"
+  "*
+{
+  if (GET_CODE (operands[1]) == CONST_INT)
+    {
+      if (INTVAL (operands[1]) >= 0)
+       return \"subi %1,%R2,%R0\;{subbo|sub,b,tsv} %%r0,%2,%0\";
+      else
+       return \"ldi -1,%0\;subi %1,%R2,%R0\;{subbo|sub,b,tsv} %0,%2,%0\";
+    }
+  else
+    return \"sub %R1,%R2,%R0\;{subbo|sub,b,tsv} %1,%2,%0\";
+}"
+  [(set_attr "type" "binary,binary")
+   (set (attr "length")
+       (if_then_else (eq_attr "alternative" "0")
+         (const_int 8)
+         (if_then_else (ge (symbol_ref "INTVAL (operands[1])")
+                           (const_int 0))
+           (const_int 8)
+           (const_int 12))))])
+
 (define_expand "subsi3"
   [(set (match_operand:SI 0 "register_operand" "")
        (minus:SI (match_operand:SI 1 "arith11_operand" "")
   [(set_attr "type" "binary,binary,move")
    (set_attr "length" "4,4,4")])
 
+(define_insn "subvsi3"
+  [(set (match_operand:SI 0 "register_operand" "=r,r")
+       (minus:SI (match_operand:SI 1 "arith11_operand" "rM,I")
+                 (match_operand:SI 2 "reg_or_0_operand" "rM,rM")))
+   (trap_if (ne (minus:DI (sign_extend:DI (match_dup 1))
+                         (sign_extend:DI (match_dup 2)))
+               (sign_extend:DI (minus:SI (match_dup 1)
+                                         (match_dup 2))))
+           (const_int 0))]
+  ""
+  "@
+  {subo|sub,tsv} %1,%2,%0
+  {subio|subi,tsv} %1,%2,%0"
+  [(set_attr "type" "binary,binary")
+   (set_attr "length" "4,4")])
+
 ;; Clobbering a "register_operand" instead of a match_scratch
 ;; in operand3 of millicode calls avoids spilling %r1 and
 ;; produces better code.
              (clobber (reg:SI 26))
              (clobber (reg:SI 25))
              (clobber (match_dup 4))])
-   (set (match_operand:SI 0 "general_operand" "") (reg:SI 29))]
+   (set (match_operand:SI 0 "move_dest_operand" "") (reg:SI 29))]
   ""
   "
 {
              (clobber (reg:SI 26))
              (clobber (reg:SI 25))
              (clobber (match_dup 5))])
-   (set (match_operand:SI 0 "general_operand" "") (reg:SI 29))]
+   (set (match_operand:SI 0 "move_dest_operand" "") (reg:SI 29))]
   ""
   "
 {
              (clobber (reg:SI 26))
              (clobber (reg:SI 25))
              (clobber (match_dup 5))])
-   (set (match_operand:SI 0 "general_operand" "") (reg:SI 29))]
+   (set (match_operand:SI 0 "move_dest_operand" "") (reg:SI 29))]
   ""
   "
 {
              (clobber (reg:SI 26))
              (clobber (reg:SI 25))
              (clobber (match_dup 5))])
-   (set (match_operand:SI 0 "general_operand" "") (reg:SI 29))]
+   (set (match_operand:SI 0 "move_dest_operand" "") (reg:SI 29))]
   ""
   "
 {
              (clobber (reg:SI 26))
              (clobber (reg:SI 25))
              (clobber (match_dup 5))])
-   (set (match_operand:SI 0 "general_operand" "") (reg:SI 29))]
+   (set (match_operand:SI 0 "move_dest_operand" "") (reg:SI 29))]
   ""
   "
 {
   [(set_attr "type" "unary")
    (set_attr "length" "4")])
 
+(define_expand "negvdi2"
+  [(parallel [(set (match_operand:DI 0 "register_operand" "")
+                  (neg:DI (match_operand:DI 1 "register_operand" "")))
+             (trap_if (ne (neg:TI (sign_extend:TI (match_dup 1)))
+                                  (sign_extend:TI (neg:DI (match_dup 1))))
+                      (const_int 0))])]
+  ""
+  "")
+
+(define_insn ""
+  [(set (match_operand:DI 0 "register_operand" "=r")
+       (neg:DI (match_operand:DI 1 "register_operand" "r")))
+   (trap_if (ne (neg:TI (sign_extend:TI (match_dup 1)))
+               (sign_extend:TI (neg:DI (match_dup 1))))
+           (const_int 0))]
+  "!TARGET_64BIT"
+  "sub %%r0,%R1,%R0\;{subbo|sub,b,tsv} %%r0,%1,%0"
+  [(set_attr "type" "unary")
+   (set_attr "length" "8")])
+
+(define_insn ""
+  [(set (match_operand:DI 0 "register_operand" "=r")
+       (neg:DI (match_operand:DI 1 "register_operand" "r")))
+   (trap_if (ne (neg:TI (sign_extend:TI (match_dup 1)))
+               (sign_extend:TI (neg:DI (match_dup 1))))
+           (const_int 0))]
+  "TARGET_64BIT"
+  "sub,tsv %%r0,%1,%0"
+  [(set_attr "type" "unary")
+   (set_attr "length" "4")])
+
 (define_insn "negsi2"
   [(set (match_operand:SI 0 "register_operand" "=r")
        (neg:SI (match_operand:SI 1 "register_operand" "r")))]
   [(set_attr "type" "unary")
    (set_attr "length" "4")])
 
+(define_insn "negvsi2"
+  [(set (match_operand:SI 0 "register_operand" "=r")
+        (neg:SI (match_operand:SI 1 "register_operand" "r")))
+   (trap_if (ne (neg:DI (sign_extend:DI (match_dup 1)))
+               (sign_extend:DI (neg:SI (match_dup 1))))
+           (const_int 0))]
+   ""
+   "{subo|sub,tsv} %%r0,%1,%0"
+  [(set_attr "type" "unary")
+   (set_attr "length" "4")])
+
 (define_expand "one_cmpldi2"
   [(set (match_operand:DI 0 "register_operand" "")
        (not:DI (match_operand:DI 1 "register_operand" "")))]
   "*
 {
   /* An unconditional branch which can reach its target.  */
-  if (get_attr_length (insn) != 24
-      && get_attr_length (insn) != 16)
+  if (get_attr_length (insn) < 16)
     return \"b%* %l0\";
 
-  return output_lbranch (operands[0], insn);
+  return output_lbranch (operands[0], insn, 1);
 }"
   [(set_attr "type" "uncond_branch")
    (set_attr "pa_combine_type" "uncond_branch")
     (cond [(eq (symbol_ref "jump_in_call_delay (insn)") (const_int 1))
           (if_then_else (lt (abs (minus (match_dup 0)
                                         (plus (pc) (const_int 8))))
-                            (const_int 8184))
-                        (const_int 4)
-                        (const_int 8))
-          (ge (abs (minus (match_dup 0) (plus (pc) (const_int 8))))
-              (const_int 262100))
-          (if_then_else (eq (symbol_ref "flag_pic") (const_int 0))
-                        (const_int 16)
-                        (const_int 24))]
-         (const_int 4)))])
+                            (const_int MAX_12BIT_OFFSET))
+          (const_int 4)
+          (const_int 8))
+          (lt (abs (minus (match_dup 0) (plus (pc) (const_int 8))))
+              (const_int MAX_17BIT_OFFSET))
+          (const_int 4)
+          (ne (symbol_ref "TARGET_PORTABLE_RUNTIME") (const_int 0))
+          (const_int 20)
+          (eq (symbol_ref "flag_pic") (const_int 0))
+          (const_int 16)]
+         (const_int 24)))])
 
 ;;; Hope this is only within a function...
 (define_insn "indirect_jump"
@@ -7070,8 +7670,7 @@ add,l %2,%3,%3\;bv,n %%r0(%3)"
             the only method that we have for doing DImode multiplication
             is with a libcall.  This could be trouble if we haven't
             allocated enough space for the outgoing arguments.  */
-         if (INTVAL (nb) > current_function_outgoing_args_size)
-           abort ();
+         gcc_assert (INTVAL (nb) <= current_function_outgoing_args_size);
 
          emit_move_insn (arg_pointer_rtx,
                          gen_rtx_PLUS (word_mode, stack_pointer_rtx,
@@ -7570,8 +8169,7 @@ add,l %2,%3,%3\;bv,n %%r0(%3)"
             the only method that we have for doing DImode multiplication
             is with a libcall.  This could be trouble if we haven't
             allocated enough space for the outgoing arguments.  */
-         if (INTVAL (nb) > current_function_outgoing_args_size)
-           abort ();
+         gcc_assert (INTVAL (nb) <= current_function_outgoing_args_size);
 
          emit_move_insn (arg_pointer_rtx,
                          gen_rtx_PLUS (word_mode, stack_pointer_rtx,
@@ -8089,8 +8687,7 @@ add,l %2,%3,%3\;bv,n %%r0(%3)"
             the only method that we have for doing DImode multiplication
             is with a libcall.  This could be trouble if we haven't
             allocated enough space for the outgoing arguments.  */
-         if (INTVAL (nb) > current_function_outgoing_args_size)
-           abort ();
+         gcc_assert (INTVAL (nb) <= current_function_outgoing_args_size);
 
          emit_move_insn (arg_pointer_rtx,
                          gen_rtx_PLUS (word_mode, stack_pointer_rtx,
@@ -8171,8 +8768,7 @@ add,l %2,%3,%3\;bv,n %%r0(%3)"
             the only method that we have for doing DImode multiplication
             is with a libcall.  This could be trouble if we haven't
             allocated enough space for the outgoing arguments.  */
-         if (INTVAL (nb) > current_function_outgoing_args_size)
-           abort ();
+         gcc_assert (INTVAL (nb) <= current_function_outgoing_args_size);
 
          emit_move_insn (arg_pointer_rtx,
                          gen_rtx_PLUS (word_mode, stack_pointer_rtx,
@@ -8635,39 +9231,71 @@ add,l %2,%3,%3\;bv,n %%r0(%3)"
       (if_then_else (eq_attr "alternative" "0")
 ;; Loop counter in register case
 ;; Short branch has length of 4
-;; Long branch has length of 8
-       (if_then_else (lt (abs (minus (match_dup 3) (plus (pc) (const_int 8))))
-                     (const_int 8184))
-           (const_int 4)
-          (const_int 8))
+;; Long branch has length of 8, 20, 24 or 28
+       (cond [(lt (abs (minus (match_dup 3) (plus (pc) (const_int 8))))
+              (const_int MAX_12BIT_OFFSET))
+          (const_int 4)
+          (lt (abs (minus (match_dup 3) (plus (pc) (const_int 8))))
+              (const_int MAX_17BIT_OFFSET))
+          (const_int 8)
+          (ne (symbol_ref "TARGET_PORTABLE_RUNTIME") (const_int 0))
+          (const_int 24)
+          (eq (symbol_ref "flag_pic") (const_int 0))
+          (const_int 20)]
+         (const_int 28))
 
 ;; Loop counter in FP reg case.
 ;; Extra goo to deal with additional reload insns.
        (if_then_else (eq_attr "alternative" "1")
          (if_then_else (lt (match_dup 3) (pc))
-           (if_then_else
-             (lt (abs (minus (match_dup 3) (plus (pc) (const_int 24))))
-                 (const_int 8184))
-             (const_int 24)
-             (const_int 28))
-           (if_then_else
-             (lt (abs (minus (match_dup 3) (plus (pc) (const_int 8))))
-                 (const_int 8184))
-             (const_int 24)
-             (const_int 28)))
+            (cond [(lt (abs (minus (match_dup 3) (plus (pc) (const_int 24))))
+                     (const_int MAX_12BIT_OFFSET))
+                   (const_int 24)
+                   (lt (abs (minus (match_dup 3) (plus (pc) (const_int 24))))
+                     (const_int MAX_17BIT_OFFSET))
+                   (const_int 28)
+                   (ne (symbol_ref "TARGET_PORTABLE_RUNTIME") (const_int 0))
+                   (const_int 44)
+                   (eq (symbol_ref "flag_pic") (const_int 0))
+                   (const_int 40)]
+                 (const_int 48))
+            (cond [(lt (abs (minus (match_dup 3) (plus (pc) (const_int 8))))
+                     (const_int MAX_12BIT_OFFSET))
+                   (const_int 24)
+                   (lt (abs (minus (match_dup 3) (plus (pc) (const_int 8))))
+                     (const_int MAX_17BIT_OFFSET))
+                   (const_int 28)
+                   (ne (symbol_ref "TARGET_PORTABLE_RUNTIME") (const_int 0))
+                   (const_int 44)
+                   (eq (symbol_ref "flag_pic") (const_int 0))
+                   (const_int 40)]
+                 (const_int 48)))
+
 ;; Loop counter in memory case.
 ;; Extra goo to deal with additional reload insns.
        (if_then_else (lt (match_dup 3) (pc))
-         (if_then_else
-           (lt (abs (minus (match_dup 3) (plus (pc) (const_int 12))))
-               (const_int 8184))
-           (const_int 12)
-           (const_int 16))
-         (if_then_else
-           (lt (abs (minus (match_dup 3) (plus (pc) (const_int 8))))
-               (const_int 8184))
-           (const_int 12)
-           (const_int 16))))))])
+            (cond [(lt (abs (minus (match_dup 3) (plus (pc) (const_int 12))))
+                     (const_int MAX_12BIT_OFFSET))
+                   (const_int 12)
+                   (lt (abs (minus (match_dup 3) (plus (pc) (const_int 12))))
+                     (const_int MAX_17BIT_OFFSET))
+                   (const_int 16)
+                   (ne (symbol_ref "TARGET_PORTABLE_RUNTIME") (const_int 0))
+                   (const_int 32)
+                   (eq (symbol_ref "flag_pic") (const_int 0))
+                   (const_int 28)]
+                 (const_int 36))
+            (cond [(lt (abs (minus (match_dup 3) (plus (pc) (const_int 8))))
+                     (const_int MAX_12BIT_OFFSET))
+                   (const_int 12)
+                   (lt (abs (minus (match_dup 3) (plus (pc) (const_int 8))))
+                     (const_int MAX_17BIT_OFFSET))
+                   (const_int 16)
+                   (ne (symbol_ref "TARGET_PORTABLE_RUNTIME") (const_int 0))
+                   (const_int 32)
+                   (eq (symbol_ref "flag_pic") (const_int 0))
+                   (const_int 28)]
+                 (const_int 36))))))])
 
 (define_insn ""
   [(set (pc)
@@ -8686,33 +9314,59 @@ add,l %2,%3,%3\;bv,n %%r0(%3)"
       (if_then_else (eq_attr "alternative" "0")
 ;; Loop counter in register case
 ;; Short branch has length of 4
-;; Long branch has length of 8
-       (if_then_else (lt (abs (minus (match_dup 3) (plus (pc) (const_int 8))))
-                     (const_int 8184))
-           (const_int 4)
-          (const_int 8))
+;; Long branch has length of 8, 20, 24 or 28
+        (cond [(lt (abs (minus (match_dup 3) (plus (pc) (const_int 8))))
+              (const_int MAX_12BIT_OFFSET))
+          (const_int 4)
+          (lt (abs (minus (match_dup 3) (plus (pc) (const_int 8))))
+              (const_int MAX_17BIT_OFFSET))
+          (const_int 8)
+          (ne (symbol_ref "TARGET_PORTABLE_RUNTIME") (const_int 0))
+          (const_int 24)
+          (eq (symbol_ref "flag_pic") (const_int 0))
+          (const_int 20)]
+         (const_int 28))
 
 ;; Loop counter in FP reg case.
 ;; Extra goo to deal with additional reload insns.
        (if_then_else (eq_attr "alternative" "1")
          (if_then_else (lt (match_dup 3) (pc))
-           (if_then_else
-             (lt (abs (minus (match_dup 3) (plus (pc) (const_int 12))))
-                 (const_int 8184))
-             (const_int 12)
-             (const_int 16))
-           (if_then_else
-             (lt (abs (minus (match_dup 3) (plus (pc) (const_int 8))))
-                 (const_int 8184))
-             (const_int 12)
-             (const_int 16)))
+            (cond [(lt (abs (minus (match_dup 3) (plus (pc) (const_int 12))))
+                     (const_int MAX_12BIT_OFFSET))
+                   (const_int 12)
+                   (lt (abs (minus (match_dup 3) (plus (pc) (const_int 12))))
+                     (const_int MAX_17BIT_OFFSET))
+                   (const_int 16)
+                   (ne (symbol_ref "TARGET_PORTABLE_RUNTIME") (const_int 0))
+                   (const_int 32)
+                   (eq (symbol_ref "flag_pic") (const_int 0))
+                   (const_int 28)]
+                 (const_int 36))
+            (cond [(lt (abs (minus (match_dup 3) (plus (pc) (const_int 8))))
+                     (const_int MAX_12BIT_OFFSET))
+                   (const_int 12)
+                   (lt (abs (minus (match_dup 3) (plus (pc) (const_int 8))))
+                     (const_int MAX_17BIT_OFFSET))
+                   (const_int 16)
+                   (ne (symbol_ref "TARGET_PORTABLE_RUNTIME") (const_int 0))
+                   (const_int 32)
+                   (eq (symbol_ref "flag_pic") (const_int 0))
+                   (const_int 28)]
+                 (const_int 36)))
+
 ;; Loop counter in memory or sar case.
 ;; Extra goo to deal with additional reload insns.
-       (if_then_else
-         (lt (abs (minus (match_dup 3) (plus (pc) (const_int 8))))
-             (const_int 8184))
-         (const_int 8)
-         (const_int 12)))))])
+       (cond [(lt (abs (minus (match_dup 3) (plus (pc) (const_int 8))))
+                  (const_int MAX_12BIT_OFFSET))
+               (const_int 8)
+               (lt (abs (minus (match_dup 3) (plus (pc) (const_int 8))))
+                 (const_int MAX_17BIT_OFFSET))
+               (const_int 12)
+               (ne (symbol_ref "TARGET_PORTABLE_RUNTIME") (const_int 0))
+               (const_int 28)
+               (eq (symbol_ref "flag_pic") (const_int 0))
+               (const_int 24)]
+             (const_int 32)))))])
 
 ;; Handle negated branch.
 (define_insn ""
@@ -8733,32 +9387,58 @@ add,l %2,%3,%3\;bv,n %%r0(%3)"
 ;; Loop counter in register case
 ;; Short branch has length of 4
 ;; Long branch has length of 8
-       (if_then_else (lt (abs (minus (match_dup 3) (plus (pc) (const_int 8))))
-                     (const_int 8184))
-           (const_int 4)
-          (const_int 8))
+        (cond [(lt (abs (minus (match_dup 3) (plus (pc) (const_int 8))))
+              (const_int MAX_12BIT_OFFSET))
+          (const_int 4)
+          (lt (abs (minus (match_dup 3) (plus (pc) (const_int 8))))
+              (const_int MAX_17BIT_OFFSET))
+          (const_int 8)
+          (ne (symbol_ref "TARGET_PORTABLE_RUNTIME") (const_int 0))
+          (const_int 24)
+          (eq (symbol_ref "flag_pic") (const_int 0))
+          (const_int 20)]
+         (const_int 28))
 
 ;; Loop counter in FP reg case.
 ;; Extra goo to deal with additional reload insns.
        (if_then_else (eq_attr "alternative" "1")
          (if_then_else (lt (match_dup 3) (pc))
-           (if_then_else
-             (lt (abs (minus (match_dup 3) (plus (pc) (const_int 12))))
-                 (const_int 8184))
-             (const_int 12)
-             (const_int 16))
-           (if_then_else
-             (lt (abs (minus (match_dup 3) (plus (pc) (const_int 8))))
-                 (const_int 8184))
-             (const_int 12)
-             (const_int 16)))
+            (cond [(lt (abs (minus (match_dup 3) (plus (pc) (const_int 12))))
+                     (const_int MAX_12BIT_OFFSET))
+                   (const_int 12)
+                   (lt (abs (minus (match_dup 3) (plus (pc) (const_int 12))))
+                     (const_int MAX_17BIT_OFFSET))
+                   (const_int 16)
+                   (ne (symbol_ref "TARGET_PORTABLE_RUNTIME") (const_int 0))
+                   (const_int 32)
+                   (eq (symbol_ref "flag_pic") (const_int 0))
+                   (const_int 28)]
+                 (const_int 36))
+            (cond [(lt (abs (minus (match_dup 3) (plus (pc) (const_int 8))))
+                     (const_int MAX_12BIT_OFFSET))
+                   (const_int 12)
+                   (lt (abs (minus (match_dup 3) (plus (pc) (const_int 8))))
+                     (const_int MAX_17BIT_OFFSET))
+                   (const_int 16)
+                   (ne (symbol_ref "TARGET_PORTABLE_RUNTIME") (const_int 0))
+                   (const_int 32)
+                   (eq (symbol_ref "flag_pic") (const_int 0))
+                   (const_int 28)]
+                 (const_int 36)))
+
 ;; Loop counter in memory or SAR case.
 ;; Extra goo to deal with additional reload insns.
-       (if_then_else
-         (lt (abs (minus (match_dup 3) (plus (pc) (const_int 8))))
-             (const_int 8184))
-         (const_int 8)
-         (const_int 12)))))])
+       (cond [(lt (abs (minus (match_dup 3) (plus (pc) (const_int 8))))
+                  (const_int MAX_12BIT_OFFSET))
+               (const_int 8)
+               (lt (abs (minus (match_dup 3) (plus (pc) (const_int 8))))
+                 (const_int MAX_17BIT_OFFSET))
+               (const_int 12)
+               (ne (symbol_ref "TARGET_PORTABLE_RUNTIME") (const_int 0))
+               (const_int 28)
+               (eq (symbol_ref "flag_pic") (const_int 0))
+               (const_int 24)]
+             (const_int 32)))))])
 
 (define_insn ""
   [(set (pc) (label_ref (match_operand 3 "" "" )))
@@ -8768,14 +9448,21 @@ add,l %2,%3,%3\;bv,n %%r0(%3)"
   "(reload_completed && operands[0] == operands[1]) || operands[0] == operands[2]"
   "*
 {
-  return output_parallel_addb (operands, get_attr_length (insn));
+  return output_parallel_addb (operands, insn);
 }"
-  [(set_attr "type" "parallel_branch")
-   (set (attr "length")
-    (if_then_else (lt (abs (minus (match_dup 3) (plus (pc) (const_int 8))))
-                     (const_int 8184))
-           (const_int 4)
-          (const_int 8)))])
+[(set_attr "type" "parallel_branch")
+ (set (attr "length")
+    (cond [(lt (abs (minus (match_dup 3) (plus (pc) (const_int 8))))
+              (const_int MAX_12BIT_OFFSET))
+          (const_int 4)
+          (lt (abs (minus (match_dup 3) (plus (pc) (const_int 8))))
+              (const_int MAX_17BIT_OFFSET))
+          (const_int 8)
+          (ne (symbol_ref "TARGET_PORTABLE_RUNTIME") (const_int 0))
+          (const_int 24)
+          (eq (symbol_ref "flag_pic") (const_int 0))
+          (const_int 20)]
+         (const_int 28)))])
 
 (define_insn ""
   [(set (pc) (label_ref (match_operand 2 "" "" )))
@@ -8784,14 +9471,21 @@ add,l %2,%3,%3\;bv,n %%r0(%3)"
   "reload_completed"
   "*
 {
-  return output_parallel_movb (operands, get_attr_length (insn));
+  return output_parallel_movb (operands, insn);
 }"
-  [(set_attr "type" "parallel_branch")
-   (set (attr "length")
-    (if_then_else (lt (abs (minus (match_dup 2) (plus (pc) (const_int 8))))
-                     (const_int 8184))
-           (const_int 4)
-          (const_int 8)))])
+[(set_attr "type" "parallel_branch")
+ (set (attr "length")
+    (cond [(lt (abs (minus (match_dup 2) (plus (pc) (const_int 8))))
+              (const_int MAX_12BIT_OFFSET))
+          (const_int 4)
+          (lt (abs (minus (match_dup 2) (plus (pc) (const_int 8))))
+              (const_int MAX_17BIT_OFFSET))
+          (const_int 8)
+          (ne (symbol_ref "TARGET_PORTABLE_RUNTIME") (const_int 0))
+          (const_int 24)
+          (eq (symbol_ref "flag_pic") (const_int 0))
+          (const_int 20)]
+         (const_int 28)))])
 
 (define_insn ""
   [(set (pc) (label_ref (match_operand 2 "" "" )))
@@ -8800,14 +9494,21 @@ add,l %2,%3,%3\;bv,n %%r0(%3)"
   "reload_completed"
   "*
 {
-  return output_parallel_movb (operands, get_attr_length (insn));
+  return output_parallel_movb (operands, insn);
 }"
-  [(set_attr "type" "parallel_branch")
-   (set (attr "length")
-    (if_then_else (lt (abs (minus (match_dup 2) (plus (pc) (const_int 8))))
-                     (const_int 8184))
-           (const_int 4)
-          (const_int 8)))])
+[(set_attr "type" "parallel_branch")
+ (set (attr "length")
+    (cond [(lt (abs (minus (match_dup 2) (plus (pc) (const_int 8))))
+              (const_int MAX_12BIT_OFFSET))
+          (const_int 4)
+          (lt (abs (minus (match_dup 2) (plus (pc) (const_int 8))))
+              (const_int MAX_17BIT_OFFSET))
+          (const_int 8)
+          (ne (symbol_ref "TARGET_PORTABLE_RUNTIME") (const_int 0))
+          (const_int 24)
+          (eq (symbol_ref "flag_pic") (const_int 0))
+          (const_int 20)]
+         (const_int 28)))])
 
 (define_insn ""
   [(set (pc) (label_ref (match_operand 2 "" "" )))
@@ -8816,14 +9517,21 @@ add,l %2,%3,%3\;bv,n %%r0(%3)"
   "reload_completed"
   "*
 {
-  return output_parallel_movb (operands, get_attr_length (insn));
+  return output_parallel_movb (operands, insn);
 }"
-  [(set_attr "type" "parallel_branch")
-   (set (attr "length")
-    (if_then_else (lt (abs (minus (match_dup 2) (plus (pc) (const_int 8))))
-                     (const_int 8184))
-           (const_int 4)
-          (const_int 8)))])
+[(set_attr "type" "parallel_branch")
+ (set (attr "length")
+    (cond [(lt (abs (minus (match_dup 2) (plus (pc) (const_int 8))))
+              (const_int MAX_12BIT_OFFSET))
+          (const_int 4)
+          (lt (abs (minus (match_dup 2) (plus (pc) (const_int 8))))
+              (const_int MAX_17BIT_OFFSET))
+          (const_int 8)
+          (ne (symbol_ref "TARGET_PORTABLE_RUNTIME") (const_int 0))
+          (const_int 24)
+          (eq (symbol_ref "flag_pic") (const_int 0))
+          (const_int 20)]
+         (const_int 28)))])
 
 (define_insn ""
   [(set (pc) (label_ref (match_operand 2 "" "" )))
@@ -8832,14 +9540,21 @@ add,l %2,%3,%3\;bv,n %%r0(%3)"
   "reload_completed"
   "*
 {
-  return output_parallel_movb (operands, get_attr_length (insn));
+  return output_parallel_movb (operands, insn);
 }"
-  [(set_attr "type" "parallel_branch")
-   (set (attr "length")
-    (if_then_else (lt (abs (minus (match_dup 2) (plus (pc) (const_int 8))))
-                     (const_int 8184))
-           (const_int 4)
-          (const_int 8)))])
+[(set_attr "type" "parallel_branch")
+ (set (attr "length")
+    (cond [(lt (abs (minus (match_dup 2) (plus (pc) (const_int 8))))
+              (const_int MAX_12BIT_OFFSET))
+          (const_int 4)
+          (lt (abs (minus (match_dup 2) (plus (pc) (const_int 8))))
+              (const_int MAX_17BIT_OFFSET))
+          (const_int 8)
+          (ne (symbol_ref "TARGET_PORTABLE_RUNTIME") (const_int 0))
+          (const_int 24)
+          (eq (symbol_ref "flag_pic") (const_int 0))
+          (const_int 20)]
+         (const_int 28)))])
 
 (define_insn ""
   [(set (match_operand 0 "register_operand" "=f")
@@ -9263,8 +9978,7 @@ add,l %2,%3,%3\;bv,n %%r0(%3)"
 {
   int locality = INTVAL (operands[2]);
 
-  if (locality < 0 || locality > 3)
-    abort ();
+  gcc_assert (locality >= 0 && locality <= 3);
 
   /* Change operand[0] to a MEM as we don't have the infrastructure
      to output all the supported address modes for ldw/ldd when we use
@@ -9309,8 +10023,7 @@ add,l %2,%3,%3\;bv,n %%r0(%3)"
   };
   int read_or_write = INTVAL (operands[1]);
 
-  if (read_or_write < 0 || read_or_write > 1)
-    abort ();
+  gcc_assert (read_or_write >= 0 && read_or_write <= 1);
 
   return instr [read_or_write];
 }
@@ -9338,11 +10051,90 @@ add,l %2,%3,%3\;bv,n %%r0(%3)"
   };
   int read_or_write = INTVAL (operands[1]);
 
-  if ((which_alternative != 0 && which_alternative != 1)
-      || (read_or_write < 0 || read_or_write > 1))
-    abort ();
+  gcc_assert (which_alternative == 0 || which_alternative == 1);
+  gcc_assert (read_or_write >= 0 && read_or_write <= 1);
 
   return instr [which_alternative][read_or_write];
 }
   [(set_attr "type" "load")
    (set_attr "length" "4")])
+
+
+;; TLS Support
+(define_insn "tgd_load"
+ [(set (match_operand:SI 0 "register_operand" "=r")
+       (unspec:SI [(match_operand 1 "tgd_symbolic_operand" "")] UNSPEC_TLSGD))
+  (clobber (reg:SI 1))]
+  ""
+  "*
+{
+  if (flag_pic)
+    return \"addil LT'%1-$tls_gdidx$,%%r19\;ldo RT'%1-$tls_gdidx$(%%r1),%0\";
+  else
+    return \"addil LR'%1-$tls_gdidx$,%%r27\;ldo RR'%1-$tls_gdidx$(%%r1),%0\";
+}"
+  [(set_attr "type" "multi")
+   (set_attr "length" "8")])
+
+(define_insn "tld_load"
+ [(set (match_operand:SI 0 "register_operand" "=r")
+       (unspec:SI [(match_operand 1 "tld_symbolic_operand" "")] UNSPEC_TLSLDM))
+  (clobber (reg:SI 1))]
+  ""
+  "*
+{
+  if (flag_pic)
+    return \"addil LT'%1-$tls_ldidx$,%%r19\;ldo RT'%1-$tls_ldidx$(%%r1),%0\";
+  else
+    return \"addil LR'%1-$tls_ldidx$,%%r27\;ldo RR'%1-$tls_ldidx$(%%r1),%0\";
+}"
+  [(set_attr "type" "multi")
+   (set_attr "length" "8")])
+
+(define_insn "tld_offset_load"
+  [(set (match_operand:SI 0 "register_operand" "=r")
+        (plus:SI (unspec:SI [(match_operand 1 "tld_symbolic_operand" "")] 
+                           UNSPEC_TLSLDO)
+                (match_operand:SI 2 "register_operand" "r")))
+   (clobber (reg:SI 1))]
+  ""
+  "*
+{
+  return \"addil LR'%1-$tls_dtpoff$,%2\;ldo RR'%1-$tls_dtpoff$(%%r1),%0\"; 
+}"
+  [(set_attr "type" "multi")
+   (set_attr "length" "8")])
+
+(define_insn "tp_load"
+  [(set (match_operand:SI 0 "register_operand" "=r")
+       (unspec:SI [(const_int 0)] UNSPEC_TP))]
+  ""
+  "mfctl %%cr27,%0"
+  [(set_attr "type" "multi")
+   (set_attr "length" "4")])
+
+(define_insn "tie_load"
+  [(set (match_operand:SI 0 "register_operand" "=r")
+        (unspec:SI [(match_operand 1 "tie_symbolic_operand" "")] UNSPEC_TLSIE))
+   (clobber (reg:SI 1))]
+  ""
+  "*
+{
+  if (flag_pic)
+    return \"addil LT'%1-$tls_ieoff$,%%r19\;ldw RT'%1-$tls_ieoff$(%%r1),%0\";
+  else
+    return \"addil LR'%1-$tls_ieoff$,%%r27\;ldw RR'%1-$tls_ieoff$(%%r1),%0\";
+}"
+  [(set_attr "type" "multi")
+   (set_attr "length" "8")])
+
+(define_insn "tle_load"
+  [(set (match_operand:SI 0 "register_operand" "=r")
+        (plus:SI (unspec:SI [(match_operand 1 "tle_symbolic_operand" "")] 
+                           UNSPEC_TLSLE)
+                (match_operand:SI 2 "register_operand" "r")))
+   (clobber (reg:SI 1))]
+  ""
+  "addil LR'%1-$tls_leoff$,%2\;ldo RR'%1-$tls_leoff$(%%r1),%0"
+  [(set_attr "type" "multi")
+   (set_attr "length" "8")])