This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: PATCH for [ARM] subsequent use of plus and minus operators couldbe improved


Richard Earnshaw wrote:
>>>+       /* Try to transform
>>>+            (set (regX) (plus\minus (regY) (constA)))
>>>+            (set (regX) (plus\minus (regX) (constB)))
>>>+          to
>>>+            (set (regX) (plus\minus (regY) (constA +\- constB))) */
>>
>>You should use forward slashes (/) here, not backslashes (\).
>
>
> In fact, because of canonicalization there should never be a MINUS with a
> constant as the second operand -- this should always be transformed into
> addition of the negated constant.  So there's no need to check for that
> case.
>
> R.
>

I've noticed that too, but I wrote this possibilities for sure.
So, in this aspect I took out this case from the patch.

All modifications are in the attched patch.

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,9183 ----
        if (! INSN_P (insn))
  	continue;
        pat = PATTERN (insn);
+       next = NEXT_INSN (insn);
+       
+       /* Try to transform 
+            (set (regX) (plus (regY) (constA)))
+            (set (regX) (plus (regX) (constB)))
+          to
+            (set (regX) (plus (regY) (constA + constB))) */
+       if (next 
+           && GET_CODE (pat) == SET 
+           && GET_CODE (next) == INSN 
+           && GET_CODE (PATTERN (next)) == SET)
+         {
+           rtx insn_dest, insn_src, next_dest, next_src;
+           insn_dest = SET_DEST (pat);
+           insn_src = SET_SRC (pat);
+           next_dest = SET_DEST (PATTERN (next));
+           next_src = SET_SRC (PATTERN (next));
+           
+           if (GET_CODE (insn_dest) == REG 
+               && GET_CODE (insn_src) == PLUS 
+               && 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 (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;
+               rtx new_value = GEN_INT (INTVAL (XEXP (insn_src, 1)) + 
+                                        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                                          
+                 /* Otherwise, replace 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




Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]