Bug 37795 - if-combine doesn't optimize != after >= test
Summary: if-combine doesn't optimize != after >= test
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: tree-optimization (show other bugs)
Version: 4.4.0
: P3 normal
Target Milestone: 4.5.0
Assignee: Richard Biener
URL: http://gcc.gnu.org/ml/gcc-patches/200...
Keywords: missed-optimization
Depends on:
Blocks: 36861
  Show dependency treegraph
 
Reported: 2008-10-10 10:06 UTC by Richard Biener
Modified: 2009-03-28 10:02 UTC (History)
1 user (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2008-10-10 10:07:01


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Richard Biener 2008-10-10 10:06:41 UTC
int foo (int i, int j)
{
  if (i >= j)
    if (i != j)
      return 0;
  return -1;
}

should be optimized to

  if (i > j)
    return 0;
  return -1;
Comment 1 Richard Biener 2008-10-10 10:07:01 UTC
Mine.
Comment 2 Richard Biener 2008-10-12 18:51:58 UTC
Queued for 4.5.
Comment 3 Uroš Bizjak 2008-10-12 20:19:06 UTC
Does this patch also solve PR 28685?
Comment 4 rguenther@suse.de 2008-10-12 20:40:15 UTC
Subject: Re:  if-combine doesn't optimize !=
 after >= test

On Sun, 12 Oct 2008, ubizjak at gmail dot com wrote:

> Does this patch also solve PR 28685?

No.  ifcombine only combines on the CFG, in PR28685 we are dealing
with a CFG-less opportunity.

Richard.
Comment 5 pinskia@gmail.com 2008-10-12 20:47:59 UTC
Subject: Re:  if-combine doesn't optimize != after >= test

On Sun, Oct 12, 2008 at 1:40 PM, rguenther at suse dot de
<gcc-bugzilla@gcc.gnu.org> wrote:
> No.  ifcombine only combines on the CFG, in PR28685 we are dealing
> with a CFG-less opportunity.

Well it depends really.  As on some targets it has a CFG based ||/&&
depending on BRANCH_COST.

Thanks,
Andrew Pinski
Comment 6 rguenther@suse.de 2008-10-12 20:51:28 UTC
Subject: Re:  if-combine doesn't optimize !=
 after >= test

On Sun, 12 Oct 2008, pinskia at gmail dot com wrote:

> ------- Comment #5 from pinskia at gmail dot com  2008-10-12 20:47 -------
> Subject: Re:  if-combine doesn't optimize != after >= test
> 
> On Sun, Oct 12, 2008 at 1:40 PM, rguenther at suse dot de
> <gcc-bugzilla@gcc.gnu.org> wrote:
> > No.  ifcombine only combines on the CFG, in PR28685 we are dealing
> > with a CFG-less opportunity.
> 
> Well it depends really.  As on some targets it has a CFG based ||/&&
> depending on BRANCH_COST.

In that case we already optimize it.

Richard.
Comment 7 Richard Biener 2009-03-28 10:02:12 UTC
Subject: Bug 37795

Author: rguenth
Date: Sat Mar 28 10:01:56 2009
New Revision: 145170

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=145170
Log:
2009-03-28  Richard Guenther  <rguenther@suse.de>

	PR tree-optimization/37795
	* tree.h (combine_comparisons): Declare.
	* fold-const.c (combine_comparisons): Export.
	* tree-ssa-ifcombine.c (ifcombine_ifandif): Optimize two successive
	comparisons.
	(ifcombine_iforif): Use combine_comparisons.

	* gcc.dg/tree-ssa/ssa-ifcombine-7.c: New testcase.

Added:
    trunk/gcc/testsuite/gcc.dg/tree-ssa/ssa-ifcombine-7.c
Modified:
    trunk/gcc/ChangeLog
    trunk/gcc/fold-const.c
    trunk/gcc/testsuite/ChangeLog
    trunk/gcc/tree-ssa-ifcombine.c
    trunk/gcc/tree.h

Comment 8 Richard Biener 2009-03-28 10:02:53 UTC
Fixed.