Consider:

int
foo (int a)
{
  int b;
  int c;

  b = 0;
  if (b)
    c = a;
  else
    c = 9;

  return c;
}

At the end of CCP, we should see "return 9;".
However, we don't.

Here is the SSA form right before CCP.

foo (a)
{
  int c;
  int b;
  int D.1612;

<bb 0>:
  b_2 = 0;
  if (b_2 != 0) goto <L0>; else goto <L1>;

<L0>:;
  c_7 = a_6;
  goto <bb 3> (<L2>);

<L1>:;
  c_5 = 9;

  # c_1 = PHI <c_7(1), c_5(2)>;
<L2>:;
  c_3 = c_1;
  return c_3;

}

Here is a part of the output from CCP.

Simulating block 3

Visiting statement:
c_3 = c_1;

Lattice value changed to VARYING.  Adding SSA edges to worklist.

Note that c_3 is considered VARYING even though it should have
a constant value of 9.

This is really strange because CCP does not visit block 1 (or <L0>).
So when evaluating the PHI node

  # c_1 = PHI <c_7(1), c_5(2)>;

c_1 should get 9, and CCP does know that c_5 is equal to 9.

-- 
           Summary: CCP is broken
           Product: gcc
           Version: unknown
            Status: UNCONFIRMED
          Keywords: missed-optimization
          Severity: normal
          Priority: P2
         Component: tree-optimization
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: kazu at gcc dot gnu dot org
                CC: gcc-bugs at gcc dot gnu dot org


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

Reply via email to