For the testcase int foo(int i, int j) { return (i < j) == (j > i); } fold does not fold the expression to 1, but instead to i < j ^ j > i which should be done as a last resort only. fold_comparison does not handle the original tree either, nor does operand_equal_p see that both operands of the EQ_EXPR are "equal".
Confirmed.
Working on a patch.
Subject: Bug 27302 Author: rguenth Date: Wed May 10 10:22:39 2006 New Revision: 113670 URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=113670 Log: 2006-05-10 Richard Guenther <rguenther@suse.de> PR tree-optimization/27302 * fold-const.c (operand_equal_p): For two comparisons, try comparison of one comparison code swapped if that yields the same code. * gcc.dg/torture/pr27302.c: New testcase. Added: trunk/gcc/testsuite/gcc.dg/torture/pr27302.c Modified: trunk/gcc/ChangeLog trunk/gcc/fold-const.c trunk/gcc/testsuite/ChangeLog
Fixed.
Subject: Bug number PR27302 A patch for this bug has been added to the patch tracker. The mailing list url for the patch is http://gcc.gnu.org/ml/gcc-patches/2006-05/msg00344.html
Subject: Bug 27302 Author: rguenth Date: Tue Feb 6 12:38:32 2007 New Revision: 121644 URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=121644 Log: 2007-02-06 Richard Guenther <rguenther@suse.de> PR middle-end/27302 * gcc.dg/torture/pr27302-2.c: New testcase. Added: trunk/gcc/testsuite/gcc.dg/torture/pr27302-2.c Modified: trunk/gcc/testsuite/ChangeLog