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]

Re: validate_replace_rtx_1 fix


>     + /* Return the preference of OP to be the first operand of commutative
>     +    operation.  */
> 
> You should have blank lines before and after this, but you also need to
> say the sense, in this case that that lower the value, the better it is
> as the second operand.
> 
>     +   /* Constants allways come the second operand.  Preffer "nice" constants.  */
> 
> It's "always" and "prefer".
> 
> +     return 101;
> +     return 100;
> +   return 50;
> 
> I don't like these "magic" constants.
> 
> Let's use negative values when this is prefered as the first operand and
> positive for the second.  So the 0, 1, 2, 3, 4 should be -4, -3, -2, and -1.
> Ones that are better for the second should be 1 and 2 and the neutral case
> should return 0.
I wanted to create an gap before largest preference for second operand
and smallest preference for the first, so if someone will want to add
new rule less strict that the existing ones, he will not need to renumber.

But magic is ugly and negative constants looks like good idea, so...

PS: testing has completed sucesfully with previous version of the patch.
I am just starting new round.

Thu May 17 19:53:30 CEST 2001  Jan Hubicka  <jh@suse.cz>

	* recog.c (validate_replace_rtx_1): Properly canonicalize expression
	* rtl.h (swap_commutative_operands_p): Declare.
	* rtlanal.c (swap_commutative_operands_p): New.
	(operand_preference): New static function.

Index: recog.c
===================================================================
RCS file: /cvs/gcc/egcs/gcc/recog.c,v
retrieving revision 1.101
diff -c -3 -p -r1.101 recog.c
*** recog.c	2001/05/17 15:00:35	1.101
--- recog.c	2001/05/17 17:42:47
*************** validate_replace_rtx_1 (loc, from, to, o
*** 468,474 ****
  
        validate_replace_rtx_1 (&XEXP (x, 0), from, to, object);
        validate_replace_rtx_1 (&XEXP (x, 1), from, to, object);
!       if (prev_changes != num_changes && CONSTANT_P (XEXP (x, 0)))
  	{
  	  validate_change (object, loc,
  			   gen_rtx_fmt_ee (GET_RTX_CLASS (code) == 'c' ? code
--- 468,475 ----
  
        validate_replace_rtx_1 (&XEXP (x, 0), from, to, object);
        validate_replace_rtx_1 (&XEXP (x, 1), from, to, object);
!       if (prev_changes != num_changes
! 	  && swap_commutative_operands_p (XEXP (x, 0), XEXP (x, 1)))
  	{
  	  validate_change (object, loc,
  			   gen_rtx_fmt_ee (GET_RTX_CLASS (code) == 'c' ? code
Index: rtl.h
===================================================================
RCS file: /cvs/gcc/egcs/gcc/rtl.h,v
retrieving revision 1.259
diff -c -3 -p -r1.259 rtl.h
*** rtl.h	2001/05/17 15:00:35	1.259
--- rtl.h	2001/05/17 17:42:47
*************** extern int reg_used_between_p		PARAMS ((
*** 1366,1371 ****
--- 1370,1376 ----
  extern int reg_referenced_between_p	PARAMS ((rtx, rtx, rtx));
  extern int reg_set_between_p		PARAMS ((rtx, rtx, rtx));
  extern int regs_set_between_p		PARAMS ((rtx, rtx, rtx));
+ extern int swap_commutative_operands_p	PARAMS ((rtx, rtx));
  extern int modified_between_p		PARAMS ((rtx, rtx, rtx));
  extern int no_labels_between_p		PARAMS ((rtx, rtx));
  extern int no_jumps_between_p		PARAMS ((rtx, rtx));
Index: rtlanal.c
===================================================================
RCS file: /cvs/gcc/egcs/gcc/rtlanal.c,v
retrieving revision 1.95
diff -c -3 -p -r1.95 rtlanal.c
*** rtlanal.c	2001/05/13 21:16:57	1.95
--- rtlanal.c	2001/05/17 18:54:05
*************** Boston, MA 02111-1307, USA.  */
*** 30,35 ****
--- 30,36 ----
  static void set_of_1		PARAMS ((rtx, rtx, void *));
  static void insn_dependent_p_1	PARAMS ((rtx, rtx, void *));
  static int computed_jump_p_1	PARAMS ((rtx));
+ static int operand_preference	PARAMS ((rtx));
  
  /* Bit flags that specify the machine subtype we are compiling for.
     Bits are tested using macros TARGET_... defined in the tm.h file
*************** regno_use_in (regno, x)
*** 2533,2538 ****
--- 2534,2581 ----
    return NULL_RTX;
  }
  
+ /* Return the preference of OP to be the first operand of commutative
+    operation.  Lower the value, the better it is as the second operand. */
+ 
+ static int
+ operand_preference (op)
+      rtx op;
+ {
+   /* Constants always come the second operand.  Prefer "nice" constants.  */
+   if (GET_CODE (op) == CONST_INT)
+     return -4;
+   if (GET_CODE (op) == CONST_DOUBLE)
+     return -3;
+   if (CONSTANT_P (op))
+     return -2;
+ 
+   /* SUBREGs of objects should come second.  */
+   if (GET_CODE (op) == SUBREG
+       && GET_RTX_CLASS (GET_CODE (SUBREG_REG (op))) == 'o')
+     return -1;
+ 
+   /* If only one operand is a `neg', `not',
+     `mult', `plus', or `minus' expression, it will be the first
+     operand.  */
+   if (GET_CODE (op) == NEG || GET_CODE (op) == NOT
+       || GET_CODE (op) == MULT || GET_CODE (op) == PLUS
+       || GET_CODE (op) == MINUS)
+     return 2;
+ 
+   /* Complex expressions should be the first.  */
+   if (GET_RTX_CLASS (GET_CODE (op)) == 'o')
+     return 1;
+   return 0;
+ }
+ 
+ /* Return 1 iff it is neccesary to swap operands of commutative operation
+    in order to canonicalize expression.  */
+ int
+ swap_commutative_operands_p (x, y)
+      rtx x, y;
+ {
+   return operand_preference (x) < operand_preference (y);
+ }
  
  /* Return 1 if X is an autoincrement side effect and the register is
     not the stack pointer.  */


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