Bug 26899 - Fold does not fold (i0 > i1 + 1) || (i1 < i0 - 1)
Summary: Fold does not fold (i0 > i1 + 1) || (i1 < i0 - 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: 26900
  Show dependency treegraph
 
Reported: 2006-03-28 14:11 UTC by Richard Biener
Modified: 2007-01-10 19:23 UTC (History)
2 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2006-10-24 15:07:37


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Richard Biener 2006-03-28 14:11:09 UTC
Fold currently does not fold a lot of TRUTH_AND/OR_EXPRs created by tree-ssa-loop-niter.c:tree_simplify_using_condition_1.  Like for the testcase

int foo0(int i0, int i1)
{
  int i, j = 0;
  for (i=i0; i<=i1+1; ++i)
    ++j;
  return j;
}

with PR26898 fixed.  We there get

  i0D.1520_4 > i1D.1521_6 + 1  ||  i1D.1521_6 < i0D.1520_4 - 1

(which is false) and

  i0D.1520_4 <= i1D.1521_6 + 1  &&  i1D.1521_6 < i0D.1520_4 - 1

(which is also false and would make us figure out # iterations for the loop).
Comment 1 Richard Biener 2006-10-24 15:07:37 UTC
Actually folding (i0 > i1 + 1) || (i1 < i0 - 1) is not possible, but I have a
patch that is able to fold (i0 < i1 + 1) || (i1 > i0 - 1) to i1 >= i0.

The original one is not possible due to overflow issues.
Comment 2 Richard Biener 2006-10-28 18:03:33 UTC
Subject: Bug 26899

Author: rguenth
Date: Sat Oct 28 18:03:21 2006
New Revision: 118106

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

	PR middle-end/26899
	* fold-const.c (maybe_canonicalize_comparison_1): Helper
	for maybe_canonicalize_comparison.
	(maybe_canonicalize_comparison): New function for canonicalizing
	comparison trees.
	(fold_comparison): Call it to canonicalize comparisons with
	constants involved.

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

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

Comment 3 Richard Biener 2006-10-28 18:04:03 UTC
Fixed what is possible to fix.