This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[patch] reload1.c: Extend move2add to strict_low_part.
- From: Kazu Hirata <kazu at cs dot umass dot edu>
- To: gcc-patches at gcc dot gnu dot org
- Date: Mon, 24 Feb 2003 08:17:20 -0500 (EST)
- Subject: [patch] reload1.c: Extend move2add to strict_low_part.
Hi,
Attached is a patch to extend move2add to strict_low_part.
Currently, move2add doesn't do anything when the substitution of SET
with PLUS turns out to not be profitable. Before we fail, we can try
one more thing, STRICT_LOW_PART. That is, we see if we can convert
(set (reg:SI)
(const_int 66))
:
:
(set (reg:SI)
(const_int 100))
to
(set (reg:SI)
(const_int 66))
:
:
(set (strict_low_part (reg:QI))
(const_int 100))
When one uses an SImode variable for example, the value range of the
variable is often limited to 255, so this transformation happens a lot
in real code.
Tested on h8300 port. OK to apply?
Kazu Hirata
2003-02-24 Kazu Hirata <kazu at cs dot umass dot edu>
* reload1.c (reload_cse_move2add): Use STRICT_LOW_PART if PLUS
does not reduce the cost of SET.
Index: reload1.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/reload1.c,v
retrieving revision 1.379
diff -u -r1.379 reload1.c
--- reload1.c 14 Feb 2003 22:23:48 -0000 1.379
+++ reload1.c 24 Feb 2003 05:53:10 -0000
@@ -9159,7 +9159,12 @@
to
(set (REGX) (CONST_INT A))
...
- (set (REGX) (plus (REGX) (CONST_INT B-A))) */
+ (set (REGX) (plus (REGX) (CONST_INT B-A)))
+ or
+ (set (REGX) (CONST_INT A))
+ ...
+ (set (STRICT_LOW_PART (REGX)) (CONST_INT B))
+ */
if (GET_CODE (src) == CONST_INT && reg_base_reg[regno] < 0)
{
@@ -9179,6 +9184,36 @@
&& have_add2_insn (reg, new_src))
success = validate_change (insn, &PATTERN (insn),
gen_add2_insn (reg, new_src), 0);
+ else
+ {
+ enum machine_mode narrow_mode;
+ for (narrow_mode = GET_CLASS_NARROWEST_MODE (MODE_INT);
+ narrow_mode != GET_MODE (reg);
+ narrow_mode = GET_MODE_WIDER_MODE (narrow_mode))
+ {
+ if (have_insn_for (STRICT_LOW_PART, narrow_mode)
+ && ((reg_offset[regno]
+ & ~GET_MODE_MASK (narrow_mode))
+ == (INTVAL (src)
+ & ~GET_MODE_MASK (narrow_mode))))
+ {
+ rtx narrow_reg = gen_rtx_REG (narrow_mode,
+ REGNO (reg));
+ rtx narrow_src =
+ GEN_INT (trunc_int_for_mode (INTVAL (src),
+ narrow_mode));
+ rtx new_set =
+ gen_rtx_SET (VOIDmode,
+ gen_rtx_STRICT_LOW_PART (VOIDmode,
+ narrow_reg),
+ narrow_src);
+ success = validate_change (insn, &PATTERN (insn),
+ new_set, 0);
+ if (success)
+ break;
+ }
+ }
+ }
reg_set_luid[regno] = move2add_luid;
reg_mode[regno] = GET_MODE (reg);
reg_offset[regno] = INTVAL (src);