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 PR18942


Hello,

> 
> On Sun, 19 Dec 2004, Zdenek Dvorak wrote:
> > 	PR rtl-optimization/18942
> > 	* simplify-rtx.c (simplify_relational_operation_1): Simplify
> > 	x + cst1 == cst2 to x == cst2 - cst1.
> 
> This is OK for mainline.  Thanks.

here is the patch with the suggested changes.  Bootstrapped & regtested on ppc.

Zdenek

Index: simplify-rtx.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/simplify-rtx.c,v
retrieving revision 1.216
diff -c -3 -p -r1.216 simplify-rtx.c
*** simplify-rtx.c	16 Dec 2004 19:16:54 -0000	1.216
--- simplify-rtx.c	19 Dec 2004 20:01:09 -0000
*************** simplify_relational_operation (enum rtx_
*** 2773,2782 ****
  
     MODE is the mode of the result, while CMP_MODE specifies in which
     mode the comparison is done in, so it is the mode of the operands.  */
! rtx
  simplify_relational_operation_1 (enum rtx_code code, enum machine_mode mode,
  				 enum machine_mode cmp_mode, rtx op0, rtx op1)
  {
    if (GET_CODE (op1) == CONST_INT)
      {
        if (INTVAL (op1) == 0 && COMPARISON_P (op0))
--- 2773,2785 ----
  
     MODE is the mode of the result, while CMP_MODE specifies in which
     mode the comparison is done in, so it is the mode of the operands.  */
! 
! static rtx
  simplify_relational_operation_1 (enum rtx_code code, enum machine_mode mode,
  				 enum machine_mode cmp_mode, rtx op0, rtx op1)
  {
+   enum rtx_code op0code = GET_CODE (op0);
+ 
    if (GET_CODE (op1) == CONST_INT)
      {
        if (INTVAL (op1) == 0 && COMPARISON_P (op0))
*************** simplify_relational_operation_1 (enum rt
*** 2800,2805 ****
--- 2803,2822 ----
  	}
      }
  
+   /* (eq/ne (plus x cst1) cst2) simplifies to (eq/ne x (cst2 - cst1))  */
+   if ((code == EQ || code == NE)
+       && (op0code == PLUS || op0code == MINUS)
+       && CONSTANT_P (op1)
+       && CONSTANT_P (XEXP (op0, 1)))
+     {
+       rtx x = XEXP (op0, 0);
+       rtx c = XEXP (op0, 1);
+ 
+       c = simplify_gen_binary (op0code == PLUS ? MINUS : PLUS,
+ 			       cmp_mode, op1, c);
+       return simplify_gen_relational (code, mode, cmp_mode, x, c);
+     }
+ 
    return NULL_RTX;
  }
  


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