Bug 38932 - [4.3 Regression] ICE in set_value_range, at tree-vrp.c:398
Summary: [4.3 Regression] ICE in set_value_range, at tree-vrp.c:398
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: middle-end (show other bugs)
Version: 4.4.0
: P2 critical
Target Milestone: 4.3.4
Assignee: Paolo Bonzini
URL: http://gcc.gnu.org/ml/gcc-patches/200...
Keywords: ice-on-valid-code, patch
Depends on:
Blocks: 38934
  Show dependency treegraph
 
Reported: 2009-01-22 08:08 UTC by Paolo Bonzini
Modified: 2009-01-26 15:54 UTC (History)
5 users (show)

See Also:
Host:
Target: i686-pc-linux-gnu
Build:
Known to work: 4.2.3 4.4.0 4.3.4
Known to fail: 4.3.3
Last reconfirmed: 2009-01-22 11:04:08


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Paolo Bonzini 2009-01-22 08:08:02 UTC
From PR38572, but unrelated to it:

void f (long long int p)
{
  int x;
  static unsigned char g;
  long long int min = -9223372036854775807LL - 1;
  g = 1;
  x = (signed char) (g | 249) / 4;
  if (p >= min - (long long int) x)
    p = 1;

  if (p)
    abort ();
}

gives

small.c: In function 'f':
small.c:3: internal compiler error: in set_value_range, at tree-vrp.c:398

Note that after FRE the code becomes the simpler

void f (long long int p)
{
  long long int min = 9223372036854775807LL + 2; /*0x7fffffffffffffff */
  if (min <= p)
    p = 1;

  if (p)
    abort ();
}

but this does not ICE because in this testcase the "min <= p" is changed to "p != min - 1" by the first CCP pass, so this is also a missed folding in FRE.

I'm looking at the VRP failure though.
Comment 1 Paolo Bonzini 2009-01-22 08:09:18 UTC
Can anyone check if this is a regression, and if so from which version?
Comment 2 Paolo Bonzini 2009-01-22 08:17:41 UTC
Actually, there is no overflow in -9223372036854775807LL - 1 so this is a third bug. :-)
Comment 3 Paolo Bonzini 2009-01-22 08:23:21 UTC
ah no there's no overflow bit on min
Comment 4 Paolo Bonzini 2009-01-22 09:00:22 UTC
In PRE there is a fold_convert_const_int_from_int call simplifying "(signed char) 249"  to -7, but setting the TREE_OVERFLOW flag in the meanwhile.  I don't think it makes sense to set the overflow flag on a NOP:

   * `The result of, or the signal raised by, converting an integer to a
     signed integer type when the value cannot be represented in an
     object of that type (C90 6.2.1.2, C99 6.3.1.3).'

     For conversion to a type of width N, the value is reduced modulo
     2^N to be within range of the type; no signal is raised.

(Integers implementation, from the gcc manual).
Comment 5 pinskia@gmail.com 2009-01-22 09:17:11 UTC
Subject: Re:  ICE in set_value_range, at tree-vrp.c:398



Sent from my iPhone

On Jan 22, 2009, at 1:00 AM, "bonzini at gnu dot org" <gcc-bugzilla@gcc.gnu.org 
 > wrote:

>
>
> ------- Comment #4 from bonzini at gnu dot org  2009-01-22 09:00  
> -------
> In PRE there is a fold_convert_const_int_from_int call simplifying  
> "(signed
> char) 249"  to -7, but setting the TREE_OVERFLOW flag in the  
> meanwhile.  I
> don't think it makes sense to set the overflow flag on a NOP:

Yes but changing that right now opens lots of bags of worms.  It has  
been tried before.  The simple way to fix this is in pre unset  
TREE_OVERFLOW because at this point in the IR it does not matter.  I  
hope someone would change vrp to do the correct thing but I guess that  
won't happen any time soon.


Thanks,
Andrew Pinski

>
>
>   * `The result of, or the signal raised by, converting an integer  
> to a
>     signed integer type when the value cannot be represented in an
>     object of that type (C90 6.2.1.2, C99 6.3.1.3).'
>
>     For conversion to a type of width N, the value is reduced modulo
>     2^N to be within range of the type; no signal is raised.
>
> (Integers implementation, from the gcc manual).
>
>
> -- 
>
> bonzini at gnu dot org changed:
>
>           What    |Removed                     |Added
> --- 
> --- 
> ----------------------------------------------------------------------
>                 CC|                            |rguenth at gcc dot  
> gnu dot
>                   |                            |org
>
>
> http://gcc.gnu.org/bugzilla/show_bug.cgi?id=38932
>
Comment 6 rguenther@suse.de 2009-01-22 09:29:41 UTC
Subject: Re:  ICE in set_value_range, at
 tree-vrp.c:398

On Thu, 22 Jan 2009, bonzini at gnu dot org wrote:

> ------- Comment #4 from bonzini at gnu dot org  2009-01-22 09:00 -------
> In PRE there is a fold_convert_const_int_from_int call simplifying "(signed
> char) 249"  to -7, but setting the TREE_OVERFLOW flag in the meanwhile.  I
> don't think it makes sense to set the overflow flag on a NOP:
> 
>    * `The result of, or the signal raised by, converting an integer to a
>      signed integer type when the value cannot be represented in an
>      object of that type (C90 6.2.1.2, C99 6.3.1.3).'
> 
>      For conversion to a type of width N, the value is reduced modulo
>      2^N to be within range of the type; no signal is raised.
> 
> (Integers implementation, from the gcc manual).

Correct.  PRE should make sure to clear TREE_OVERFLOW, like CCP for
example does.  A more general solution unfortunately opens too many
cans of worms.

Richard.
Comment 7 Paolo Bonzini 2009-01-22 11:04:08 UTC
mine.
Comment 8 Paolo Bonzini 2009-01-22 12:10:43 UTC
Fixing FRE still causes an ICE for this:

/* { dg-do compile } */
/* { dg-options "-O2 --std=gnu99" } */

/* This variable needed only to exercise FRE instead of CCP.  */
unsigned char g;

extern void abort();

void f (long long int p)
{
  g = 255;
  /* { dg-warning "constant is" "" { target *-*-* } 14 } */
  /* { dg-warning "overflow" "" { target *-*-* } 14 } */
  if (p >= -9223372036854775808LL - (signed char) g)
    p = 1;

  if (p)
    abort ();
}

Should I create a separate bug and submit what I have?
Comment 9 rguenther@suse.de 2009-01-22 12:28:22 UTC
Subject: Re:  [4.4 Regression] ICE in set_value_range,
 at tree-vrp.c:398

On Thu, 22 Jan 2009, bonzini at gnu dot org wrote:

> ------- Comment #8 from bonzini at gnu dot org  2009-01-22 12:10 -------
> Fixing FRE still causes an ICE for this:
> 
> /* { dg-do compile } */
> /* { dg-options "-O2 --std=gnu99" } */
> 
> /* This variable needed only to exercise FRE instead of CCP.  */
> unsigned char g;
> 
> extern void abort();
> 
> void f (long long int p)
> {
>   g = 255;
>   /* { dg-warning "constant is" "" { target *-*-* } 14 } */
>   /* { dg-warning "overflow" "" { target *-*-* } 14 } */
>   if (p >= -9223372036854775808LL - (signed char) g)
>     p = 1;
> 
>   if (p)
>     abort ();
> }
> 
> Should I create a separate bug and submit what I have?

Yes.

Thanks,
Richard.
Comment 10 H.J. Lu 2009-01-22 16:09:18 UTC
It is caused by revision 126434:

http://gcc.gnu.org/ml/gcc-cvs/2007-07/msg00290.html
Comment 11 Daniel Berlin 2009-01-22 17:12:49 UTC
Subject: Re:  [4.3/4.4 Regression] ICE in 
	set_value_range, at tree-vrp.c:398

Uh, well, that would be tricky since none of this code still exists in 4.4.0

On Thu, Jan 22, 2009 at 11:09 AM, hjl dot tools at gmail dot com
<gcc-bugzilla@gcc.gnu.org> wrote:
>
>
> ------- Comment #10 from hjl dot tools at gmail dot com  2009-01-22 16:09 -------
> It is caused by revision 126434:
>
> http://gcc.gnu.org/ml/gcc-cvs/2007-07/msg00290.html
>
>
> --
>
> hjl dot tools at gmail dot com changed:
>
>           What    |Removed                     |Added
> ----------------------------------------------------------------------------
>                 CC|                            |dberlin at gcc dot gnu dot
>                   |                            |org
>      Known to fail|4.4.0                       |4.3.3 4.4.0
>            Summary|[4.4 Regression] ICE in     |[4.3/4.4 Regression] ICE in
>                   |set_value_range, at tree-   |set_value_range, at tree-
>                   |vrp.c:398                   |vrp.c:398
>
>
> http://gcc.gnu.org/bugzilla/show_bug.cgi?id=38932
>
> ------- You are receiving this mail because: -------
> You are on the CC list for the bug, or are watching someone who is.
>
Comment 12 Paolo Bonzini 2009-01-23 15:57:34 UTC
Subject: Bug 38932

Author: bonzini
Date: Fri Jan 23 15:57:19 2009
New Revision: 143588

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=143588
Log:
2008-01-23  Paolo Bonzini  <bonzini@gnu.org>

	PR tree-optimization/38932
	* fold-const.c (fold_unary_no_overflow): New.
	* tree.h (fold_unary_no_overflow): Declare.
	* tree-ssa-ccp.c (ccp_fold): Use fold_unary_no_overflow.
	* tree-ssa-sccvn.c (visit_reference_op_load,
	simplify_unary_expression): Likewise.

testsuite:
2008-01-23  Paolo Bonzini  <bonzini@gnu.org>

	PR tree-optimization/38932
	* gcc.dg/pr38932.c: New.


Added:
    trunk/gcc/testsuite/gcc.dg/pr38932.c
Modified:
    trunk/gcc/ChangeLog
    trunk/gcc/fold-const.c
    trunk/gcc/testsuite/ChangeLog
    trunk/gcc/tree-ssa-ccp.c
    trunk/gcc/tree-ssa-sccvn.c
    trunk/gcc/tree.h

Comment 13 Richard Biener 2009-01-23 16:18:23 UTC
Fixed on the trunk.
Comment 14 Paolo Bonzini 2009-01-24 08:59:45 UTC
Regarding the target milestone, you mean I should apply a 4.3 patch before the release goes out, too? (I'm currently regtesting it).
Comment 15 rguenther@suse.de 2009-01-24 09:34:54 UTC
Subject: Re:  [4.3 Regression] ICE in set_value_range,
 at tree-vrp.c:398

On Sat, 24 Jan 2009, bonzini at gnu dot org wrote:

> ------- Comment #14 from bonzini at gnu dot org  2009-01-24 08:59 -------
> Regarding the target milestone, you mean I should apply a 4.3 patch before the
> release goes out, too? (I'm currently regtesting it).

No.

Richard.
Comment 16 Paolo Bonzini 2009-01-24 09:54:14 UTC
changing milestone appropriately then, it did sound strange.
Comment 17 rguenther@suse.de 2009-01-24 09:55:46 UTC
Subject: Re:  [4.3 Regression] ICE in set_value_range,
 at tree-vrp.c:398

On Sat, 24 Jan 2009, bonzini at gnu dot org wrote:

> ------- Comment #16 from bonzini at gnu dot org  2009-01-24 09:54 -------
> changing milestone appropriately then, it did sound strange.

Well, we will bump the target milestone of all bugs appropriately
after the release.  So it wasn't inappropriate but just followed
policy.

Richard.
Comment 18 Paolo Bonzini 2009-01-26 15:54:31 UTC
Subject: Bug 38932

Author: bonzini
Date: Mon Jan 26 15:54:18 2009
New Revision: 143677

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=143677
Log:
gcc:
2008-01-26  Paolo Bonzini  <bonzini@gnu.org>

	PR tree-optimization/38932
	* fold-const.c (fold_unary_ignore_overflow): New.
	* tree.h (fold_unary_ignore_overflow): Declare.
	* tree-ssa-ccp.c (ccp_fold): Use fold_unary_ignore_overflow.
	* tree-ssa-sccvn.c (simplify_unary_expression): Likewise.

gcc/testsuite:
2008-01-26  Paolo Bonzini  <bonzini@gnu.org>

	PR tree-optimization/38932
	* gcc.dg/pr38932.c: New.


Added:
    branches/gcc-4_3-branch/gcc/testsuite/gcc.dg/pr38932.c
      - copied unchanged from r143588, trunk/gcc/testsuite/gcc.dg/pr38932.c
Modified:
    branches/gcc-4_3-branch/gcc/ChangeLog
    branches/gcc-4_3-branch/gcc/fold-const.c
    branches/gcc-4_3-branch/gcc/testsuite/ChangeLog
    branches/gcc-4_3-branch/gcc/tree-ssa-ccp.c
    branches/gcc-4_3-branch/gcc/tree-ssa-sccvn.c
    branches/gcc-4_3-branch/gcc/tree.h

Comment 19 Paolo Bonzini 2009-01-26 15:54:43 UTC
fixed on 4.3 branch too.