extern void link_error ();
void foo (int a)
{
  if (a < 0)
    {
      int y;
      a = -a;
      y  = a / 7;
      if (y > 1 << 30)
        link_error ();
    }
}

int main()
{
  return 0;
}

Before the VRP overflow handling changes we have after the first VRP pass:

Value ranges after VRP:

a_1(D): VARYING
a_2: [1, +INF]  EQUIVALENCES: { } (0 elements)
y_3: [0, 306783378]  EQUIVALENCES: { } (0 elements)
a_4: [-INF, -1]  EQUIVALENCES: { a_1(D) } (1 elements)

Substituing values and folding statements

Folding predicate y_3 > 1073741824 to 0
Folded statement: if (y_3 > 1073741824) goto <L1>; else goto <L2>;
            into: if (0) goto <L1>; else goto <L2>;

void foo(int) (a)
{
  int y;

<bb 2>:
  if (a_1(D) < 0) goto <L0>; else goto <L2>;

<L0>:;
  a_2 = -a_1(D);
  y_3 = a_2 / 7;

<L2>:;
  return;

}


while now we get

Value ranges after VRP:

a_1(D): VARYING
a_2: [1, +INF(OVF)]  EQUIVALENCES: { } (0 elements)
y_3: [0, +INF(OVF)]  EQUIVALENCES: { } (0 elements)
a_4: [-INF, -1]  EQUIVALENCES: { a_1(D) } (1 elements)

Substituing values and folding statements

foo (a)
{
  int y;

<bb 2>:
  if (a_1(D) < 0) goto <L0>; else goto <L2>;

<L0>:;
  a_2 = -a_1(D);
  y_3 = a_2 / 7;
  if (y_3 > 1073741824) goto <L1>; else goto <L2>;

<L1>:;
  link_error ();

<L2>:;
  return;

}


without -Wstrict-overflow=N warning about the issues with signed negation
and the [1, +INF(OVF)] derived range.  Note that the testcase is simple
enough that expansion optimizes the comparison, so it will not fail to link.


-- 
           Summary: [4.3 Regression] VRP no longer derives range for
                    division after negation
           Product: gcc
           Version: 4.3.0
            Status: UNCONFIRMED
          Keywords: missed-optimization
          Severity: normal
          Priority: P3
         Component: tree-optimization
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: rguenth at gcc dot gnu dot org


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=31130

Reply via email to