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?
It does not happen on the mainline though. I do not think this will ever be fixed for 3.3.3 though.
For another example of endless loop in c_g_r_l see PR opt/12158.
Fixed on mainline with: http://gcc.gnu.org/ml/gcc-patches/2003-04/msg01324.html Will post to gcc-patches.
Patch here: <http://gcc.gnu.org/ml/gcc-patches/2003-12/msg02314.html>.
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
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
Fixed for 3.3.3 and already for 3.4.
*** Bug 14335 has been marked as a duplicate of this bug. ***