fold-const.c (fold_binary_loc): Move Fold (A & ~B) - (A & B) into (A ^ B) - B to match.pd Move (X & ~Y) | (~X &...
2015-10-23 Richard Biener <rguenther@suse.de> Naveen H.S <Naveen.Hurugalawadi@caviumnetworks.com> * fold-const.c (fold_binary_loc) : Move Fold (A & ~B) - (A & B) into (A ^ B) - B to match.pd Move (X & ~Y) | (~X & Y) is X ^ Y to match.pd. * match.pd (minus (bit_and:cs @0 (bit_not @1)) (bit_and:s @0 @1)): New simplifier. (minus (bit_and:s @0 INTEGER_CST@2) (bit_and:s @0 INTEGER_CST@1)): New simplifier. (minus (bit_and:s @0 @1) (bit_and:cs @0 (bit_not @1))): New simplifier. (bit_ior:c (bit_and:c @0 (bit_not @1)) (bit_and:c (bit_not @0) @1)): New simplifier. (bit_ior:c (bit_and @0 INTEGER_CST@2) (bit_and (bit_not @0) INTEGER_CST@1)): New simplifier. Co-Authored-By: Naveen H.S <Naveen.Hurugalawadi@caviumnetworks.com> From-SVN: r229225
This commit is contained in:
parent
95fef24ff9
commit
1015831766
3 changed files with 41 additions and 44 deletions
|
@ -1,3 +1,21 @@
|
|||
2015-10-23 Richard Biener <rguenther@suse.de>
|
||||
Naveen H.S <Naveen.Hurugalawadi@caviumnetworks.com>
|
||||
|
||||
* fold-const.c (fold_binary_loc) : Move Fold (A & ~B) - (A & B)
|
||||
into (A ^ B) - B to match.pd
|
||||
Move (X & ~Y) | (~X & Y) is X ^ Y to match.pd.
|
||||
|
||||
* match.pd (minus (bit_and:cs @0 (bit_not @1)) (bit_and:s @0 @1)):
|
||||
New simplifier.
|
||||
(minus (bit_and:s @0 INTEGER_CST@2) (bit_and:s @0 INTEGER_CST@1)):
|
||||
New simplifier.
|
||||
(minus (bit_and:s @0 @1) (bit_and:cs @0 (bit_not @1))):
|
||||
New simplifier.
|
||||
(bit_ior:c (bit_and:c @0 (bit_not @1)) (bit_and:c (bit_not @0) @1)):
|
||||
New simplifier.
|
||||
(bit_ior:c (bit_and @0 INTEGER_CST@2) (bit_and (bit_not @0)
|
||||
INTEGER_CST@1)): New simplifier.
|
||||
|
||||
2015-10-23 Richard Sandiford <richard.sandiford@arm.com>
|
||||
|
||||
* builtins.c (integer_valued_real_p): Move to fold-const.c.
|
||||
|
|
|
@ -9649,28 +9649,6 @@ fold_binary_loc (location_t loc,
|
|||
fold_convert_loc (loc, type,
|
||||
TREE_OPERAND (arg0, 0)));
|
||||
|
||||
if (! FLOAT_TYPE_P (type))
|
||||
{
|
||||
/* Fold (A & ~B) - (A & B) into (A ^ B) - B, where B is
|
||||
any power of 2 minus 1. */
|
||||
if (TREE_CODE (arg0) == BIT_AND_EXPR
|
||||
&& TREE_CODE (arg1) == BIT_AND_EXPR
|
||||
&& operand_equal_p (TREE_OPERAND (arg0, 0),
|
||||
TREE_OPERAND (arg1, 0), 0))
|
||||
{
|
||||
tree mask0 = TREE_OPERAND (arg0, 1);
|
||||
tree mask1 = TREE_OPERAND (arg1, 1);
|
||||
tree tem = fold_build1_loc (loc, BIT_NOT_EXPR, type, mask0);
|
||||
|
||||
if (operand_equal_p (tem, mask1, 0))
|
||||
{
|
||||
tem = fold_build2_loc (loc, BIT_XOR_EXPR, type,
|
||||
TREE_OPERAND (arg0, 0), mask1);
|
||||
return fold_build2_loc (loc, MINUS_EXPR, type, tem, mask1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* Fold __complex__ ( x, 0 ) - __complex__ ( 0, y ) to
|
||||
__complex__ ( x, -y ). This is not the same for SNaNs or if
|
||||
signed zeros are involved. */
|
||||
|
@ -9920,28 +9898,6 @@ fold_binary_loc (location_t loc,
|
|||
arg1);
|
||||
}
|
||||
|
||||
/* (X & ~Y) | (~X & Y) is X ^ Y */
|
||||
if (TREE_CODE (arg0) == BIT_AND_EXPR
|
||||
&& TREE_CODE (arg1) == BIT_AND_EXPR)
|
||||
{
|
||||
tree a0, a1, l0, l1, n0, n1;
|
||||
|
||||
a0 = fold_convert_loc (loc, type, TREE_OPERAND (arg1, 0));
|
||||
a1 = fold_convert_loc (loc, type, TREE_OPERAND (arg1, 1));
|
||||
|
||||
l0 = fold_convert_loc (loc, type, TREE_OPERAND (arg0, 0));
|
||||
l1 = fold_convert_loc (loc, type, TREE_OPERAND (arg0, 1));
|
||||
|
||||
n0 = fold_build1_loc (loc, BIT_NOT_EXPR, type, l0);
|
||||
n1 = fold_build1_loc (loc, BIT_NOT_EXPR, type, l1);
|
||||
|
||||
if ((operand_equal_p (n0, a0, 0)
|
||||
&& operand_equal_p (n1, a1, 0))
|
||||
|| (operand_equal_p (n0, a1, 0)
|
||||
&& operand_equal_p (n1, a0, 0)))
|
||||
return fold_build2_loc (loc, BIT_XOR_EXPR, type, l0, n1);
|
||||
}
|
||||
|
||||
/* See if this can be simplified into a rotate first. If that
|
||||
is unsuccessful continue in the association code. */
|
||||
goto bit_rotate;
|
||||
|
|
23
gcc/match.pd
23
gcc/match.pd
|
@ -433,6 +433,29 @@ along with GCC; see the file COPYING3. If not see
|
|||
(bit_and:c (convert? @0) (convert? (bit_not @0)))
|
||||
{ build_zero_cst (type); })
|
||||
|
||||
/* Fold (A & ~B) - (A & B) into (A ^ B) - B. */
|
||||
(simplify
|
||||
(minus (bit_and:cs @0 (bit_not @1)) (bit_and:s @0 @1))
|
||||
(minus (bit_xor @0 @1) @1))
|
||||
(simplify
|
||||
(minus (bit_and:s @0 INTEGER_CST@2) (bit_and:s @0 INTEGER_CST@1))
|
||||
(if (wi::bit_not (@2) == @1)
|
||||
(minus (bit_xor @0 @1) @1)))
|
||||
|
||||
/* Fold (A & B) - (A & ~B) into B - (A ^ B). */
|
||||
(simplify
|
||||
(minus (bit_and:s @0 @1) (bit_and:cs @0 (bit_not @1)))
|
||||
(minus @1 (bit_xor @0 @1)))
|
||||
|
||||
/* Simplify (X & ~Y) | (~X & Y) -> X ^ Y. */
|
||||
(simplify
|
||||
(bit_ior:c (bit_and:c @0 (bit_not @1)) (bit_and:c (bit_not @0) @1))
|
||||
(bit_xor @0 @1))
|
||||
(simplify
|
||||
(bit_ior:c (bit_and @0 INTEGER_CST@2) (bit_and (bit_not @0) INTEGER_CST@1))
|
||||
(if (wi::bit_not (@2) == @1)
|
||||
(bit_xor @0 @1)))
|
||||
|
||||
/* X % Y is smaller than Y. */
|
||||
(for cmp (lt ge)
|
||||
(simplify
|
||||
|
|
Loading…
Add table
Reference in a new issue