aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJeff Law <law@gcc.gnu.org>2005-03-10 21:52:42 -0700
committerJeff Law <law@gcc.gnu.org>2005-03-10 21:52:42 -0700
commitcbefb99c9944240c248e7aa8dcd9bfd2b7ecc864 (patch)
treeb68e8b88fbd204957fa2a685eaa6985b21264dfc
parentc0cbd601303809da24e1ea49b711193cba4815be (diff)
downloadgcc-cbefb99c9944240c248e7aa8dcd9bfd2b7ecc864.zip
gcc-cbefb99c9944240c248e7aa8dcd9bfd2b7ecc864.tar.gz
gcc-cbefb99c9944240c248e7aa8dcd9bfd2b7ecc864.tar.bz2
re PR tree-optimization/15784 (fold misses binary optimization)
PR tree-optimization/15784 * fold-const.c (fold): Fold ~A + 1 to -A. Fold -A - 1 and -1 - A to ~A. * stmt.c (expand_case): Don't change index_type. Convert minval to the proper type. From-SVN: r96289
-rw-r--r--gcc/ChangeLog11
-rw-r--r--gcc/fold-const.c15
-rw-r--r--gcc/stmt.c5
3 files changed, 26 insertions, 5 deletions
diff --git a/gcc/ChangeLog b/gcc/ChangeLog
index 82d61aa..8f21dbb 100644
--- a/gcc/ChangeLog
+++ b/gcc/ChangeLog
@@ -1,5 +1,12 @@
2005-03-11 James A. Morrison <phython@gcc.gnu.org>
+ PR tree-optimization/15784
+ * fold-const.c (fold): Fold ~A + 1 to -A. Fold -A - 1
+ and -1 - A to ~A.
+
+ * stmt.c (expand_case): Don't change index_type. Convert minval
+ to the proper type.
+
PR tree-optimization/20130
* fold-const.c (fold): Fold x * -1 into -x.
@@ -722,7 +729,7 @@
Revert for now:
2005-03-03 James A. Morrison <phython@gcc.gnu.org>
PR tree-optimization/15784
- * fold-const.c (fold): Fold ~A + 1 to -1. Fold -A - 1
+ * fold-const.c (fold): Fold ~A + 1 to -A. Fold -A - 1
and -1 - A to ~A.
2005-03-04 Ben Elliston <bje@au.ibm.com>
@@ -756,7 +763,7 @@
2005-03-03 James A. Morrison <phython@gcc.gnu.org>
PR tree-optimization/15784
- * fold-const.c (fold): Fold ~A + 1 to -1. Fold -A - 1
+ * fold-const.c (fold): Fold ~A + 1 to -A. Fold -A - 1
and -1 - A to ~A.
2005-03-03 David Edelsohn <edelsohn@gnu.org>
diff --git a/gcc/fold-const.c b/gcc/fold-const.c
index 9d0a9f0..3fdfb92 100644
--- a/gcc/fold-const.c
+++ b/gcc/fold-const.c
@@ -7198,6 +7198,11 @@ fold_binary (enum tree_code code, tree type, tree op0, tree op1)
if (TREE_CODE (arg0) == NEGATE_EXPR
&& reorder_operands_p (TREE_OPERAND (arg0, 0), arg1))
return fold (build2 (MINUS_EXPR, type, arg1, TREE_OPERAND (arg0, 0)));
+ /* Convert ~A + 1 to -A. */
+ if (INTEGRAL_TYPE_P (type)
+ && TREE_CODE (arg0) == BIT_NOT_EXPR
+ && integer_onep (arg1))
+ return fold (build1 (NEGATE_EXPR, type, TREE_OPERAND (arg0, 0)));
if (TREE_CODE (type) == COMPLEX_TYPE)
{
@@ -7636,6 +7641,16 @@ fold_binary (enum tree_code code, tree type, tree op0, tree op1)
&& reorder_operands_p (arg0, arg1))
return fold (build2 (MINUS_EXPR, type, negate_expr (arg1),
TREE_OPERAND (arg0, 0)));
+ /* Convert -A - 1 to ~A. */
+ if (INTEGRAL_TYPE_P (type)
+ && TREE_CODE (arg0) == NEGATE_EXPR
+ && integer_onep (arg1))
+ return fold (build1 (BIT_NOT_EXPR, type, TREE_OPERAND (arg0, 0)));
+
+ /* Convert -1 - A to ~A. */
+ if (INTEGRAL_TYPE_P (type)
+ && integer_all_onesp (arg0))
+ return fold (build1 (BIT_NOT_EXPR, type, arg1));
if (TREE_CODE (type) == COMPLEX_TYPE)
{
diff --git a/gcc/stmt.c b/gcc/stmt.c
index a23c23c..9a1df90 100644
--- a/gcc/stmt.c
+++ b/gcc/stmt.c
@@ -2424,7 +2424,7 @@ expand_case (tree exp)
if (compare_tree_int (minval, 0) > 0
&& compare_tree_int (maxval, GET_MODE_BITSIZE (word_mode)) < 0)
{
- minval = integer_zero_node;
+ minval = fold_convert (index_type, integer_zero_node);
range = maxval;
}
emit_case_bit_tests (index_type, index_expr, minval, range,
@@ -2502,7 +2502,6 @@ expand_case (tree exp)
table_label, default_label))
{
bool ok;
- index_type = integer_type_node;
/* Index jumptables from zero for suitable values of
minval to avoid a subtraction. */
@@ -2510,7 +2509,7 @@ expand_case (tree exp)
&& compare_tree_int (minval, 0) > 0
&& compare_tree_int (minval, 3) < 0)
{
- minval = integer_zero_node;
+ minval = fold_convert (index_type, integer_zero_node);
range = maxval;
}