diff options
author | Marek Polacek <polacek@redhat.com> | 2015-06-30 09:02:00 +0000 |
---|---|---|
committer | Marek Polacek <mpolacek@gcc.gnu.org> | 2015-06-30 09:02:00 +0000 |
commit | a4398a300ed00d842f9786d529a7a4b0fce6e634 (patch) | |
tree | 58346bd90053e6a614e0e37ed3fed21fc9b01ece /gcc | |
parent | 582554e3bc1509b6ddc407004f97e3f756bcedf5 (diff) | |
download | gcc-a4398a300ed00d842f9786d529a7a4b0fce6e634.zip gcc-a4398a300ed00d842f9786d529a7a4b0fce6e634.tar.gz gcc-a4398a300ed00d842f9786d529a7a4b0fce6e634.tar.bz2 |
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
Diffstat (limited to 'gcc')
-rw-r--r-- | gcc/ChangeLog | 5 | ||||
-rw-r--r-- | gcc/fold-const.c | 18 | ||||
-rw-r--r-- | gcc/match.pd | 6 | ||||
-rw-r--r-- | gcc/testsuite/ChangeLog | 4 | ||||
-rw-r--r-- | gcc/testsuite/gcc.dg/fold-ior-2.c | 47 |
5 files changed, 62 insertions, 18 deletions
diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 836b69c..5f2e14e 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,8 @@ +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. diff --git a/gcc/fold-const.c b/gcc/fold-const.c index 5cdb6d1..f330d78 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 0cf3d21..5dcbc1a 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 f249a7d..b006b4c 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,7 @@ +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 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 0000000..6abac9e --- /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" } } */ |