Bug 38926 - [4.4 Regression] ice in find_or_generate_expression, at tree-ssa-pre.c:2769
Summary: [4.4 Regression] ice in find_or_generate_expression, at tree-ssa-pre.c:2769
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: tree-optimization (show other bugs)
Version: 4.4.0
: P1 normal
Target Milestone: 4.4.0
Assignee: Richard Biener
URL:
Keywords: ice-on-valid-code
: 39017 (view as bug list)
Depends on:
Blocks:
 
Reported: 2009-01-21 04:07 UTC by John Regehr
Modified: 2018-03-12 16:50 UTC (History)
4 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2009-01-27 14:38:26


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description John Regehr 2009-01-21 04:07:29 UTC
Seen using r143537 on Ubuntu Hardy.

regehr@john-home:~/volatile/tmp123$ current-gcc -O3 small.c
small.c: In function ‘baz’:
small.c:59: internal compiler error: in find_or_generate_expression, at tree-ssa-pre.c:2769
Please submit a full bug report,
with preprocessed source if appropriate.
See <http://gcc.gnu.org/bugs.html> for instructions.
regehr@john-home:~/volatile/tmp123$ current-gcc -v
Using built-in specs.
Target: i686-pc-linux-gnu
Configured with: ../configure --prefix=/home/regehr/z/tmp/gcc-r143537-install --program-prefix=r143537- --enable-languages=c,c++
Thread model: posix
gcc version 4.4.0 20090121 (experimental) (GCC) 
regehr@john-home:~/volatile/tmp123$ cat small.c
unsigned foo (int _si1, unsigned _si2)
{
  return _si1 > 0 && _si2 > 0 && _si1 > 2147483647 - _si2 && _si2;
}

signed char bar (signed char _left, int _right)
{
  return (unsigned int) _right >= 1 * 8 ? : _left >> _right;
}

unsigned g_2;
unsigned g_67;
unsigned g_111;
volatile unsigned g_162;

unsigned func_51 (unsigned p_53, unsigned p_55)
{
  return g_2;
}

int func_62 (unsigned p_63)
{
  p_63 = g_2 & g_67;
  if (g_2)
    {
    }
  else if (p_63)
    return 1;
  g_67 = bar (p_63, func_51 (g_67, 1));
  return 0;
}

int func_57 (unsigned p_58)
{
  return func_62 (1);
}

int func_48 (unsigned p_49, unsigned p_50)
{
  return func_57 (1);
}

unsigned func_1 (void)
{
  unsigned l_5 = 0;
  if (g_2)
    for (1; g_2 <= -16; g_2 = foo (g_2, 1))
      {
	for (1; g_162; g_162)
	  func_48 (func_48 (g_2, 1), l_5);
	if (g_111)
	  return 1;
      }
  return 0;
}

void crc32 (int);

void baz (void)
{
  func_1 ();
  crc32 (g_2);
}
Comment 1 Richard Biener 2009-01-21 10:13:21 UTC
Confirmed.  PRE doesn't find a leader for a NAME (!?) when inserting {nop_expr,g_2.7_47}.
Comment 2 Daniel Berlin 2009-01-21 14:09:52 UTC
Subject: Re:  [4.4 Regression] ice in 
	find_or_generate_expression, at tree-ssa-pre.c:2769

names should be self-leaders.
Sounds like a set bitmap messup somewhere or an equality function gone
bad or something.
i'll take a look

On Wed, Jan 21, 2009 at 5:13 AM, rguenth at gcc dot gnu dot org
<gcc-bugzilla@gcc.gnu.org> wrote:
>
>
> ------- Comment #1 from rguenth at gcc dot gnu dot org  2009-01-21 10:13 -------
> Confirmed.  PRE doesn't find a leader for a NAME (!?) when inserting
> {nop_expr,g_2.7_47}.
>
>
> --
>
> rguenth at gcc dot gnu dot org changed:
>
>           What    |Removed                     |Added
> ----------------------------------------------------------------------------
>                 CC|                            |dberlin at gcc dot gnu dot
>                   |                            |org
>             Status|UNCONFIRMED                 |NEW
>          Component|c                           |tree-optimization
>     Ever Confirmed|0                           |1
>  GCC build triplet|i686-pc-linux-gnu           |
>   GCC host triplet|i686-pc-linux-gnu           |
>  GCC target triplet|i686-pc-linux-gnu           |
>           Keywords|                            |ice-on-valid-code
>   Last reconfirmed|0000-00-00 00:00:00         |2009-01-21 10:13:21
>               date|                            |
>            Summary|ice in                      |[4.4 Regression] ice in
>                   |find_or_generate_expression,|find_or_generate_expression,
>                   |at tree-ssa-pre.c:2769      |at tree-ssa-pre.c:2769
>   Target Milestone|---                         |4.4.0
>            Version|unknown                     |4.4.0
>
>
> http://gcc.gnu.org/bugzilla/show_bug.cgi?id=38926
>
> ------- You are receiving this mail because: -------
> You are on the CC list for the bug, or are watching someone who is.
>
Comment 3 Richard Biener 2009-01-27 11:07:50 UTC
Smaller testcase:

unsigned foo (int _si1, unsigned _si2)
{
  return _si1 > 0 && _si1 > 2147483647 - _si2;
}

unsigned bar (unsigned _left, int _right)
{
  return (unsigned) _right >= 8 ? 1 : _left >> _right;
}

unsigned g_2;
unsigned g_67;
unsigned g_111;
volatile unsigned g_162;

int func_62 (unsigned p_63)
{
  p_63 = g_2 & g_67;
  if (g_2)
    ;
  else if (p_63)
    return 1;
  g_67 = bar (p_63, g_2);
  return 0;
}

void func_1 (void)
{
  if (g_2)
    for (; g_2 <= -16; g_2 = foo (g_2, 1))
      {
        for (; g_162; g_162)
          func_62 (func_62 (0));
        if (g_111)
          return;
      }
}

void crc32 (int);

void baz (void)
{
  func_1 ();
  crc32 (g_2);
}
Comment 4 Richard Biener 2009-01-27 13:36:18 UTC
static inline int foo (unsigned _si1)
{
  if (_si1 != 0)
    if (_si1 > 2147483647)
      return 1;
  return 0;
}

static inline unsigned bar (unsigned _left, int _right)
{
  return (unsigned) _right >= 8 ? 1 : _left >> _right;
}

unsigned g_2;
unsigned g_67;
volatile unsigned g_162;

static inline int func_62 (unsigned p_63)
{
  p_63 = g_2 & g_67;
  if (g_2)
    ;
  else if (p_63)
    return 1;
  g_67 = bar (p_63, g_2);
  return 0;
}

unsigned baz (void)
{
  if (g_2)
    for (; g_2 <= -16; g_2 = foo (g_2))
      {
        for (; g_162; g_162)
          func_62 (func_62 (0));
        if (g_67)
          break;
      }
  return g_2;
}


The only difference between -O2 and -O3 is that PPRE is enabled which is
what somehow triggers the ICE.
Comment 5 Richard Biener 2009-01-27 14:34:31 UTC
We try to insert {nop_expr,g_2.7_58} in bb 41

<bb 18>:
  # g_67_22 = PHI <g_67_63(39), g_67_44(D)(24)>
  # g_2.7_58 = PHI <g_2.11_10(39), g_2.7_1(24)>
  # g_2_59 = PHI <g_2_48(39), g_2_43(D)(24)>
  # VUSE <g_162_45(D)>
  g_162.9_61 ={v} g_162;
  if (g_162.9_61 != 0)
    goto <bb 41>;
  else
    goto <bb 42>;

<bb 42>:
  goto <bb 13>;

<bb 41>:
  goto <bb 4>;

The original avail_out computation says

exp_gen[41] := {  }
tmp_gen[41] := {  }
avail_out[41] := { g_2.7_1 (0002), g_2.7_58 (0030), g_162.9_61 (0032) }

(correct)

but at the point of insertion we instead have

debug[0] := { g_2.7_1 (0002), g_162.9_61 (0032), pretmp.23_38 (0046), prephitmp.24_23 (0044), prephitmp.29_66 (0037) }

so we replaced some value here, but with a different value-number.

This happens in

              /* Note that we need to value_replace both NEW_SETS, and
                 AVAIL_OUT. For both the case of NEW_SETS, the value may be
                 represented by some non-simple expression here that we want
                 to replace it with.  */
              FOR_EACH_EXPR_ID_IN_SET (newset, i, bi)
                {
                  pre_expr expr = expression_for_id (i);
                  bitmap_value_replace_in_set (NEW_SETS (block), expr);
                  bitmap_value_replace_in_set (AVAIL_OUT (block), expr);
                }

where I see us replacing in

debug[0] := { g_2.7_1 (0002), g_2.7_58 (0030), g_162.9_61 (0032), pretmp.23_38 (0046), prephitmp.24_23 (0044), prephitmp.29_66 (0037) }

with expr prephitmp.29_66 (0037)

with the above result.  The expression set for 0037 at that point is

debug[0] := { g_2.7_58 (0030), {g_2} (0037), pretmp.23_2 (0037), prephitmp.29_66 (0037) }

where for some weird reason g_2.7_58 (0030) is in it (!?).
Comment 6 Richard Biener 2009-01-27 14:38:26 UTC
Happens here:

  /* If the PHI node is already available, use it.  */
  if ((res = vn_phi_lookup (phi)) != NULL_TREE)
    {
      gimple_stmt_iterator gsi = gsi_for_stmt (phi);
      remove_phi_node (&gsi, true);
      release_defs (phi);
      add_to_value (val, get_or_alloc_expr_for_name (res));

we add g_2.7_58 to 0037 here even though get_expr_value_id returns 0030.  I
vaguely remember adding that code ...
Comment 7 Richard Biener 2009-01-27 15:08:21 UTC
So we are about to insert a duplicate PHI node but for a different value number.

I can trivially avoid the ICE, but I wonder if that (missed optimization?) is
bad or not ...

Patch in testing.
Comment 8 Richard Biener 2009-01-28 12:14:21 UTC
Subject: Bug 38926

Author: rguenth
Date: Wed Jan 28 12:14:09 2009
New Revision: 143725

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

	PR tree-optimization/38926
	* tree-ssa-pre.c (add_to_value): Assert we add only expressions
	with the correct value id to a value.
	(do_regular_insertion): Use the value number of edoubleprime
	for the value number of the expr.

	Revert
	2008-08-21  Richard Guenther  <rguenther@suse.de>
  
        * tree-ssa-pre.c (insert_into_preds_of_block): Before inserting
        a PHI ask VN if it is already available.
        * tree-ssa-sccvn.h (vn_phi_lookup): Declare.
        * tree-ssa-sccvn.c (vn_phi_lookup): Export.

	* gcc.c-torture/compile/pr38926.c: New testcase.

Added:
    trunk/gcc/testsuite/gcc.c-torture/compile/pr38926.c
Modified:
    trunk/gcc/ChangeLog
    trunk/gcc/testsuite/ChangeLog
    trunk/gcc/tree-ssa-pre.c
    trunk/gcc/tree-ssa-sccvn.c
    trunk/gcc/tree-ssa-sccvn.h

Comment 9 Richard Biener 2009-01-28 12:26:18 UTC
Fixed.
Comment 10 hjl@gcc.gnu.org 2009-01-29 17:06:30 UTC
Subject: Bug 38926

Author: hjl
Date: Thu Jan 29 17:06:01 2009
New Revision: 143762

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=143762
Log:
2009-01-29  H.J. Lu  <hongjiu.lu@intel.com>

	Backport from mainline:
	2009-01-29  Steve Ellcey  <sje@cup.hp.com>

	PR middle-end/38857
	* gcc.c-torture/compile/pr38857.c: New test.

	2009-01-28  Richard Guenther  <rguenther@suse.de>

	PR tree-optimization/38926
	* gcc.c-torture/compile/pr38926.c: New testcase.

Added:
    branches/gcc-4_3-branch/gcc/testsuite/gcc.c-torture/compile/pr38857.c
      - copied unchanged from r143760, trunk/gcc/testsuite/gcc.c-torture/compile/pr38857.c
    branches/gcc-4_3-branch/gcc/testsuite/gcc.c-torture/compile/pr38926.c
      - copied unchanged from r143759, trunk/gcc/testsuite/gcc.c-torture/compile/pr38926.c
Modified:
    branches/gcc-4_3-branch/gcc/testsuite/ChangeLog

Comment 11 Volker Reichelt 2009-02-02 23:46:34 UTC
*** Bug 39017 has been marked as a duplicate of this bug. ***