Bug 39455 - [4.3 Regression] ICE : in compare_values_warnv, at tree-vrp.c:1073
Summary: [4.3 Regression] ICE : in compare_values_warnv, at tree-vrp.c:1073
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: tree-optimization (show other bugs)
Version: 4.4.0
: P2 normal
Target Milestone: 4.3.4
Assignee: Richard Biener
URL:
Keywords: ice-on-valid-code
Depends on:
Blocks:
 
Reported: 2009-03-13 12:33 UTC by macius bat
Modified: 2009-06-17 19:45 UTC (History)
3 users (show)

See Also:
Host: x86_64-linux
Target: x86_64-linux
Build: X86_64-PC-LINUX-GNU
Known to work: 4.1.2 4.2.4 4.4.0
Known to fail: 4.3.3
Last reconfirmed: 2009-03-16 08:49:06


Attachments
the source (8.99 KB, application/x-gzip)
2009-03-13 12:34 UTC, macius bat
Details

Note You need to log in before you can comment on or make changes to this bug.
Description macius bat 2009-03-13 12:33:23 UTC
{~/tmp}$gcc -v
Using built-in specs.
Target: x86_64-unknown-linux-gnu
Configured with: /svn/gcc/configure --prefix=/gcc-4.4/gcc --enable-shared --enable-languages=c,c++,objc,obj-c++,fortran --disable-multilib --with-gmp=/gcc-4.4/gmp --with-mpfr=/gcc-4.4/mpfr --with-ppl=/gcc-4.4/ppl --with-cloog=/gcc-4.4/cloog
Thread model: posix
gcc version 4.4.0 20090313 (experimental) (GCC) 


{~/tmp}$gcc -O2 -fprefetch-loop-arrays -c sort.c
/svn/gcc/libiberty/sort.c: In function 'sort_pointers':
/svn/gcc/libiberty/sort.c:47: internal compiler error: in compare_values_warnv, at tree-vrp.c:1073
Please submit a full bug report,with preprocessed source if appropriate.
See <http://gcc.gnu.org/bugs.html> for instructions.
Comment 1 macius bat 2009-03-13 12:34:31 UTC
Created attachment 17456 [details]
the source
Comment 2 Richard Biener 2009-03-13 14:03:54 UTC
Confirmed.  Works with 4.1 and 4.2.
Comment 3 H.J. Lu 2009-03-13 14:43:14 UTC
(In reply to comment #2)
> Confirmed.  Works with 4.1 and 4.2.
> 

I got

[hjl@gnu-16 rrs]$ gcc -O2 -fprefetch-loop-array pr39455.c -S
cc1: error: unrecognized command line option "-fprefetch-loop-array"
[hjl@gnu-16 rrs]$ gcc --version
gcc (GCC) 4.3.2 20081105 (Red Hat 4.3.2-7)

Is -fprefetch-loop-array a new option in gcc 4.4?
Comment 4 Jakub Jelinek 2009-03-13 14:57:37 UTC
s/array/arrays/
Comment 6 Richard Biener 2009-03-13 17:10:45 UTC
Well, exposed rather than caused.
Comment 7 Jakub Jelinek 2009-03-16 08:15:45 UTC
Reduced testcase:

/* { dg-do compile } */
/* { dg-options "-O2 -fprefetch-loop-arrays" } */

void
foo (char *x, unsigned long y, unsigned char *z)
{
  unsigned int c[256], *d;

  for (d = c + 1; d < c + 256; ++d)
    *d += d[-1];
  x[--c[z[y]]] = 0;
}
Comment 8 pinskia@gmail.com 2009-03-16 08:28:56 UTC
Subject: Re:  [4.3/4.4 Regression] ICE : in compare_values_warnv, at tree-vrp.c:1073



Sent from my iPhone

On Mar 16, 2009, at 1:15 AM, "jakub at gcc dot gnu dot org" <gcc-bugzilla@gcc.gnu.org 
 > wrote:

>
>
> ------- Comment #7 from jakub at gcc dot gnu dot org  2009-03-16  
> 08:15 -------
> Reduced testcase:
>
> /* { dg-do compile } */
> /* { dg-options "-O2 -fprefetch-loop-arrays" } */
>
> void
> foo (char *x, unsigned long y, unsigned char *z)
> {
>  unsigned int c[256], *d;
>
>  for (d = c + 1; d < c + 256; ++d)
>    *d += d[-1];
>  x[--c[z[y]]] = 0;

Hmm. Could this be the char-- bug? Where the front-end/gimplifier does  
not promote that to int?

Thanks,
Andrew Pinski

>
> }
>
>
> -- 
>
>
> http://gcc.gnu.org/bugzilla/show_bug.cgi?id=39455
>
Comment 9 Jakub Jelinek 2009-03-16 08:49:05 UTC
No, this seems to be aprefetch's pass fault, at least in quick skim
*.cunroll seems to be ok typewise, while *.aprefetch has:
  D.1649_44 = &c + 1024;
  D.1650_43 = (long unsigned int) D.1649_44;
  if (&c[2] <= D.1650_43)

D.1650 is long unsigned int and c is unsigned int c[256], so obviously the comparison above is wrong.

Will try to debug it.
Comment 10 Jakub Jelinek 2009-03-16 09:43:05 UTC
Seems tree-ssa-loop-niter.c has a lot of p+ issues.  The following untested patch fixes just the number_of_iterations_lt_to_ne bugs and fixes this testcase:

--- gcc/tree-ssa-loop-niter.c.jj	2009-03-04 20:06:31.000000000 +0100
+++ gcc/tree-ssa-loop-niter.c	2009-03-16 10:30:39.000000000 +0100
@@ -699,8 +699,10 @@ number_of_iterations_lt_to_ne (tree type
 	 iv0->base <= iv1->base + MOD.  */
       if (!iv0->no_overflow && !integer_zerop (mod))
 	{
-	  bound = fold_build2 (MINUS_EXPR, type,
+	  bound = fold_build2 (MINUS_EXPR, type1,
 			       TYPE_MAX_VALUE (type1), tmod);
+	  if (POINTER_TYPE_P (type))
+	    bound = fold_convert (type, bound);
 	  assumption = fold_build2 (LE_EXPR, boolean_type_node,
 				    iv1->base, bound);
 	  if (integer_zerop (assumption))
@@ -708,6 +710,11 @@ number_of_iterations_lt_to_ne (tree type
 	}
       if (mpz_cmp (mmod, bnds->below) < 0)
 	noloop = boolean_false_node;
+      else if (POINTER_TYPE_P (type))
+	noloop = fold_build2 (GT_EXPR, boolean_type_node,
+			      iv0->base,
+			      fold_build2 (POINTER_PLUS_EXPR, type,
+					   iv1->base, tmod));
       else
 	noloop = fold_build2 (GT_EXPR, boolean_type_node,
 			      iv0->base,
@@ -723,6 +730,8 @@ number_of_iterations_lt_to_ne (tree type
 	{
 	  bound = fold_build2 (PLUS_EXPR, type1,
 			       TYPE_MIN_VALUE (type1), tmod);
+	  if (POINTER_TYPE_P (type))
+	    bound = fold_convert (type, bound);
 	  assumption = fold_build2 (GE_EXPR, boolean_type_node,
 				    iv0->base, bound);
 	  if (integer_zerop (assumption))
@@ -730,6 +739,13 @@ number_of_iterations_lt_to_ne (tree type
 	}
       if (mpz_cmp (mmod, bnds->below) < 0)
 	noloop = boolean_false_node;
+      else if (POINTER_TYPE_P (type))
+	noloop = fold_build2 (GT_EXPR, boolean_type_node,
+			      fold_build2 (POINTER_PLUS_EXPR, type,
+					   iv0->base,
+					   fold_unary (NEGATE_EXPR,
+						       type1, tmod)),
+			      iv1->base);
       else
 	noloop = fold_build2 (GT_EXPR, boolean_type_node,
 			      fold_build2 (MINUS_EXPR, type1,

but e.g. number_of_iterations_le doesn't look correct at all as well.
Comment 11 Jakub Jelinek 2009-03-16 16:07:23 UTC
Subject: Bug 39455

Author: jakub
Date: Mon Mar 16 16:07:07 2009
New Revision: 144885

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=144885
Log:
	PR tree-optimization/39455
	* tree-ssa-loop-niter.c (number_of_iterations_lt_to_ne): Fix types
	mismatches for POINTER_TYPE_P (type).
	(number_of_iterations_le): Likewise.

	* gcc.dg/pr39455.c: New test.

Added:
    trunk/gcc/testsuite/gcc.dg/pr39455.c
Modified:
    trunk/gcc/ChangeLog
    trunk/gcc/testsuite/ChangeLog
    trunk/gcc/tree-ssa-loop-niter.c

Comment 12 Jakub Jelinek 2009-03-16 16:27:15 UTC
Fixed on the trunk so far.
Comment 13 littlestar 2009-06-16 03:54:30 UTC
ping 4.3.4...
Comment 14 littlestar 2009-06-16 03:56:34 UTC
ping 4.3.4...
The PR40087 fix depends on changes from the this fix, thanks!
Comment 15 Richard Biener 2009-06-17 15:12:23 UTC
Testing a backport.
Comment 16 Richard Biener 2009-06-17 19:45:56 UTC
Fixed.
Comment 17 Richard Biener 2009-06-17 19:46:10 UTC
Subject: Bug 39455

Author: rguenth
Date: Wed Jun 17 19:45:52 2009
New Revision: 148625

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

	Backport from mainline
	2009-03-16  Jakub Jelinek  <jakub@redhat.com>

	PR tree-optimization/39455
	* tree-ssa-loop-niter.c (number_of_iterations_lt_to_ne): Fix types
	mismatches for POINTER_TYPE_P (type).
	(number_of_iterations_le): Likewise.

	* gcc.dg/pr39455.c: New test.

	2009-05-19  Zdenek Dvorak  <ook@ucw.cz>

	PR tree-optimization/40087
	* tree-ssa-loop-niter.c (number_of_iterations_ne_max,
	number_of_iterations_ne): Rename never_infinite argument.
	(number_of_iterations_lt_to_ne, number_of_iterations_lt,
	number_of_iterations_le): Handle pointer-type ivs when
	exit_must_be_taken is false.
	(number_of_iterations_cond):  Do not always assume that
	exit_must_be_taken if the control variable is a pointer.

	* gcc.dg/tree-ssa/pr40087.c: New test.

Added:
    branches/gcc-4_3-branch/gcc/testsuite/gcc.dg/pr39455.c
    branches/gcc-4_3-branch/gcc/testsuite/gcc.dg/tree-ssa/pr40087.c
Modified:
    branches/gcc-4_3-branch/gcc/ChangeLog
    branches/gcc-4_3-branch/gcc/testsuite/ChangeLog
    branches/gcc-4_3-branch/gcc/tree-ssa-loop-niter.c