This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[patch] simplify-rtx.c: Simplify ~y when (x - (x & y)) is found.
- From: Kazu Hirata <kazu at cs dot umass dot edu>
- To: gcc-patches at gcc dot gnu dot org
- Date: Fri, 14 Feb 2003 07:16:24 -0500 (EST)
- Subject: [patch] simplify-rtx.c: Simplify ~y when (x - (x & y)) is found.
Hi,
Attached is a patch to simplify ~y when (x - (x & y)) is found.
For this program,
unsigned long
foo (unsigned long a)
{
return a - (a & 255);
}
the combiner currently suggests
(set (reg:SI 18)
(and:SI (not:SI (const_int 255))
(reg:SI 17)))
Notice that a subexpression (not:SI (const_int 255)) hasn't been
folded. This is because (not:SI (const_int 255)) is generated with
gen_rtx_NOT, not with simplify_gen_unary. The patch replaces
gen_rtx_NOT with simplify_gen_unary.
Regression testing on h8300 port in progress. OK to apply if no
regression is found?
Kazu Hirata
2003-02-14 Kazu Hirata <kazu@cs.umass.edu>
* simplify-rtx.c (simplify_binary_operation): Simplify ~y when
(x - (x & y)) is found.
Index: simplify-rtx.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/simplify-rtx.c,v
retrieving revision 1.136
diff -u -r1.136 simplify-rtx.c
--- simplify-rtx.c 9 Feb 2003 22:55:35 -0000 1.136
+++ simplify-rtx.c 14 Feb 2003 05:08:15 -0000
@@ -1338,11 +1338,17 @@
if (GET_CODE (op1) == AND)
{
if (rtx_equal_p (op0, XEXP (op1, 0)))
- return simplify_gen_binary (AND, mode, op0,
- gen_rtx_NOT (mode, XEXP (op1, 1)));
+ {
+ tem = simplify_gen_unary (NOT, mode, XEXP (op1, 1),
+ GET_MODE (XEXP (op1, 1)));
+ return simplify_gen_binary (AND, mode, op0, tem);
+ }
if (rtx_equal_p (op0, XEXP (op1, 1)))
- return simplify_gen_binary (AND, mode, op0,
- gen_rtx_NOT (mode, XEXP (op1, 0)));
+ {
+ tem = simplify_gen_unary (NOT, mode, XEXP (op1, 0),
+ GET_MODE (XEXP (op1, 0)));
+ return simplify_gen_binary (AND, mode, op0, tem);
+ }
}
break;