Consider:

void
foo (int length, int *array)
{
  int i;

  for (i = 0; i < length; i++)
    {
      if (array[i] != 0)
        {
          int j;

          for (j = 0; j < length; j++)
            ;

          if (j != length)
            array[i] = 0;
        }
    }
}

A part of the last tree SSA form looks like so:

<L2>:;
  j_16 = j_15 + 1;
  D.1187_17 = (unsigned int) length_4;
  if (j_16 != D.1187_17) goto <L2>; else goto <L4>;

<L4>:;
  if (length_4 != j_16) goto <L5>; else goto <L6>;

Note that when we take edge from <L2> to <L4>, we know that we leave <L4>
for <L6> because length_4 == D.1187_17 == j_16, but we don't notice that
because a sign-changing cast is in the way.

CSE pickes up this optimization oportunity.

Reduced from reload.c:find_reloads.

-- 
           Summary: Missed jump threading opportunity due to signedness
                    difference
           Product: gcc
           Version: unknown
            Status: UNCONFIRMED
          Keywords: missed-optimization, TREE
          Severity: enhancement
          Priority: P2
         Component: tree-optimization
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: kazu at cs dot umass dot edu
                CC: gcc-bugs at gcc dot gnu dot org
OtherBugsDependingO 19721,19794
             nThis:


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

Reply via email to