Bug 51042 - [4.5 Regression] endless recursion in phi_translate
Summary: [4.5 Regression] endless recursion in phi_translate
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: tree-optimization (show other bugs)
Version: 4.7.0
: P2 normal
Target Milestone: 4.6.3
Assignee: Richard Biener
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2011-11-08 22:45 UTC by John Regehr
Modified: 2019-06-15 00:18 UTC (History)
2 users (show)

See Also:
Host:
Target:
Build:
Known to work: 4.4.6, 4.6.3, 4.7.0
Known to fail:
Last reconfirmed: 2011-11-09 00:00:00


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description John Regehr 2011-11-08 22:45:17 UTC
Valgrind wasn't too helpful in narrowing this down, just says something generic about a stack overflow.

[regehr@gamow tmp052]$ current-gcc -Ofast -w small.c

current-gcc: internal compiler error: Segmentation fault (program cc1)
Please submit a full bug report,
with preprocessed source if appropriate.
See <http://gcc.gnu.org/bugs.html> for instructions.

[regehr@gamow tmp052]$ current-gcc -v

Using built-in specs.
COLLECT_GCC=current-gcc
COLLECT_LTO_WRAPPER=/uusoc/exports/scratch/regehr/z/compiler-install/gcc-r181147-install/bin/../libexec/gcc/x86_64-unknown-linux-gnu/4.7.0/lto-wrapper
Target: x86_64-unknown-linux-gnu
Configured with: ../configure --with-libelf=/usr/local --enable-lto --prefix=/home/regehr/z/compiler-install/gcc-r181147-install --program-prefix=r181147- --enable-languages=c,c++
Thread model: posix
gcc version 4.7.0 20111108 (experimental) (GCC) 

[regehr@gamow tmp052]$ cat small.c 


int g_10;
int g_97;
int g_144;
int g_237;
int g_264[2][2];

int func_22 (p_25)
{
  for (; p_25;)
    {
      for (g_237 = 0; g_237 <= 1; g_237 = 1)
	if (g_264[g_144][g_10])
	  break;
      for (g_97 = 0; g_97 <= 0; g_97 = 1)
	{
	  g_264[g_144][g_10] = g_10;
	  if (g_10)
	    break;
	}
    }
  return 0;
}
Comment 1 Jakub Jelinek 2011-11-09 08:59:47 UTC
Caused by http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=155360

int a, b, c, d, e[2][2];

void
foo (int x)
{
  while (x)
    {
      for (d = 0; d <= 1; d = 1)
        if (e[c][a])
          break;
      for (b = 0; b <= 0; b = 1)
        {
          e[c][a] = a;
          if (a)
            break;
        }
    }
}
Comment 2 Richard Biener 2011-11-09 09:22:04 UTC
Mine.
Comment 3 Richard Biener 2011-11-09 13:23:00 UTC
Even shorter testcase:

int a, b;

void
foo (int x)
{
  int e[2];
  int d; 
  while (x)
    {
      for (d = 0; d <= 1; d = 1)
        if (e[a])
          break;
      for (b = 0; b <= 0; b = 1)
        {
          e[a] = a;
          if (a)
            break;
        }
    }
}
Comment 4 Richard Biener 2011-11-09 14:33:14 UTC
The clean () code does not work properly for memory references it seems.  We
fail to prune expressions that are not available (the tricks we play with
dominance tests for virtual operands are not effective once we translate
them).
Comment 5 Richard Biener 2011-11-10 12:50:51 UTC
Of course in principle the issue is that an SSA name can have an expression
leader that references the SSA name itself.
Comment 6 Richard Biener 2011-11-10 15:29:01 UTC
Author: rguenth
Date: Thu Nov 10 15:28:57 2011
New Revision: 181256

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=181256
Log:
2011-11-10  Richard Guenther  <rguenther@suse.de>

	PR tree-optimization/51042
	* tree-ssa-pre.c (phi_translate_1): Avoid recursing on
	self-referential expressions.  Refactor code to avoid duplication.

	* gcc.dg/torture/pr51042.c: New testcase.

Added:
    trunk/gcc/testsuite/gcc.dg/torture/pr51042.c
Modified:
    trunk/gcc/ChangeLog
    trunk/gcc/testsuite/ChangeLog
    trunk/gcc/tree-ssa-pre.c
Comment 7 Richard Biener 2011-11-10 15:29:39 UTC
Fixed on trunk sofar.
Comment 8 Richard Biener 2012-01-03 14:46:08 UTC
Author: rguenth
Date: Tue Jan  3 14:46:03 2012
New Revision: 182848

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=182848
Log:
2012-01-03  Richard Guenther  <rguenther@suse.de>

	Backport from mainline
	2011-11-10  Richard Guenther  <rguenther@suse.de>

	PR tree-optimization/51042
	* tree-ssa-pre.c (phi_translate_1): Avoid recursing on
	self-referential expressions.  Refactor code to avoid duplication.

	* gcc.dg/torture/pr51042.c: New testcase.

Added:
    branches/gcc-4_6-branch/gcc/testsuite/gcc.dg/torture/pr51042.c
Modified:
    branches/gcc-4_6-branch/gcc/ChangeLog
    branches/gcc-4_6-branch/gcc/testsuite/ChangeLog
    branches/gcc-4_6-branch/gcc/tree-ssa-pre.c
Comment 9 Jiangning Liu 2012-06-12 09:53:57 UTC
Author: liujiangning
Date: Tue Jun 12 09:53:53 2012
New Revision: 188433

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=188433
Log:
2011-06-12  Jiangning Liu  <jiangning.liu@arm.com>                                                        

	Backport r181256 from mainline
	2011-11-10  Richard Guenther  <rguenther@suse.de>

	PR tree-optimization/51042
	* tree-ssa-pre.c (phi_translate_1): Avoid recursing on
	self-referential expressions.  Refactor code to avoid duplication.

2011-06-12  Jiangning Liu  <jiangning.liu@arm.com>                                                        

	Backport r181256 from mainline
	2011-11-10  Richard Guenther  <rguenther@suse.de>


Added:
    branches/ARM/embedded-4_6-branch/gcc/testsuite/gcc.dg/torture/pr51042.c
Modified:
    branches/ARM/embedded-4_6-branch/gcc/ChangeLog.arm
    branches/ARM/embedded-4_6-branch/gcc/testsuite/ChangeLog.arm
    branches/ARM/embedded-4_6-branch/gcc/tree-ssa-pre.c
Comment 10 Richard Biener 2012-07-02 10:16:20 UTC
Fixed in 4.6.3.