This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: PATCH: simplify ~x + 1 into -x
- To: Geoff Keating <geoffk at geoffk dot org>
- Subject: Re: PATCH: simplify ~x + 1 into -x
- From: Lars Brinkhoff <lars dot spam at nocrew dot org>
- Date: 04 May 2001 12:06:40 +0200
- Cc: gcc-patches at gcc dot gnu dot org
- Organization: nocrew
- References: <85ae58hvw1.fsf@junk.nocrew.org> <jm7l0b3ceh.fsf@geoffk.org><85g0eyh4et.fsf@junk.nocrew.org>
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