Bug 27302 - Fold does not fold (i < j) == (j > i) to 1
Summary: Fold does not fold (i < j) == (j > i) to 1
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: middle-end (show other bugs)
Version: 4.2.0
: P3 enhancement
Target Milestone: 4.2.0
Assignee: Richard Biener
URL:
Keywords: missed-optimization
Depends on:
Blocks:
 
Reported: 2006-04-25 10:27 UTC by Richard Biener
Modified: 2006-05-10 11:03 UTC (History)
1 user (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2006-05-06 13:52:08


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Richard Biener 2006-04-25 10:27:16 UTC
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".
Comment 1 Andrew Pinski 2006-04-25 18:31:38 UTC
Confirmed.
Comment 2 Richard Biener 2006-05-06 13:52:08 UTC
Working on a patch.
Comment 3 Richard Biener 2006-05-10 10:22:49 UTC
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

Comment 4 Richard Biener 2006-05-10 11:03:35 UTC
Fixed.
Comment 5 patchapp@dberlin.org 2006-05-15 19:37:46 UTC
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
Comment 6 Richard Biener 2007-02-06 12:38:47 UTC
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