Commit a4398a30 by Marek Polacek Committed by Marek Polacek

fold-const.c (fold_binary_loc): Move ~X | X folding ...

	* fold-const.c (fold_binary_loc): Move ~X | X folding ...
	* match.pd: ... here.

	* gcc.dg/fold-ior-2.c: New test.

From-SVN: r225164
parent 582554e3
2015-06-30 Marek Polacek <polacek@redhat.com>
* fold-const.c (fold_binary_loc): Move ~X | X folding ...
* match.pd: ... here.
2015-06-30 Richard Biener <rguenther@suse.de>
* target-insns.def (canonicalize_funcptr_for_compare): Add.
......
......@@ -10922,24 +10922,6 @@ fold_binary_loc (location_t loc,
case BIT_IOR_EXPR:
bit_ior:
/* ~X | X is -1. */
if (TREE_CODE (arg0) == BIT_NOT_EXPR
&& operand_equal_p (TREE_OPERAND (arg0, 0), arg1, 0))
{
t1 = build_zero_cst (type);
t1 = fold_unary_loc (loc, BIT_NOT_EXPR, type, t1);
return omit_one_operand_loc (loc, type, t1, arg1);
}
/* X | ~X is -1. */
if (TREE_CODE (arg1) == BIT_NOT_EXPR
&& operand_equal_p (arg0, TREE_OPERAND (arg1, 0), 0))
{
t1 = build_zero_cst (type);
t1 = fold_unary_loc (loc, BIT_NOT_EXPR, type, t1);
return omit_one_operand_loc (loc, type, t1, arg0);
}
/* Canonicalize (X & C1) | C2. */
if (TREE_CODE (arg0) == BIT_AND_EXPR
&& TREE_CODE (arg1) == INTEGER_CST
......
......@@ -283,6 +283,12 @@ along with GCC; see the file COPYING3. If not see
(bit_and @0 integer_zerop@1)
@1)
/* ~x | x -> -1 */
(simplify
(bit_ior:c (convert? @0) (convert? (bit_not @0)))
(if (tree_nop_conversion_p (type, TREE_TYPE (@0)))
{ build_all_ones_cst (type); }))
/* x ^ x -> 0 */
(simplify
(bit_xor @0 @0)
......
2015-06-30 Marek Polacek <polacek@redhat.com>
* gcc.dg/fold-ior-2.c: New test.
2015-06-30 Tom de Vries <tom@codesourcery.com>
PR tree-optimization/66652
......
/* { dg-do compile } */
/* { dg-options "-O -fdump-tree-cddce1" } */
int
fn1 (int x)
{
return ~x | x;
}
int
fn2 (int x)
{
return x | ~x;
}
unsigned int
fn3 (unsigned int x)
{
return ~x | x;
}
unsigned int
fn4 (unsigned int x)
{
return ~x | x;
}
int
fn5 (int x)
{
return ~x | (unsigned) x;
}
int
fn6 (int x)
{
return (unsigned) ~x | x;
}
int
fn7 (int x)
{
return ~(unsigned) x | x;
}
/* { dg-final { scan-tree-dump-not "~" "cddce1" } } */
/* { dg-final { scan-tree-dump-not " \\| " "cddce1" } } */
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