Bug 40281 - [4.4 Regression] -fprefetch-loop-arrays: ICE: in initialize_matrix_A, at tree-data-ref.c:1887
Summary: [4.4 Regression] -fprefetch-loop-arrays: ICE: in initialize_matrix_A, at tree...
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: middle-end (show other bugs)
Version: 4.5.0
: P2 normal
Target Milestone: 4.4.3
Assignee: Not yet assigned to anyone
URL:
Keywords: ice-on-valid-code
: 41957 (view as bug list)
Depends on:
Blocks:
 
Reported: 2009-05-28 04:55 UTC by Joost VandeVondele
Modified: 2010-01-13 07:59 UTC (History)
7 users (show)

See Also:
Host:
Target:
Build:
Known to work: 4.3.1 4.5.0
Known to fail: 4.4.3
Last reconfirmed: 2009-11-09 13:48:47


Attachments
testcase (1.11 KB, text/plain)
2009-05-28 04:57 UTC, Joost VandeVondele
Details
testcase (342 bytes, text/plain)
2009-06-19 14:41 UTC, Pat Haugen
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Joost VandeVondele 2009-05-28 04:55:40 UTC
for the testcase to be attached (what about enhancing bugzilla with an option to attach files at initial submit time?)

gfortran -v -c -O2  -funroll-loops -fprefetch-loop-arrays test.f90

Using built-in specs.
Target: x86_64-unknown-linux-gnu
Configured with: /data03/vondele/gcc_trunk/gcc/configure --prefix=/data03/vondele/gcc_trunk/build --enable-languages=c,c++,fortran --disable-multilib --with-ppl=/data03/vondele/gcc_trunk/build/ --with-cloog=/data03/vondele/gcc_trunk/build/
Thread model: posix
gcc version 4.5.0 20090527 (experimental) [trunk revision 147915] (GCC)
COLLECT_GCC_OPTIONS='-v' '-c' '-O2' '-funroll-loops' '-fprefetch-loop-arrays' '-mtune=generic'
 /data03/vondele/gcc_trunk/build/libexec/gcc/x86_64-unknown-linux-gnu/4.5.0/f951 test.f90 -quiet -dumpbase test.f90 -mtune=generic -auxbase test -O2 -version -funroll-loops -fprefetch-loop-arrays -fintrinsic-modules-path /data03/vondele/gcc_trunk/build/lib/gcc/x86_64-unknown-linux-gnu/4.5.0/finclude -o /tmp/ccDzkBkL.s
GNU Fortran (GCC) version 4.5.0 20090527 (experimental) [trunk revision 147915] (x86_64-unknown-linux-gnu)
        compiled by GNU C version 4.5.0 20090527 (experimental) [trunk revision 147915], GMP version 4.2.2, MPFR version 2.3.1
GGC heuristics: --param ggc-min-expand=30 --param ggc-min-heapsize=4096
GNU Fortran (GCC) version 4.5.0 20090527 (experimental) [trunk revision 147915] (x86_64-unknown-linux-gnu)
        compiled by GNU C version 4.5.0 20090527 (experimental) [trunk revision 147915], GMP version 4.2.2, MPFR version 2.3.1
GGC heuristics: --param ggc-min-expand=30 --param ggc-min-heapsize=4096
test.f90: In function ‘makedcoul’:
test.f90:7: internal compiler error: in initialize_matrix_A, at tree-data-ref.c:1887
Please submit a full bug report,
with preprocessed source if appropriate.
See <http://gcc.gnu.org/bugs.html> for instructions.
Comment 1 Joost VandeVondele 2009-05-28 04:57:21 UTC
Created attachment 17923 [details]
testcase

compile as 

gfortran -v -c -O2  -funroll-loops -fprefetch-loop-arrays PR40281.f90
Comment 2 Pat Haugen 2009-06-19 14:41:36 UTC
Created attachment 18024 [details]
testcase

The attatched testcase is from cpu2006 component 464.h264ref and appears to fail in the same manner on PowerPC.

work/spec_err> /home/pthaugen/install/gcc/trunk/bin/gcc -c -m32 -O2 -fprefetch-loop-arrays q_matrix.c
q_matrix.c: In function #ParseMatrix#:
q_matrix.c:5:6: internal compiler error: in initialize_matrix_A, at tree-data-ref.c:1896
Please submit a full bug report,
with preprocessed source if appropriate.
Comment 3 Andrew Pinski 2009-06-21 23:42:58 UTC
Confirmed, reduced testcase:
void f(int, int);
int g(int);
extern char errortext[300];

void ParseMatrix (void)
{
  char items[1000];
  extern int item;
  int range;
  int i, j, type, cnt;
  for (i=0; i<item; i+=cnt)
  {
    cnt=1;
    if (!type)
      range = 16;
    else
      range = 64;
    for(j=0; j<range; j++)
      if (1 != g (items[i+cnt+j]))
        f (items[i], items[i+cnt+j]);
    cnt+=j;
  }
}
Comment 4 Tobias Burnus 2009-11-05 21:04:46 UTC
Test case in comment 2 fails for me on x86-64-linux with 4.4.1 [gcc-4_4-branch revision 150839] and with 4.4.3 20091105 [gcc-4_4-branch revision 153928]. Marking thus as 4.4 regression.

Maybe related: PR 41957
Comment 5 Richard Biener 2009-11-09 13:48:47 UTC
Hm.

(gdb) call debug_generic_expr (chrec)
{{1, +, {2, +, 1}_2}_1, +, 1}_2

how can this happen?  Why does evolution_function_is_affine_multivariate_p
not reject this chrec?
Comment 6 Richard Biener 2009-11-09 13:59:26 UTC
*** Bug 41957 has been marked as a duplicate of this bug. ***
Comment 7 Volker Reichelt 2009-11-13 12:32:58 UTC
Even shorter testcase (crashes with "-O -fprefetch-loop-arrays"):

=======================================
void foo(int);

void bar(int n)
{
  int a[2], i, j = 0;

  for (i = 0; i < 2; i += j+1)
    for (j = 0; j < (n ? 1 : 2); ++j)
      foo(a[i] + a[j]);
}
=======================================
Comment 8 Sebastian Pop 2009-11-19 22:14:05 UTC
Subject: Re:  [4.4/4.5 Regression] -fprefetch-loop-arrays: 
	ICE: in initialize_matrix_A, at tree-data-ref.c:1887

Hi,

Here is a fix for this one, on top of the graphite branch.
I will commit this fix to the graphite branch to run the automatic testers,
and then it will be included in the merge from graphite to trunk.

Sebastian

diff --git a/gcc/tree-scalar-evolution.c b/gcc/tree-scalar-evolution.c
index fcd3382..7321b6e 100644
--- a/gcc/tree-scalar-evolution.c
+++ b/gcc/tree-scalar-evolution.c
@@ -2215,9 +2215,21 @@ instantiate_scev_poly (basic_block instantiate_below,
   if (CHREC_LEFT (chrec) != op0
       || CHREC_RIGHT (chrec) != op1)
     {
+      unsigned var = CHREC_VARIABLE (chrec);
+
+      /* When the instantiated stride or base has an evolution in an
+	 innermost loop, return chrec_dont_know, as this is not a
+	 valid SCEV representation.  In the reduced testcase for
+	 PR40281 we would have {0, +, {1, +, 1}_2}_1 that has no
+	 meaning.  */
+      if ((tree_is_chrec (op0) && CHREC_VARIABLE (op0) > var)
+	  || (tree_is_chrec (op1) && CHREC_VARIABLE (op1) > var))
+	return chrec_dont_know;
+
       op1 = chrec_convert_rhs (chrec_type (op0), op1, NULL);
-      chrec = build_polynomial_chrec (CHREC_VARIABLE (chrec), op0, op1);
+      chrec = build_polynomial_chrec (var, op0, op1);
     }
+
   return chrec;
 }
Comment 9 Sebastian Pop 2009-11-19 22:33:13 UTC
Subject: Bug 40281

Author: spop
Date: Thu Nov 19 22:32:50 2009
New Revision: 154348

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=154348
Log:
Fix PR40281.

2009-11-18  Sebastian Pop  <sebastian.pop@amd.com>

	PR middle-end/40281
	* testsuite/gcc.dg/graphite/pr40281.c: New.

	* tree-scalar-evolution.c (instantiate_scev_poly): Base and stride
	evolutions should not variate in inner loops.

Added:
    branches/graphite/gcc/testsuite/gcc.dg/graphite/pr40281.c
Modified:
    branches/graphite/gcc/ChangeLog.graphite
    branches/graphite/gcc/tree-scalar-evolution.c

Comment 10 Sebastian Pop 2009-11-25 05:36:16 UTC
Subject: Bug 40281

Author: spop
Date: Wed Nov 25 05:35:58 2009
New Revision: 154641

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=154641
Log:
2009-11-18  Sebastian Pop  <sebastian.pop@amd.com>

	PR middle-end/40281
	* testsuite/gcc.dg/graphite/pr40281.c: New.

	* tree-scalar-evolution.c (instantiate_scev_poly): Base and stride
	evolutions should not variate in inner loops.

Modified:
    trunk/gcc/ChangeLog.graphite
    trunk/gcc/tree-scalar-evolution.c

Comment 11 Sebastian Pop 2009-11-25 05:40:48 UTC
Fixed.
Comment 12 Richard Biener 2009-11-25 10:19:57 UTC
testcase from comment #7 still fails on the 4.4 branch.  4.4.1 doesn't work.
Comment 13 Sebastian Pop 2010-01-13 07:59:03 UTC
Subject: Bug 40281

Author: spop
Date: Wed Jan 13 07:58:50 2010
New Revision: 155851

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=155851
Log:
2010-01-13  Sebastian Pop  <sebastian.pop@amd.com>

	PR middle-end/40281
	* tree-scalar-evolution.c (instantiate_scev_1): Base and stride
	evolutions should not variate in inner loops.

	* gcc.dg/graphite/pr40281.c: New.


Added:
    branches/gcc-4_4-branch/gcc/testsuite/gcc.dg/graphite/pr40281.c
Modified:
    branches/gcc-4_4-branch/gcc/ChangeLog
    branches/gcc-4_4-branch/gcc/testsuite/ChangeLog
    branches/gcc-4_4-branch/gcc/tree-scalar-evolution.c

Comment 14 Sebastian Pop 2010-01-13 07:59:56 UTC
Fixed also in the 4.4 branch.