aboutsummaryrefslogtreecommitdiff
path: root/gcc
diff options
context:
space:
mode:
authorJames A. Morrison <phython@gcc.gnu.org>2005-03-04 02:48:30 +0000
committerJames A. Morrison <phython@gcc.gnu.org>2005-03-04 02:48:30 +0000
commit8d06c80914d7374d16887b0e817eadb41d898aa8 (patch)
treec908d67b93dc9a831686bb43afc3806aef6fd260 /gcc
parent3159b178b0479e9c8998982c112f486d5d28ab53 (diff)
downloadgcc-8d06c80914d7374d16887b0e817eadb41d898aa8.zip
gcc-8d06c80914d7374d16887b0e817eadb41d898aa8.tar.gz
gcc-8d06c80914d7374d16887b0e817eadb41d898aa8.tar.bz2
re PR tree-optimization/15784 (fold misses binary optimization)
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 and -1 - A to ~A. From-SVN: r95870
Diffstat (limited to 'gcc')
-rw-r--r--gcc/ChangeLog6
-rw-r--r--gcc/fold-const.c15
-rw-r--r--gcc/testsuite/ChangeLog4
-rw-r--r--gcc/testsuite/gcc.dg/pr15784-4.c12
4 files changed, 37 insertions, 0 deletions
diff --git a/gcc/ChangeLog b/gcc/ChangeLog
index 67c26a2..19b45f2 100644
--- a/gcc/ChangeLog
+++ b/gcc/ChangeLog
@@ -1,3 +1,9 @@
+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
+ and -1 - A to ~A.
+
2005-03-03 David Edelsohn <edelsohn@gnu.org>
* config/rs6000/predicates.md (branch_comparison_operator):
diff --git a/gcc/fold-const.c b/gcc/fold-const.c
index 72e557e..2c6d71e 100644
--- a/gcc/fold-const.c
+++ b/gcc/fold-const.c
@@ -7223,6 +7223,11 @@ fold (tree expr)
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)
{
@@ -7661,6 +7666,16 @@ fold (tree expr)
&& 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/testsuite/ChangeLog b/gcc/testsuite/ChangeLog
index e589f7b..b7a3692 100644
--- a/gcc/testsuite/ChangeLog
+++ b/gcc/testsuite/ChangeLog
@@ -1,3 +1,7 @@
+2005-03-03 James A. Morrison <phython@gcc.gnu.org>
+
+ * gcc.dg/pr15784-4.c: New test.
+
2005-03-03 Geoffrey Keating <geoffk@apple.com>
* gcc.c-torture/execute/pr17133.c: New.
diff --git a/gcc/testsuite/gcc.dg/pr15784-4.c b/gcc/testsuite/gcc.dg/pr15784-4.c
new file mode 100644
index 0000000..021b637
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/pr15784-4.c
@@ -0,0 +1,12 @@
+/* { dg-do compile } */
+/* { dg-options "-O2 -fdump-tree-optimized" } */
+int a (int x) {
+ return ~x + 1; /* -x */
+}
+
+int b (int x) {
+ return -x -1; /* ~x */
+}
+
+/* { dg-final { scan-tree-dump "~x;" "optimized" } } */
+/* { dg-final { scan-tree-dump "-x;" "optimized" } } */