Bug 46723 - [4.5 Regression] internal compiler error: in get_initial_def_for_induction, at tree-vect-loop.c:2431
Summary: [4.5 Regression] internal compiler error: in get_initial_def_for_induction, a...
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: tree-optimization (show other bugs)
Version: 4.5.1
: P2 normal
Target Milestone: 4.5.3
Assignee: Richard Biener
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2010-11-30 13:49 UTC by Matthias Kretz (Vir)
Modified: 2011-03-01 17:04 UTC (History)
4 users (show)

See Also:
Host:
Target:
Build:
Known to work: 4.5.0, 4.6.0
Known to fail: 4.5.1
Last reconfirmed: 2010-11-30 14:27:37


Attachments
preprocessed source which makes G++ 4.5.1 ICE (99.99 KB, text/plain)
2010-11-30 13:50 UTC, Matthias Kretz (Vir)
Details
A reduced testcase (1.57 KB, text/plain)
2010-11-30 18:11 UTC, H.J. Lu
Details
patch (1.85 KB, patch)
2010-12-01 15:37 UTC, Richard Biener
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Matthias Kretz (Vir) 2010-11-30 13:49:16 UTC
Compile the attached (preprocessed) source file with
/opt/gcc-4.5.1/bin/g++ -O3 -o tmp.o -c gcc_4.5.1_ice.cpp

and you'll get
/home/mkretz/src/testing/Vc-Nightly/tests/memory.cpp: In static member function ‘static void TestVectors<V, Size>::test() [with V = Vc::Simple::Vector<short int>, unsigned int Size = 128u]’:
/home/mkretz/src/testing/Vc-Nightly/tests/memory.cpp:89:46: internal compiler error: in get_initial_def_for_induction, at tree-vect-loop.c:2431
Comment 1 Matthias Kretz (Vir) 2010-11-30 13:50:55 UTC
Created attachment 22578 [details]
preprocessed source which makes G++ 4.5.1 ICE
Comment 2 Richard Biener 2010-11-30 14:27:37 UTC
Confirmed.  This is a regression on the branch, trunk works, so maybe some
patches need to be backported (PR45971 comes to my mind).

Reducing.
Comment 3 H.J. Lu 2010-11-30 18:11:41 UTC
Created attachment 22583 [details]
A reduced testcase

[hjl@gnu-35 delta]$ /usr/gcc-4.5/bin/gcc -S -O3 testcase-min.cc
testcase-min.cc: In function ‘void testVectors() [with V = Vc::Simple::Vector<short int>]’:
testcase-min.cc:157:27: internal compiler error: in get_initial_def_for_induction, at tree-vect-loop.c:2431
Please submit a full bug report,
with preprocessed source if appropriate.
See <http://gcc.gnu.org/bugs.html> for instructions.
[hjl@gnu-35 delta]$
Comment 4 H.J. Lu 2010-11-30 19:20:29 UTC
It is caused by revision 161951:

http://gcc.gnu.org/ml/gcc-cvs/2010-07/msg00305.html
Comment 5 Richard Biener 2010-12-01 10:01:32 UTC
Mine then.
Comment 6 Richard Biener 2010-12-01 15:32:55 UTC
C testcase that also ICEs on trunk:

short *m;
void test()
{
  short x = 128;
  unsigned int i;
  for (i = 0; i < 128; ++i, x = (unsigned short)x + 1)
    m[i] = x;
}

we are confused wrt the address arithmetic in

  D.2720_6 = (long unsigned int) i_20;
  D.2721_7 = D.2720_6 * 2;
  D.2722_8 = pretmp.6_18 + D.2721_7;
  *D.2722_8 = x_19;

and don't ICE with

short m[128];

which just gives us m[i_20] = x_19;

The access function that isn't a simple iv evolution is:

(short int) {(short unsigned int) x_50, +, 1}_1

At analysis time (in the not copied loop) we analyse it to

{128, +, 1}_1

instead as the loop bound is now non-constant after peeling a prologue:

<bb 3>:
  # x_19 = PHI <x_12(4), x_50(22)>
  # i_20 = PHI <i_9(4), i_52(22)>
  # ivtmp.14_5 = PHI <ivtmp.14_27(4), ivtmp.14_55(22)>
  D.2690_6 = (long unsigned int) i_20;
  D.2691_7 = D.2690_6 * 2;
  D.2692_8 = pretmp.6_18 + D.2691_7;
  *D.2692_8 = x_19;
  i_9 = i_20 + 1;
  x.1_10 = (short unsigned int) x_19;
  D.2694_11 = x.1_10 + 1;
  x_12 = (short int) D.2694_11;
  ivtmp.14_27 = ivtmp.14_5 - 1;
  if (ivtmp.14_27 != 0)
    goto <bb 4>;
  else
    goto <bb 19>;

in principle we can deal with that evolution just fine, but this
discrepancy analysis vs. transformation time doesn't look too good.
Comment 7 Richard Biener 2010-12-01 15:37:09 UTC
Created attachment 22587 [details]
patch

Patch I'm testing.  Computes the induction PHI in the type of the evolution,
stripping conversions (sign-changing only for now) and re-applying them at
uses (by inserting another assignment that does the conversion in place for
the vectorized stmt).
Comment 8 Ira Rosen 2010-12-02 08:15:16 UTC
*************** get_initial_def_for_induction (gimple iv
*** 2656,2667 ****
--- 2639,2664 ----
    loop_arg = PHI_ARG_DEF_FROM_EDGE (iv_phi, latch_e);
  
    access_fn = analyze_scalar_evolution (iv_loop, PHI_RESULT (iv_phi));
+   STRIP_NOPS (access_fn);
    gcc_assert (access_fn);

this makes gcc_assert meaningless: STRIP_NOPS will segfault for NULL access_fn before the assert.

Thanks,
Ira
Comment 9 rguenther@suse.de 2010-12-02 09:03:35 UTC
On Thu, 2 Dec 2010, irar at il dot ibm.com wrote:

> http://gcc.gnu.org/bugzilla/show_bug.cgi?id=46723
> 
> Ira Rosen <irar at il dot ibm.com> changed:
> 
>            What    |Removed                     |Added
> ----------------------------------------------------------------------------
>                  CC|                            |irar at il dot ibm.com
> 
> --- Comment #8 from Ira Rosen <irar at il dot ibm.com> 2010-12-02 08:15:16 UTC ---
> *************** get_initial_def_for_induction (gimple iv
> *** 2656,2667 ****
> --- 2639,2664 ----
>     loop_arg = PHI_ARG_DEF_FROM_EDGE (iv_phi, latch_e);
> 
>     access_fn = analyze_scalar_evolution (iv_loop, PHI_RESULT (iv_phi));
> +   STRIP_NOPS (access_fn);
>     gcc_assert (access_fn);
> 
> this makes gcc_assert meaningless: STRIP_NOPS will segfault for NULL access_fn
> before the assert.

Ah, indeed.  Of course we should never assert here (if we do the analysis
has wrongly determined we can handle the induction), but of course we
can't fail to vectorize at this point either ...

Thanks,
Richard.
Comment 10 Richard Biener 2010-12-02 16:23:26 UTC
Author: rguenth
Date: Thu Dec  2 16:23:20 2010
New Revision: 167377

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=167377
Log:
2010-12-02  Richard Guenther  <rguenther@suse.de>

	PR tree-optimization/46723
	* tree-vect-loop.c (get_initial_def_for_induction): Strip
	conversions from the induction evolution and apply it to
	the result instead.
	* tree-vect-stmts.c (vect_get_vec_def_for_operand): Handle
	assigns for induction defs.

	* gcc.dg/torture/pr46723.c: New testcase.

Added:
    trunk/gcc/testsuite/gcc.dg/torture/pr46723.c
Modified:
    trunk/gcc/ChangeLog
    trunk/gcc/testsuite/ChangeLog
    trunk/gcc/tree-vect-loop.c
    trunk/gcc/tree-vect-stmts.c
Comment 11 Richard Biener 2010-12-02 16:27:26 UTC
Fixed on trunk sofar.
Comment 12 Richard Biener 2010-12-16 13:02:42 UTC
GCC 4.5.2 is being released, adjusting target milestone.
Comment 13 Matthias Klose 2011-02-19 18:43:00 UTC
the patch fixes the ICE on the 4.5 branch, no regressions on a i686-linux-gnu biarch build and test.
Comment 14 Richard Biener 2011-03-01 17:04:32 UTC
Author: rguenth
Date: Tue Mar  1 17:04:26 2011
New Revision: 170595

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

        Backport from mainline
        2011-03-01  Richard Guenther  <rguenther@suse.de>

	PR tree-optimization/47890
	* tree-vect-loop.c (get_initial_def_for_induction): Set
	related stmt properly.

	* gcc.dg/torture/pr47890.c: New testcase.

        2010-12-01  Richard Guenther  <rguenther@suse.de>

	PR tree-optimization/46723
	* tree-vect-loop.c (get_initial_def_for_induction): Strip
	conversions from the induction evolution and apply it to
	the result instead.
	* tree-vect-stmts.c (vect_get_vec_def_for_operand): Handle
	assigns for induction defs.

	* gcc.dg/torture/pr46723.c: New testcase.

Added:
    branches/gcc-4_5-branch/gcc/testsuite/gcc.dg/torture/pr46723.c
    branches/gcc-4_5-branch/gcc/testsuite/gcc.dg/torture/pr47890.c
Modified:
    branches/gcc-4_5-branch/gcc/ChangeLog
    branches/gcc-4_5-branch/gcc/testsuite/ChangeLog
    branches/gcc-4_5-branch/gcc/tree-vect-loop.c
    branches/gcc-4_5-branch/gcc/tree-vect-stmts.c
Comment 15 Richard Biener 2011-03-01 17:04:58 UTC
Fixed.