[Commited] Constant fold (x | 5) != 0
Roger Sayle
roger@eyesopen.com
Tue Mar 23 19:21:00 GMT 2004
I've committed the following minor improvement to GCC's constant folding
to mainline. This patch adds three additional cases to the middle-end's
predicates that are used for simplifying conditional expressions.
[1] The expression "A & B" is nonnegative, if A or B is nonnegative.
[2] The expression "A | B" is nonnegative, if A and B are nonnegative.
[3] The expression "A | B" is nonzero, if A is nonzero or B is nonzero.
Although the expression "(x | 5) != 0" is currently optimized away at
the RTL-level, supporting this transformation in "fold" makes it available
to tree-ssa's optimizers.
The following patch was tested on i686-pc-linux-gnu with a complete "make
bootstrap", all languages except treelang, and regression tested with a
top-level "make -k check" with no new failures.
2004-03-23 Roger Sayle <roger@eyesopen.com>
* fold-const.c (tree_expr_nonnegative_p): A&B is nonnegative when
A is nonnegative or B is nonnegative. Similarly A|B is nonnegative
when both A and B are nonnegative.
(tree_expr_nonzero_p): A|B is nonzero when A is nonzero or B is
nonzero.
Index: fold-const.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/fold-const.c,v
retrieving revision 1.355
diff -c -3 -p -r1.355 fold-const.c
*** fold-const.c 21 Mar 2004 18:09:17 -0000 1.355
--- fold-const.c 22 Mar 2004 02:07:08 -0000
*************** tree_expr_nonnegative_p (tree t)
*** 8722,8727 ****
--- 8722,8734 ----
return tree_expr_nonnegative_p (TREE_OPERAND (t, 0))
&& tree_expr_nonnegative_p (TREE_OPERAND (t, 1));
+ case BIT_AND_EXPR:
+ return tree_expr_nonnegative_p (TREE_OPERAND (t, 1))
+ || tree_expr_nonnegative_p (TREE_OPERAND (t, 0));
+ case BIT_IOR_EXPR:
+ return tree_expr_nonnegative_p (TREE_OPERAND (t, 0))
+ && tree_expr_nonnegative_p (TREE_OPERAND (t, 1));
+
case NOP_EXPR:
{
tree inner_type = TREE_TYPE (TREE_OPERAND (t, 0));
*************** tree_expr_nonzero_p (tree t)
*** 8959,8964 ****
--- 8966,8975 ----
case SAVE_EXPR:
case NON_LVALUE_EXPR:
return tree_expr_nonzero_p (TREE_OPERAND (t, 0));
+
+ case BIT_IOR_EXPR:
+ return tree_expr_nonzero_p (TREE_OPERAND (t, 1))
+ || tree_expr_nonzero_p (TREE_OPERAND (t, 0));
default:
break;
Roger
--
Roger Sayle, E-mail: roger@eyesopen.com
OpenEye Scientific Software, WWW: http://www.eyesopen.com/
Suite 1107, 3600 Cerrillos Road, Tel: (+1) 505-473-7385
Santa Fe, New Mexico, 87507. Fax: (+1) 505-473-0833
More information about the Gcc-patches
mailing list