Bug 29715 - fold produces &a - 4
Summary: fold produces &a - 4
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: middle-end (show other bugs)
Version: 4.3.0
: P3 normal
Target Milestone: 4.3.0
Assignee: Andrew Pinski
URL: http://gcc.gnu.org/ml/gcc-patches/200...
Keywords: patch
Depends on:
Blocks:
 
Reported: 2006-11-04 21:30 UTC by Andrew Pinski
Modified: 2007-05-02 18:49 UTC (History)
3 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2007-02-27 06:55:50


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Andrew Pinski 2006-11-04 21:30:36 UTC
Take this valid testcase:
int main ()
{
  static int a[] = { 0, 1, 2 };
  int *i = a+3;
  if (i-- > a)
    return 0;
  return 0;
}

In the IR (in .orginal) we get:
  if ( --i > &a - 4B)

which is incorrect and not really defined.
Comment 1 Andrew Pinski 2006-11-04 21:34:23 UTC
Note: I found this while implementing PTR_PLUS_EXPR but that is because I did not fix the part which does this optimization.
Comment 2 Andrew Pinski 2007-02-27 06:55:50 UTC
The comment from the code:
For pointer types we assume overflow doesn't happen. 


That is true but you can cause an overflow to happen when you transform the code this way.

Mine, I have a fix.
Comment 3 Andrew Pinski 2007-02-27 07:01:04 UTC
Before we would produce:
  i = &a + 12B;
  i = i - 4B;
  D.1616 = &a - 4B;
  if (i > D.1616)


Now we produce:
  i = &a + 12B;
  D.1620 = i > &a;
  i = i - 4B;
  if (D.1620)

Which is better because we can actually fold it down to return 0.
Comment 4 Andrew Pinski 2007-05-02 18:48:05 UTC
Subject: Bug 29715

Author: pinskia
Date: Wed May  2 17:47:50 2007
New Revision: 124354

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=124354
Log:
Forgot to add the PR number to the last changelog entry:
2007-05-02  Andrew Pinski  <andrew_pinski@playstation.sony.com>

        PR middle-end/29715
        * fold-const.c (fold_comparision): Remove the "foo++ == CONST"
        transformation.


Modified:
    trunk/gcc/ChangeLog

Comment 5 Andrew Pinski 2007-05-02 18:49:01 UTC
Fixed.