Hi! I've left these 4 out because I thought they should be fine given that the other operands are equal. But the testcase shows I was wrong.
Fixed thusly, bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk? 2011-03-29 Jakub Jelinek <ja...@redhat.com> PR c/48305 * fold-const.c (fold_binary_loc) <case EQ_EXPR, NE_EXPR>: Make sure arg10/arg11 in (X ^ Y) == (Z ^ W) are always fold converted to matching arg00/arg01 types. * gcc.c-torture/compile/pr48305.c: New test. --- gcc/fold-const.c.jj 2011-03-25 07:56:32.000000000 +0100 +++ gcc/fold-const.c 2011-03-28 12:45:58.000000000 +0200 @@ -12625,13 +12625,21 @@ fold_binary_loc (location_t loc, operand_equal_p guarantees no side-effects so we don't need to use omit_one_operand on Z. */ if (operand_equal_p (arg01, arg11, 0)) - return fold_build2_loc (loc, code, type, arg00, arg10); + return fold_build2_loc (loc, code, type, arg00, + fold_convert_loc (loc, TREE_TYPE (arg00), + arg10)); if (operand_equal_p (arg01, arg10, 0)) - return fold_build2_loc (loc, code, type, arg00, arg11); + return fold_build2_loc (loc, code, type, arg00, + fold_convert_loc (loc, TREE_TYPE (arg00), + arg11)); if (operand_equal_p (arg00, arg11, 0)) - return fold_build2_loc (loc, code, type, arg01, arg10); + return fold_build2_loc (loc, code, type, arg01, + fold_convert_loc (loc, TREE_TYPE (arg01), + arg10)); if (operand_equal_p (arg00, arg10, 0)) - return fold_build2_loc (loc, code, type, arg01, arg11); + return fold_build2_loc (loc, code, type, arg01, + fold_convert_loc (loc, TREE_TYPE (arg01), + arg11)); /* Optimize (X ^ C1) op (Y ^ C2) as (X ^ (C1 ^ C2)) op Y. */ if (TREE_CODE (arg01) == INTEGER_CST --- gcc/testsuite/gcc.c-torture/compile/pr48305.c.jj 2011-03-28 12:48:02.000000000 +0200 +++ gcc/testsuite/gcc.c-torture/compile/pr48305.c 2011-03-28 12:47:49.000000000 +0200 @@ -0,0 +1,7 @@ +/* PR c/48305 */ + +int +foo (int x) +{ + return (x ^ 1) == (x ^ 1U); +} Jakub