As discussed here: <https://gcc.gnu.org/ml/gcc-patches/2015-06/msg02223.html>.
Bootstrapped/regtested on x86_64-linux, applying to trunk. 2015-06-30 Marek Polacek <pola...@redhat.com> * match.pd (~x | x): Don't use tree_nop_conversion_p. Build the final expression with the operand's type and then convert it to the type of the expression. * gcc.dg/fold-ior-3.c: New test. diff --git gcc/match.pd gcc/match.pd index 682784b..adb7a52 100644 --- gcc/match.pd +++ gcc/match.pd @@ -286,8 +286,7 @@ along with GCC; see the file COPYING3. If not see /* ~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); })) + (convert { build_all_ones_cst (TREE_TYPE (@0)); })) /* x ^ x -> 0 */ (simplify diff --git gcc/testsuite/gcc.dg/fold-ior-3.c gcc/testsuite/gcc.dg/fold-ior-3.c index e69de29..ed89ff9 100644 --- gcc/testsuite/gcc.dg/fold-ior-3.c +++ gcc/testsuite/gcc.dg/fold-ior-3.c @@ -0,0 +1,35 @@ +/* { dg-do compile } */ +/* { dg-options "-O -fdump-tree-cddce1" } */ + +int +fn1 (_Bool a) +{ + return ((int) a) | ((int) ~a); +} + +int +fn2 (unsigned char a) +{ + return ((int) a) | ((int) ~a); +} + +int +fn3 (unsigned short a) +{ + return ((int) a) | ((int) ~a); +} + +int +fn4 (signed char a) +{ + return ((int) a) | ((int) ~a); +} + +int +fn5 (signed short a) +{ + return ((int) a) | ((int) ~a); +} + +/* { dg-final { scan-tree-dump-not "~" "cddce1" } } */ +/* { dg-final { scan-tree-dump-not " \\| " "cddce1" } } */ Marek