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: 24 Apr 2001 14:24:10 +0200
- Cc: gcc-patches at gcc dot gnu dot org
- Organization: nocrew
- References: <85ae58hvw1.fsf@junk.nocrew.org> <jm7l0b3ceh.fsf@geoffk.org>
Geoff Keating <geoffk@geoffk.org> writes:
> Lars Brinkhoff <lars@nocrew.org> writes:
> > This patch simlifies ~x + 1 into -x on two's complement machines
> > (probably all machines supported by GCC). It also adds a new target
> > macro to indicate the integer format, in case anyone would like to
> > port GCC to a machine without two's complement integers.
>
> The TARGET_INT_FORMAT part is not OK, because there are lots of other
> places where GCC assumes two's-complement, and so it just adds clutter
> without adding any new features. (It would be different if you
> actually planned to port GCC to a non-twos-complement machine.)
>
> The optimisation part might be OK, please submit it separately.
Ok. Then the patch boils down to just this.
Bootstrapped on powerpc-unknown-linux-gnu and checked without
regressions.
2001-04-24 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.45
diff -c -3 -p -r1.45 simplify-rtx.c
*** simplify-rtx.c 2001/04/05 02:27:45 1.45
--- simplify-rtx.c 2001/04/24 12:04:48
*************** simplify_binary_operation (code, mode, o
*** 915,920 ****
--- 915,927 ----
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