re PR tree-optimization/19055 (Minor bit optimization with or and xor)

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 middle-end/19055
        * fold-const.c (fold_binary): Transform "(X | Y) ^ X" to "Y & ~ X".

From-SVN: r102243
This commit is contained in:
Andrew Pinski 2005-07-21 19:33:45 +00:00 committed by Andrew Pinski
parent 35f5a23f7b
commit 9d24eb542c
3 changed files with 59 additions and 0 deletions

View File

@ -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,

View File

@ -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)

View File

@ -1,3 +1,9 @@
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