diff options
author | sayle <sayle@138bc75d-0d04-0410-961f-82ee72b054a4> | 2006-11-12 18:41:31 +0000 |
---|---|---|
committer | sayle <sayle@138bc75d-0d04-0410-961f-82ee72b054a4> | 2006-11-12 18:41:31 +0000 |
commit | 32484276f69da1dec8600428f6c9eb387aa06a2d (patch) | |
tree | b02ba3cb889c222125601c7fa415210e5d22fcf6 | |
parent | 56743459ef01d1123da77ce237b73dfbfd49badd (diff) | |
download | gcc-32484276f69da1dec8600428f6c9eb387aa06a2d.tar.gz |
PR tree-optimization/13827
* fold-const.c (fold_binary) <EQ_EXPR, NE_EXPR>: Fold (X&C) op (Y&C)
as ((X^Y)&C) op 0.
* gcc.dg/fold-eqand-1.c: New test case.
git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@118727 138bc75d-0d04-0410-961f-82ee72b054a4
-rw-r--r-- | gcc/ChangeLog | 6 | ||||
-rw-r--r-- | gcc/fold-const.c | 43 | ||||
-rw-r--r-- | gcc/testsuite/ChangeLog | 5 | ||||
-rw-r--r-- | gcc/testsuite/gcc.dg/fold-eqand-1.c | 17 |
4 files changed, 71 insertions, 0 deletions
diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 081c6cfde3a..e1a2a6553ca 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,9 @@ +2006-11-12 Roger Sayle <roger@eyesopen.com> + + PR tree-optimization/13827 + * fold-const.c (fold_binary) <EQ_EXPR, NE_EXPR>: Fold (X&C) op (Y&C) + as ((X^Y)&C) op 0. + 2006-11-12 Zdenek Dvorak <dvorakz@suse.cz> * cfgloopmanip.c (update_single_exit_for_duplicated_loop, diff --git a/gcc/fold-const.c b/gcc/fold-const.c index 08e74a292f9..cf1df69c468 100644 --- a/gcc/fold-const.c +++ b/gcc/fold-const.c @@ -10818,6 +10818,49 @@ fold_binary (enum tree_code code, tree type, tree op0, tree op1) TREE_OPERAND (arg0, 0), TREE_OPERAND (arg1, 0)); + /* Fold (X & C) op (Y & C) as (X ^ Y) & C op 0", and symmetries. */ + if (TREE_CODE (arg0) == BIT_AND_EXPR + && TREE_CODE (arg1) == BIT_AND_EXPR) + { + tree arg00 = TREE_OPERAND (arg0, 0); + tree arg01 = TREE_OPERAND (arg0, 1); + tree arg10 = TREE_OPERAND (arg1, 0); + tree arg11 = TREE_OPERAND (arg1, 1); + tree itype = TREE_TYPE (arg0); + + if (operand_equal_p (arg01, arg11, 0)) + return fold_build2 (code, type, + fold_build2 (BIT_AND_EXPR, itype, + fold_build2 (BIT_XOR_EXPR, itype, + arg00, arg10), + arg01), + build_int_cst (itype, 0)); + + if (operand_equal_p (arg01, arg10, 0)) + return fold_build2 (code, type, + fold_build2 (BIT_AND_EXPR, itype, + fold_build2 (BIT_XOR_EXPR, itype, + arg00, arg11), + arg01), + build_int_cst (itype, 0)); + + if (operand_equal_p (arg00, arg11, 0)) + return fold_build2 (code, type, + fold_build2 (BIT_AND_EXPR, itype, + fold_build2 (BIT_XOR_EXPR, itype, + arg01, arg10), + arg00), + build_int_cst (itype, 0)); + + if (operand_equal_p (arg00, arg10, 0)) + return fold_build2 (code, type, + fold_build2 (BIT_AND_EXPR, itype, + fold_build2 (BIT_XOR_EXPR, itype, + arg01, arg11), + arg00), + build_int_cst (itype, 0)); + } + return NULL_TREE; case LT_EXPR: diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index c8bd6d4ef9b..5a2b502b967 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2006-11-12 Roger Sayle <roger@eyesopen.com> + + PR tree-optimization/13827 + * gcc.dg/fold-eqand-1.c: New test case. + 2006-11-11 Andrew Pinski <andrew_pinski@playstation.sony.com> PR rtl-opt/28812 diff --git a/gcc/testsuite/gcc.dg/fold-eqand-1.c b/gcc/testsuite/gcc.dg/fold-eqand-1.c new file mode 100644 index 00000000000..6ed5b6db0e2 --- /dev/null +++ b/gcc/testsuite/gcc.dg/fold-eqand-1.c @@ -0,0 +1,17 @@ +/* PR tree-optimization/13827 */ +/* { dg-do compile } */ +/* { dg-options "-O2 -fdump-tree-original" } */ + +unsigned foo (unsigned a, unsigned b) +{ + return (a & 0xff00) != (b & 0xff00); +} + +unsigned bar (unsigned c, unsigned d) +{ + return (c & 0xff00) == (d & 0xff00); +} + +/* { dg-final { scan-tree-dump-times "a \\^ b" 1 "original" } } */ +/* { dg-final { scan-tree-dump-times "c \\^ d" 1 "original" } } */ +/* { dg-final { cleanup-tree-dump "original" } } */ |