[Bug optimization/13521] New: Endless loop in calculate_global_regs_live

jakub at gcc dot gnu dot org gcc-bugzilla@gcc.gnu.org
Tue Dec 30 15:36:00 GMT 2003


Following testcase at -O2 and higher loops forever in calculate_global_regs_live.
extern int f1 (int, void *);
extern int *f2 (void) __attribute__ ((__const__));
extern int f3 (int, void *);

int
test (int x, char *y, int z)
{
  int b = 0;

  if (x < 1024)
    {
      y[0] = '\0';

      do
        {
          switch (f1 (x, y + b))
            {
            case -1:
              if (b == 0)
                return -1;
              else
                return b;

            default:
              b++;
            }
        }
      while (y[b - 1] != '\0' && y[b - 1] != '\n' && b < z);
    }
  else
    {
      do
        {
          switch (f3 (x, y + b))
            {
            case -1:
              if ((*f2 ()) == 4)
                continue;
              if (b == 0)
                return -1;
              else
                return b;

            default:
              b++;
            }
        }
      while (y[b - 1] != '\0' && y[b - 1] != '\n' && b < z);
    }
  return b;
}

The problem seems to be that 1) cse finds out that the -1 constant in both return -1;
statements is already in the pseudo holding return value of f1() resp. f3()
and changes (set (reg:SI X) (const_int -1)) to (set (reg:SI X) (reg:SI Y)) REG_EQUAL (const_int -1).
2) during reload, this pseudo (Y above) is %eax after f1() and %r14d after f3()
(as in the latter case there is another function call in between)
3) during flow2 GCC replaces the pseudo with REG_EQUAL, so it is again:
(set (reg:SI %edx) (const_int -1)) REG_DEAD %r14d REG_EQUAL (const_int -1)
(in the f3() case and then merges both return -1's together).
The problem is REG_DEAD %r14d now, because it is set only in one of the predecessors
of the merged basic block, which causes the endless loop in calculate_global_regs_live
(as it keeps alternating between having %r14 live and not having it live).
Should cfg* not attempt to merge if there are different REG_DEAD notes
or do you have other ideas?

-- 
           Summary: Endless loop in calculate_global_regs_live
           Product: gcc
           Version: 3.3.3
            Status: UNCONFIRMED
          Severity: normal
          Priority: P2
         Component: optimization
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: jakub at gcc dot gnu dot org
                CC: gcc-bugs at gcc dot gnu dot org,jh at suse dot cz,rth at
                    redhat dot com
 GCC build triplet: *-*-*
  GCC host triplet: *-*-*
GCC target triplet: x86_64-redhat-linux


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



More information about the Gcc-bugs mailing list