Commit 015e23f4 by Roger Sayle Committed by Roger Sayle

re PR tree-optimization/13827 ((a & b) != (c & b) should be transformed to ((a^c) & b) !=0)


	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.

From-SVN: r118727
parent c0493b13
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> 2006-11-12 Zdenek Dvorak <dvorakz@suse.cz>
* cfgloopmanip.c (update_single_exit_for_duplicated_loop, * cfgloopmanip.c (update_single_exit_for_duplicated_loop,
......
...@@ -10818,6 +10818,49 @@ fold_binary (enum tree_code code, tree type, tree op0, tree op1) ...@@ -10818,6 +10818,49 @@ fold_binary (enum tree_code code, tree type, tree op0, tree op1)
TREE_OPERAND (arg0, 0), TREE_OPERAND (arg0, 0),
TREE_OPERAND (arg1, 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; return NULL_TREE;
case LT_EXPR: case LT_EXPR:
......
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> 2006-11-11 Andrew Pinski <andrew_pinski@playstation.sony.com>
PR rtl-opt/28812 PR rtl-opt/28812
/* 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" } } */
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment