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: PATCH: simplify ~x + 1 into -x


This patch is unreviewed:

Lars Brinkhoff <lars.spam@nocrew.org> writes:
> Geoff Keating <geoffk@geoffk.org> writes:
> > Lars Brinkhoff <lars@nocrew.org> writes:
> > > This patch simlifies ~x + 1 into -x.  It also adds a new target
> > > macro to indicate the integer format
> > 
> > The TARGET_INT_FORMAT part is not OK.  The optimisation part might
> > be OK, please submit it separately.
> 
> Ok.  Then the patch boils down to just this.

Updated to the current CVS tree.  Bootstrapped and checked on
powerpc-unknown-linux-gnu.

2001-05-04  Lars Brinkhoff  <lars@nocrew.org>

	* simplify-rtx.c (simplify_binary_operation): Simplify ~a + 1
	into -a.

Index: simplify-rtx.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/simplify-rtx.c,v
retrieving revision 1.47
diff -c -3 -p -r1.47 simplify-rtx.c
*** simplify-rtx.c	2001/05/01 12:11:34	1.47
--- simplify-rtx.c	2001/05/04 09:59:41
*************** simplify_binary_operation (code, mode, o
*** 945,950 ****
--- 945,957 ----
  	  else if (GET_CODE (op1) == NEG)
  	    return simplify_gen_binary (MINUS, mode, op0, XEXP (op1, 0));
  
+ 	  /* (~a) + 1 -> -a */
+ 	  if (INTEGRAL_MODE_P (mode)
+ 	      && GET_CODE (op0) == NOT
+ 	      && GET_CODE (op1) == CONST_INT
+ 	      && INTVAL (op1) == 1)
+ 	    return gen_rtx_NEG (mode, XEXP (op0, 0));
+ 
  	  /* Handle both-operands-constant cases.  We can only add
  	     CONST_INTs to constants since the sum of relocatable symbols
  	     can't be handled by most assemblers.  Don't add CONST_INT


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