This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: PATCH for [ARM] subsequent use of plus and minus operators couldbe improved
- From: Gábor Lóki <alga at rgai dot hu>
- To: Richard dot Earnshaw at arm dot com
- Cc: gcc-patches <gcc-patches at gcc dot gnu dot org>
- Date: Wed, 16 Apr 2003 13:14:44 +0100
- Subject: Re: PATCH for [ARM] subsequent use of plus and minus operators couldbe improved
- References: <200304071029.h37ATks28444@pc960.cambridge.arm.com>
Richard Earnshaw wrote:
> First of all, please read the documents on contributing to GCC and pay
> particular attention to the coding standards sections. Patches can only
> be accepted if they conform to these standards.
Ok. I am done with the code forming.
> You should look to see if this code could be merged with one of the other
> reload_cse passes so that we can avoid another scan through the entire RTL
> of a function. One possible candidate here is reload_cse_move2add which
> is looking for similar types of thing to fix up.
I examined the reload_cse_move2add candidate again, but as I saw it first, this
function tries to transform move instruction into add. This isn't what I'd like
to do, and no other reload_cse passes do the same thing. These were the reasons
why I created a new function.
You are right. There is no reason for another scan on the RTL. So I merged my
code with reload_cse_move2add. You can see in the attached patch.
>
> You need to contact the Copyright Assignment Clerk at the FSF (IIRC
> assign at gnu dot org). Explain what you want to contribute to and who will be
> contributing; they can then send you the correct papers for you to sign.
>
We've sent our request to the copyright office and to the gcc list as well
(http://gcc.gnu.org/ml/gcc/2003-04/msg00257.html). We got a reply from Peter
Brown (FSF) to contact the maintainers first, but we didn't get any answer yet.
What shall we do now?
Regards,
Gábor Lóki
*** reload1.c.orig Sat Mar 29 00:22:05 2003
--- reload1.c Wed Apr 9 10:40:42 2003
*************** reload_cse_move2add (first)
*** 9116,9122 ****
move2add_luid = 2;
for (insn = first; insn; insn = NEXT_INSN (insn), move2add_luid++)
{
! rtx pat, note;
if (GET_CODE (insn) == CODE_LABEL)
{
--- 9116,9122 ----
move2add_luid = 2;
for (insn = first; insn; insn = NEXT_INSN (insn), move2add_luid++)
{
! rtx pat, note, next;
if (GET_CODE (insn) == CODE_LABEL)
{
*************** reload_cse_move2add (first)
*** 9130,9135 ****
--- 9130,9186 ----
if (! INSN_P (insn))
continue;
pat = PATTERN (insn);
+ next = NEXT_INSN (insn);
+
+ /* Try to transform
+ (set (regX) (plus\minus (regY) (constA)))
+ (set (regX) (plus\minus (regX) (constB)))
+ to
+ (set (regX) (plus\minus (regY) (constA +\- constB))) */
+ if (next
+ && GET_CODE (pat) == SET
+ && GET_CODE (next) == INSN
+ && GET_CODE (PATTERN (next)) == SET)
+ {
+ rtx insn_dest = SET_DEST (pat);
+ rtx insn_src = SET_SRC (pat);
+ rtx next_dest = SET_DEST (PATTERN (next));
+ rtx next_src = SET_SRC (PATTERN (next));
+
+ if (GET_CODE (insn_dest) == REG
+ && (GET_CODE (insn_src) == PLUS
+ || GET_CODE (insn_src) == MINUS)
+ && GET_CODE (XEXP (insn_src, 0)) == REG
+ && GET_CODE (XEXP (insn_src, 1)) == CONST_INT
+ && GET_CODE (next_dest) == REG
+ && (GET_CODE (next_src) == PLUS
+ || GET_CODE (next_src) == MINUS)
+ && GET_CODE (XEXP (next_src, 0)) == REG
+ && GET_CODE (XEXP (next_src, 1)) == CONST_INT
+ && REGNO (insn_dest) == REGNO (next_dest)
+ && REGNO (next_dest) == REGNO (XEXP (next_src, 0)))
+ {
+ int success = 0;
+ int sign = (GET_CODE (insn_src) ==
+ GET_CODE (next_src)) ? 1 : -1;
+ /* Combine the two constant into a new one. */
+ rtx new_value = GEN_INT (INTVAL (XEXP (insn_src, 1)) +
+ sign * INTVAL (XEXP (next_src, 1)));
+ if (new_value == const0_rtx)
+ /* Create (set (regX) (regY)) if the new constant is zero. */
+ success = validate_change (insn,
+ &SET_SRC (PATTERN (insn)),
+ XEXP (insn_src,0), 0);
+ else
+ /* Override the constA with the new constant. */
+ success = validate_change (insn,
+ &XEXP (SET_SRC (PATTERN (insn)),1),
+ new_value, 0);
+ if (success)
+ delete_insn (next);
+ }
+ }
+
/* For simplicity, we only perform this optimization on
straightforward SETs. */
if (GET_CODE (pat) == SET