Bug 13521 - [3.3 only] Endless loop in calculate_global_regs_live
[3.3 only] Endless loop in calculate_global_regs_live
Status: RESOLVED FIXED
Product: gcc
Classification: Unclassified
Component: rtl-optimization
3.3.3
: P2 normal
: 3.3.3
Assigned To: Not yet assigned to anyone
: ice-on-valid-code, patch
Depends on:
Blocks:
  Show dependency treegraph
 
Reported: 2003-12-30 13:27 UTC by Jakub Jelinek
Modified: 2004-03-03 12:54 UTC (History)
5 users (show)

See Also:
Host: *-*-*
Target: x86_64-redhat-linux
Build: *-*-*
Known to work:
Known to fail:
Last reconfirmed: 2003-12-31 16:06:09


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Jakub Jelinek 2003-12-30 13:27:56 UTC
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?
Comment 1 Andrew Pinski 2003-12-30 19:38:03 UTC
It does not happen on the mainline though.  I do not think this will ever be fixed for 3.3.3 though.
Comment 2 Eric Botcazou 2003-12-30 19:43:41 UTC
For another example of endless loop in c_g_r_l see PR opt/12158.
Comment 3 Jakub Jelinek 2003-12-31 11:59:28 UTC
Fixed on mainline with:
http://gcc.gnu.org/ml/gcc-patches/2003-04/msg01324.html
Will post to gcc-patches.
Comment 4 Andrew Pinski 2003-12-31 16:06:08 UTC
Patch here: <http://gcc.gnu.org/ml/gcc-patches/2003-12/msg02314.html>.
Comment 5 CVS Commits 2004-01-01 13:19:46 UTC
Subject: Bug 13521

CVSROOT:	/cvs/gcc
Module name:	gcc
Branch: 	gcc-3_3-branch
Changes by:	jakub@gcc.gnu.org	2004-01-01 13:19:41

Modified files:
	gcc            : ChangeLog cfgcleanup.c 
	gcc/testsuite  : ChangeLog 
Added files:
	gcc/testsuite/gcc.c-torture/compile: 20031231-1.c 

Log message:
	PR optimization/13521
	Backport from mainline:
	2003-03-22  Richard Henderson <rth@redhat.com>
	
	* cfgcleanup.c (insns_match_p): Do not do EQUIV substitution
	after reload.
	
	* gcc.c-torture/compile/20031231-1.c: New test.

Patches:
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/ChangeLog.diff?cvsroot=gcc&only_with_tag=gcc-3_3-branch&r1=1.16114.2.865&r2=1.16114.2.866
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cfgcleanup.c.diff?cvsroot=gcc&only_with_tag=gcc-3_3-branch&r1=1.68.2.8&r2=1.68.2.9
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/ChangeLog.diff?cvsroot=gcc&only_with_tag=gcc-3_3-branch&r1=1.2261.2.349&r2=1.2261.2.350
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/gcc.c-torture/compile/20031231-1.c.diff?cvsroot=gcc&only_with_tag=gcc-3_3-branch&r1=NONE&r2=1.1.2.1

Comment 6 CVS Commits 2004-01-01 13:21:20 UTC
Subject: Bug 13521

CVSROOT:	/cvs/gcc
Module name:	gcc
Changes by:	jakub@gcc.gnu.org	2004-01-01 13:21:18

Modified files:
	gcc/testsuite  : ChangeLog 
Added files:
	gcc/testsuite/gcc.c-torture/compile: 20031231-1.c 

Log message:
	PR optimization/13521
	* gcc.c-torture/compile/20031231-1.c: New test.

Patches:
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/ChangeLog.diff?cvsroot=gcc&r1=1.3327&r2=1.3328
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/gcc.c-torture/compile/20031231-1.c.diff?cvsroot=gcc&r1=1.1&r2=1.2

Comment 7 Andrew Pinski 2004-01-01 15:32:05 UTC
Fixed for 3.3.3 and already for 3.4.
Comment 8 Eric Botcazou 2004-03-03 12:54:13 UTC
*** Bug 14335 has been marked as a duplicate of this bug. ***