From: Marek Polacek Date: Tue, 30 Jun 2015 09:02:00 +0000 (+0000) Subject: fold-const.c (fold_binary_loc): Move ~X | X folding ... X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=a4398a300ed00d842f9786d529a7a4b0fce6e634;p=gcc.git 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 --- diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 836b69cb8d6..5f2e14ee42a 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,8 @@ +2015-06-30 Marek Polacek + + * fold-const.c (fold_binary_loc): Move ~X | X folding ... + * match.pd: ... here. + 2015-06-30 Richard Biener * target-insns.def (canonicalize_funcptr_for_compare): Add. diff --git a/gcc/fold-const.c b/gcc/fold-const.c index 5cdb6d1e13d..f330d78904a 100644 --- a/gcc/fold-const.c +++ b/gcc/fold-const.c @@ -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 diff --git a/gcc/match.pd b/gcc/match.pd index 0cf3d218389..5dcbc1a47e0 100644 --- a/gcc/match.pd +++ b/gcc/match.pd @@ -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) diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index f249a7d7ded..b006b4c021b 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,7 @@ +2015-06-30 Marek Polacek + + * gcc.dg/fold-ior-2.c: New test. + 2015-06-30 Tom de Vries PR tree-optimization/66652 diff --git a/gcc/testsuite/gcc.dg/fold-ior-2.c b/gcc/testsuite/gcc.dg/fold-ior-2.c new file mode 100644 index 00000000000..6abac9ee7b6 --- /dev/null +++ b/gcc/testsuite/gcc.dg/fold-ior-2.c @@ -0,0 +1,47 @@ +/* { 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" } } */