+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.
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));
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));
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. */
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;
{
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)));
}
}
}
}
+/* 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
(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);")