diff options
author | Roger Sayle <roger@eyesopen.com> | 2006-10-29 17:51:07 +0000 |
---|---|---|
committer | Roger Sayle <sayle@gcc.gnu.org> | 2006-10-29 17:51:07 +0000 |
commit | f8ed9a1c654104efd3cc124f52a4e14f396b43ad (patch) | |
tree | b49a8dec3cf8d233b45cd54501b107cf1aa58844 | |
parent | 0f8bc3e1736a1b5b8195f0cb968511ca36a17c19 (diff) | |
download | gcc-f8ed9a1c654104efd3cc124f52a4e14f396b43ad.zip gcc-f8ed9a1c654104efd3cc124f52a4e14f396b43ad.tar.gz gcc-f8ed9a1c654104efd3cc124f52a4e14f396b43ad.tar.bz2 |
re PR tree-optimization/15458 (Combine ~ and ^.)
PR tree-optimization/15458
* fold-const.c (fold_binary): Optimize ~X ^ C as X ^ ~C, where C
is a constant.
* gcc.dg/fold-xornot-1.c: New test case.
From-SVN: r118152
-rw-r--r-- | gcc/ChangeLog | 6 | ||||
-rw-r--r-- | gcc/fold-const.c | 7 | ||||
-rw-r--r-- | gcc/testsuite/ChangeLog | 5 | ||||
-rw-r--r-- | gcc/testsuite/gcc.dg/fold-xornot-1.c | 16 |
4 files changed, 34 insertions, 0 deletions
diff --git a/gcc/ChangeLog b/gcc/ChangeLog index c4bd388..fbdec1a 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,9 @@ +2006-10-29 Roger Sayle <roger@eyesopen.com> + + PR tree-optimization/15458 + * fold-const.c (fold_binary): Optimize ~X ^ C as X ^ ~C, where C + is a constant. + 2006-10-29 Richard Guenther <rguenther@suse.de> * config/i386/i386-protos.h (ix86_expand_trunc): Declare. diff --git a/gcc/fold-const.c b/gcc/fold-const.c index 8e3c97a..1c3c752 100644 --- a/gcc/fold-const.c +++ b/gcc/fold-const.c @@ -9506,6 +9506,13 @@ fold_binary (enum tree_code code, tree type, tree op0, tree op1) fold_convert (type, TREE_OPERAND (arg0, 0)), fold_convert (type, TREE_OPERAND (arg1, 0))); + /* Convert ~X ^ C to X ^ ~C. */ + if (TREE_CODE (arg0) == BIT_NOT_EXPR + && TREE_CODE (arg1) == INTEGER_CST) + return fold_build2 (code, type, + fold_convert (type, TREE_OPERAND (arg0, 0)), + fold_build1 (BIT_NOT_EXPR, type, arg1)); + /* Fold (X & 1) ^ 1 as (X & 1) == 0. */ if (TREE_CODE (arg0) == BIT_AND_EXPR && integer_onep (TREE_OPERAND (arg0, 1)) diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 067d97e..de569bb 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2006-10-29 Roger Sayle <roger@eyesopen.com> + + PR tree-optimization/15458 + * gcc.dg/fold-xornot-1.c: New test case. + 2006-10-29 Richard Guenther <rguenther@suse.de> * gcc.target/i386/math-torture/trunc.c: New testcase. diff --git a/gcc/testsuite/gcc.dg/fold-xornot-1.c b/gcc/testsuite/gcc.dg/fold-xornot-1.c new file mode 100644 index 0000000..c92095d --- /dev/null +++ b/gcc/testsuite/gcc.dg/fold-xornot-1.c @@ -0,0 +1,16 @@ +/* { dg-do compile } */ +/* { dg-options "-O2 -fdump-tree-original" } */ + +int foo(int x) +{ + return ~(x ^ 4); +} + +int bar(int y) +{ + return ~y ^ 4; +} + +/* { dg-final { scan-tree-dump-times "x \\^ -5" 1 "original" } } */ +/* { dg-final { scan-tree-dump-times "y \\^ -5" 1 "original" } } */ +/* { dg-final { cleanup-tree-dump "original" } } */ |