]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
h8300-protos.h: Update the prototype for split_adds_subs.
authorKazu Hirata <kazu@cs.umass.edu>
Sat, 21 Dec 2002 17:43:15 +0000 (17:43 +0000)
committerKazu Hirata <kazu@gcc.gnu.org>
Sat, 21 Dec 2002 17:43:15 +0000 (17:43 +0000)
* config/h8300/h8300-protos.h: Update the prototype for
split_adds_subs.
Add prototypes for const_le_2_operand and const_le_6_operand.
* config/h8300/h8300.c (split_adds_subs): Add an argument to
specify whether inc/dec should be used when possible.
(const_le_2_operand): New.
(const_le_6_operand): Likewise.
* config/h8300/h8300.md (two peepholes): New.

From-SVN: r60387

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

index 6261fe35c804bf411528dcb479ada5662d3fa169..5896006ece793606743e388d13a733fb088d2ec8 100644 (file)
@@ -1,3 +1,14 @@
+2002-12-21  Kazu Hirata  <kazu@cs.umass.edu>
+
+       * config/h8300/h8300-protos.h: Update the prototype for
+       split_adds_subs.
+       Add prototypes for const_le_2_operand and const_le_6_operand.
+       * config/h8300/h8300.c (split_adds_subs): Add an argument to
+       specify whether inc/dec should be used when possible.
+       (const_le_2_operand): New.
+       (const_le_6_operand): Likewise.
+       * config/h8300/h8300.md (two peepholes): New.
+
 2002-12-21  Kazu Hirata  <kazu@cs.umass.edu>
 
        * config/fr30/fr30.md: Fix a comment typo.
index f56d8377ea9a0e585e7e671f3cac437b457089bc..ebb0cd17d4cff1aad02f380fdec25aa1748c6e25 100644 (file)
@@ -47,7 +47,7 @@ extern int h8300_shift_needs_scratch_p PARAMS ((int, enum machine_mode));
 extern int expand_a_rotate PARAMS ((enum rtx_code, rtx[]));
 extern int fix_bit_operand PARAMS ((rtx *, int, enum rtx_code));
 extern int h8300_adjust_insn_length PARAMS ((rtx, int));
-extern void split_adds_subs PARAMS ((enum machine_mode, rtx[]));
+extern void split_adds_subs PARAMS ((enum machine_mode, rtx[], int));
 
 extern int general_operand_src PARAMS ((rtx, enum machine_mode));
 extern int general_operand_dst PARAMS ((rtx, enum machine_mode));
@@ -59,6 +59,8 @@ extern int small_call_insn_operand PARAMS ((rtx, enum machine_mode));
 extern int jump_address_operand PARAMS ((rtx, enum machine_mode));
 extern int bit_operand PARAMS ((rtx, enum machine_mode));
 extern int bit_memory_operand PARAMS ((rtx, enum machine_mode));
+extern int const_le_2_operand PARAMS ((rtx, enum machine_mode));
+extern int const_le_6_operand PARAMS ((rtx, enum machine_mode));
 extern int incdec_operand PARAMS ((rtx, enum machine_mode));
 extern int bit_operator PARAMS ((rtx, enum machine_mode));
 extern int nshift_operator PARAMS ((rtx, enum machine_mode));
index 739728c69451f7b1ae8af19e4217a16ae257e965..c13b247ec75a99260dd5cbdaf92eff0f749f11f1 100644 (file)
@@ -916,17 +916,23 @@ two_insn_adds_subs_operand (op, mode)
   return 0;
 }
 
-/* Split an add of a small constant into two adds/subs insns.  */
+/* Split an add of a small constant into two adds/subs insns.
+
+   If USE_INCDEC_P is nonzero, we generate the last insn using inc/dec
+   instead of adds/subs.  */
 
 void
-split_adds_subs (mode, operands)
+split_adds_subs (mode, operands, use_incdec_p)
      enum machine_mode mode;
      rtx *operands;
+     int use_incdec_p;
 {
   HOST_WIDE_INT val = INTVAL (operands[1]);
   rtx reg = operands[0];
   HOST_WIDE_INT sign = 1;
   HOST_WIDE_INT amount;
+  rtx (*gen_last) (rtx, rtx, rtx);
+  rtx (*gen_normal) (rtx, rtx, rtx);
 
   /* Force VAL to be positive so that we do not have to consider the
      sign.  */
@@ -936,6 +942,22 @@ split_adds_subs (mode, operands)
       sign = -1;
     }
 
+  switch (mode)
+    {
+    case HImode:
+      gen_normal = gen_addhi3;
+      gen_last   = gen_addhi3_incdec;
+      break;
+
+    case SImode:
+      gen_normal = gen_addsi3;
+      gen_last   = gen_addsi3_incdec;
+      break;
+
+    default:
+      abort ();
+    }
+
   /* Try different amounts in descending order.  */
   for (amount = (TARGET_H8300H || TARGET_H8300S) ? 4 : 2;
        amount > 0;
@@ -943,8 +965,11 @@ split_adds_subs (mode, operands)
     {
       for (; val >= amount; val -= amount)
        {
-         rtx tmp = gen_rtx_PLUS (mode, reg, GEN_INT (sign * amount));
-         emit_insn (gen_rtx_SET (VOIDmode, reg, tmp));
+         /* If requested, generate the last insn using inc/dec.  */
+         if (use_incdec_p && amount <= 2 && val == amount)
+           emit_insn (gen_last (reg, reg, GEN_INT (sign * amount)));
+         else
+           emit_insn (gen_normal (reg, reg, GEN_INT (sign * amount)));
        }
     }
 
@@ -1806,6 +1831,30 @@ notice_update_cc (body, insn)
     }
 }
 
+/* Return nonzero if X is a constant whose absolute value is no
+   greater than 2.  */
+
+int
+const_le_2_operand (x, mode)
+     rtx x;
+     enum machine_mode mode ATTRIBUTE_UNUSED;
+{
+  return (GET_CODE (x) == CONST_INT
+         && abs (INTVAL (x)) <= 2);
+}
+
+/* Return nonzero if X is a constant whose absolute value is no
+   greater than 6.  */
+
+int
+const_le_6_operand (x, mode)
+     rtx x;
+     enum machine_mode mode ATTRIBUTE_UNUSED;
+{
+  return (GET_CODE (x) == CONST_INT
+         && abs (INTVAL (x)) <= 6);
+}
+
 /* Return nonzero if X is a constant suitable for inc/dec.  */
 
 int
index 5bba952c0a57e78cc4d4adbfe439ad9b95f2863b..5eb0c74ee9c6dfe91efd146207d3666b34ce026e 100644 (file)
                 (match_operand:HI 1 "two_insn_adds_subs_operand" "")))]
   ""
   [(const_int 0)]
-  "split_adds_subs (HImode, operands); DONE;")
+  "split_adds_subs (HImode, operands, 0); DONE;")
 
 (define_expand "addsi3"
   [(set (match_operand:SI 0 "register_operand" "")
                 (match_operand:SI 1 "two_insn_adds_subs_operand" "")))]
   "TARGET_H8300H || TARGET_H8300S"
   [(const_int 0)]
-  "split_adds_subs (SImode, operands); DONE;")
+  "split_adds_subs (SImode, operands, 0); DONE;")
 
 ;; ----------------------------------------------------------------------
 ;; SUBTRACT INSTRUCTIONS
                      (label_ref (match_dup 2))
                      (pc)))]
   "")
+
+;; For a small constant, it is cheaper to actually do the subtraction
+;; and then test the register.
+
+(define_peephole2
+  [(set (cc0)
+       (compare:HI (match_operand:HI 0 "register_operand" "")
+                   (match_operand:HI 1 "const_le_2_operand" "")))
+   (set (pc)
+       (if_then_else (match_operator 3 "eqne_operator"
+                       [(cc0) (const_int 0)])
+                     (label_ref (match_operand 2 "" ""))
+                     (pc)))]
+  "(TARGET_H8300H || TARGET_H8300S)
+   && find_regno_note (insn, REG_DEAD, REGNO (operands[0]))"
+  [(set (cc0)
+       (match_dup 0))
+   (set (pc)
+       (if_then_else (match_op_dup 3 [(cc0) (const_int 0)])
+                     (label_ref (match_operand 2 "" ""))
+                     (pc)))]
+  "operands[1] = GEN_INT (- INTVAL (operands[1]));
+   split_adds_subs (HImode, operands, 1);")
+
+;; The SImode version of the previous pattern.
+
+(define_peephole2
+  [(set (cc0)
+       (compare:SI (match_operand:SI 0 "register_operand" "")
+                   (match_operand:SI 1 "const_le_6_operand" "")))
+   (set (pc)
+       (if_then_else (match_operator 3 "eqne_operator"
+                       [(cc0) (const_int 0)])
+                     (label_ref (match_operand 2 "" ""))
+                     (pc)))]
+  "(TARGET_H8300H || TARGET_H8300S)
+   && find_regno_note (insn, REG_DEAD, REGNO (operands[0]))"
+  [(set (cc0)
+       (match_dup 0))
+   (set (pc)
+       (if_then_else (match_op_dup 3 [(cc0) (const_int 0)])
+                     (label_ref (match_operand 2 "" ""))
+                     (pc)))]
+  "operands[1] = GEN_INT (- INTVAL (operands[1]));
+   split_adds_subs (SImode, operands, 1);")