PATCH: simplify ~x + 1 into -x
Lars Brinkhoff
lars.spam@nocrew.org
Tue Apr 24 05:24:00 GMT 2001
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
More information about the Gcc-patches
mailing list