diff options
-rw-r--r-- | gcc/ChangeLog | 5 | ||||
-rw-r--r-- | gcc/fold-const.c | 48 | ||||
-rw-r--r-- | gcc/testsuite/ChangeLog | 6 |
3 files changed, 59 insertions, 0 deletions
diff --git a/gcc/ChangeLog b/gcc/ChangeLog index be6747137c8..a8f5b466e60 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,8 @@ +2005-07-21 Andrew Pinski <pinskia@physics.uc.edu> + + PR middle-end/19055 + * fold-const.c (fold_binary): Transform "(X | Y) ^ X" to "Y & ~ X". + 2005-07-21 Paolo Bonzini <bonzini@gnu.org> * common.opt (-fforward-propagate): Committed by mistake, diff --git a/gcc/fold-const.c b/gcc/fold-const.c index 7b83eb3ef5f..acafd6a4655 100644 --- a/gcc/fold-const.c +++ b/gcc/fold-const.c @@ -8059,6 +8059,54 @@ fold_binary (enum tree_code code, tree type, tree op0, tree op1) goto bit_ior; } + /* (X | Y) ^ X -> Y & ~ X*/ + if (TREE_CODE (arg0) == BIT_IOR_EXPR + && operand_equal_p (TREE_OPERAND (arg0, 0), arg1, 0)) + { + tree t2 = TREE_OPERAND (arg0, 1); + t1 = fold_build1 (BIT_NOT_EXPR, TREE_TYPE (arg1), + arg1); + t1 = fold_build2 (BIT_AND_EXPR, type, fold_convert (type, t2), + fold_convert (type, t1)); + return t1; + } + + /* (Y | X) ^ X -> Y & ~ X*/ + if (TREE_CODE (arg0) == BIT_IOR_EXPR + && operand_equal_p (TREE_OPERAND (arg0, 1), arg1, 0)) + { + tree t2 = TREE_OPERAND (arg0, 0); + t1 = fold_build1 (BIT_NOT_EXPR, TREE_TYPE (arg1), + arg1); + t1 = fold_build2 (BIT_AND_EXPR, type, fold_convert (type, t2), + fold_convert (type, t1)); + return t1; + } + + /* X ^ (X | Y) -> Y & ~ X*/ + if (TREE_CODE (arg1) == BIT_IOR_EXPR + && operand_equal_p (TREE_OPERAND (arg1, 0), arg0, 0)) + { + tree t2 = TREE_OPERAND (arg1, 1); + t1 = fold_build1 (BIT_NOT_EXPR, TREE_TYPE (arg0), + arg0); + t1 = fold_build2 (BIT_AND_EXPR, type, fold_convert (type, t2), + fold_convert (type, t1)); + return t1; + } + + /* X ^ (Y | X) -> Y & ~ X*/ + if (TREE_CODE (arg1) == BIT_IOR_EXPR + && operand_equal_p (TREE_OPERAND (arg1, 1), arg0, 0)) + { + tree t2 = TREE_OPERAND (arg1, 0); + t1 = fold_build1 (BIT_NOT_EXPR, TREE_TYPE (arg0), + arg0); + t1 = fold_build2 (BIT_AND_EXPR, type, fold_convert (type, t2), + fold_convert (type, t1)); + return t1; + } + /* Convert ~X ^ ~Y to X ^ Y. */ if (TREE_CODE (arg0) == BIT_NOT_EXPR && TREE_CODE (arg1) == BIT_NOT_EXPR) diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 04dfb01cf4c..f5497d16830 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,5 +1,11 @@ 2005-07-21 Andrew Pinski <pinskia@physics.uc.edu> + PR middle-end/19055 + * gcc.dg/tree-ssa/pr19055.c: New test. + * gcc.dg/tree-ssa/pr19055-2.c: New test. + +2005-07-21 Andrew Pinski <pinskia@physics.uc.edu> + PR C++/22358 * g++.dg/other/pr22358.C: New test. |