Bug 48734 - [4.6/4.7 Regression] ICE in eliminate_redundant_comparison, at tree-ssa-reassoc.c:1321
Summary: [4.6/4.7 Regression] ICE in eliminate_redundant_comparison, at tree-ssa-reass...
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: tree-optimization (show other bugs)
Version: 4.7.0
: P3 normal
Target Milestone: 4.6.1
Assignee: Jakub Jelinek
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2011-04-22 20:52 UTC by John Regehr
Modified: 2011-04-26 13:48 UTC (History)
2 users (show)

See Also:
Host: x86_64-unknown-linux-gnu
Target: x86_64-unknown-linux-gnu
Build: x86_64-unknown-linux-gnu
Known to work:
Known to fail:
Last reconfirmed: 2011-04-26 06:14:36


Attachments
gcc46-pr48734.patch (754 bytes, patch)
2011-04-26 07:37 UTC, Jakub Jelinek
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description John Regehr 2011-04-22 20:52:37 UTC
[regehr@gamow tmp013]$ current-gcc -O3 small.c
small.c: In function 'func_69':
small.c:12:1: internal compiler error: in eliminate_redundant_comparison, at tree-ssa-reassoc.c:1321
Please submit a full bug report,
with preprocessed source if appropriate.
See <http://gcc.gnu.org/bugs.html> for instructions.
[regehr@gamow tmp013]$ current-gcc -v
Using built-in specs.
COLLECT_GCC=current-gcc
COLLECT_LTO_WRAPPER=/uusoc/exports/scratch/regehr/z/compiler-install/gcc-r172870-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-r172870-install --program-prefix=r172870- --enable-languages=c,c++
Thread model: posix
gcc version 4.7.0 20110422 (experimental) (GCC) 
[regehr@gamow tmp013]$ cat small.c
int
safe_21 (int si)
{
  return si == -2147483647 - 1 ? si : -si;
}

unsigned g_73;
unsigned g_79;
long g_178;
int g_709;
int *
func_69 (p_71)
{
  long l_78 = 1;
  int i;
  for (i = 0; l_78 < 10; l_78 += 1)
    for (g_79 = 0; g_79 < 1; g_79 = 1)
      g_178 &= safe_21 (p_71) > g_73;
  return 0;
}

void
func_60 (unsigned p_61, int *p_62, int *p_64)
{
  func_69 (p_61);
}

int
main (void)
{
  int *l_858 = &g_709;
  int i;
  for (i = 0; i < 1; g_73 = 1)
    for (; i < 1; i++)
      {
      }
  long l_857 = 1;
  func_60 (l_857, l_858, &g_709);
  func_60 (0, 0, 0);
  return 0;
}
Comment 1 Jakub Jelinek 2011-04-26 06:14:36 UTC
Related to PR45059, caused by
http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=159189
Comment 2 Jakub Jelinek 2011-04-26 06:56:46 UTC
Reduced testcase:

unsigned int
foo (int x, unsigned int y, unsigned int z)
{
  z &= (x == -__INT_MAX__ - 1 ? x : -x) > y;
  z &= (x == -__INT_MAX__ - 1 ? x : -x) > y;
  z &= (x == -__INT_MAX__ - 1 ? x : -x) > y;
  return z;
}

The problem is that fold (from maybe_fold_and_comparisons) in this case canonicalizes the comparison in:
                /* The following case also applies to X < signed_max+1
                   and X >= signed_max+1 because previous transformations.  */
                if (code == LE_EXPR || code == GT_EXPR)
                  {
                    tree st;
                    st = signed_type_for (TREE_TYPE (arg1));   
                    return fold_build2_loc (loc,
                                        code == LE_EXPR ? GE_EXPR : LT_EXPR,
                                        type, fold_convert_loc (loc, st, arg0),
                                        build_int_cst (st, 0));
                  }
to include the extra cast to the signed cast and eliminate_redundant_comparison is prepared to handle just one operation instead of two.  I think expecting fold to return some particular form of result is just wrong assumption, it will break sooner or later, so while the code could perhaps handle on extra cast or something similar, it needs to give up on elimination if the returned expression can't be handled.
Comment 3 Jakub Jelinek 2011-04-26 07:37:58 UTC
Created attachment 24099 [details]
gcc46-pr48734.patch

Untested fix.
Comment 4 Richard Biener 2011-04-26 12:15:13 UTC
Looks good to me.
Comment 5 Jakub Jelinek 2011-04-26 13:33:55 UTC
Author: jakub
Date: Tue Apr 26 13:33:49 2011
New Revision: 172967

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=172967
Log:
	PR tree-optimization/48734
	* tree-ssa-reassoc.c (eliminate_redundant_comparison): Give up
	if return value from maybe_fold_*_comparsions isn't something
	the code is prepared to handle.

	* gcc.c-torture/compile/pr48734.c: New test.

Added:
    trunk/gcc/testsuite/gcc.c-torture/compile/pr48734.c
Modified:
    trunk/gcc/ChangeLog
    trunk/gcc/testsuite/ChangeLog
    trunk/gcc/tree-ssa-reassoc.c
Comment 6 Jakub Jelinek 2011-04-26 13:44:54 UTC
Author: jakub
Date: Tue Apr 26 13:44:51 2011
New Revision: 172969

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=172969
Log:
	PR tree-optimization/48734
	* tree-ssa-reassoc.c (eliminate_redundant_comparison): Give up
	if return value from maybe_fold_*_comparsions isn't something
	the code is prepared to handle.

	* gcc.c-torture/compile/pr48734.c: New test.

Added:
    branches/gcc-4_6-branch/gcc/testsuite/gcc.c-torture/compile/pr48734.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-reassoc.c
Comment 7 Jakub Jelinek 2011-04-26 13:48:10 UTC
Fixed.