Bug 56270 - [4.6 Regression] loop over array of struct float causes compiler error: segmentation fault
Summary: [4.6 Regression] loop over array of struct float causes compiler error: segme...
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: tree-optimization (show other bugs)
Version: 4.7.2
: P3 normal
Target Milestone: 4.7.3
Assignee: Richard Biener
URL:
Keywords: ice-on-valid-code
Depends on: 56531
Blocks:
  Show dependency treegraph
 
Reported: 2013-02-09 23:41 UTC by Norbert B
Modified: 2013-04-12 16:29 UTC (History)
1 user (show)

See Also:
Host:
Target:
Build:
Known to work: 4.3.6, 4.7.3, 4.8.0
Known to fail: 4.7.2
Last reconfirmed: 2013-03-04 00:00:00


Attachments
Preprocessed file, comment, compiler call, compiler configuration (2.23 KB, application/octet-stream)
2013-02-09 23:41 UTC, Norbert B
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Norbert B 2013-02-09 23:41:18 UTC
Created attachment 29408 [details]
Preprocessed file, comment, compiler call, compiler configuration

Compiling a loop over an array of struct with members of type float leads to:
internal compiler error: Segmentation Fault

Occurs optimizing with -O3

Affected gcc versions: 4.7.2, 4.6.3, 4.6.1, 4.5.2 (at least)
NOT affected versions: 3.4.3 (at least)

Platforms: Solaris 11.1, Ubuntu 12.04.2 LTS (precise), Linux Mint 12 (Lisa);
(Ubuntu and LinuxMint in Virtual Box)

Solaris uname -a: SunOS xxx 5.11 11.1 i86pc i386 i86pc
Ubuntu uname -a Linux xxx 3.2.0-37-generic #58-Ubuntu SMP Thu Jan 24 15:28:10 UTC 2013 x86_64 x86_64 x86_64 GNU/Linux
LinuxMint uname -a: Linux xxx 3.0.0-12-generic #20-Ubuntu SMP Fri Oct 7 14:56:25 UTC 2011 x86_64 x86_64 x86_64 GNU/Linux


Attachment contains preprocessed file and further information
Comment 1 Andrew Pinski 2013-02-09 23:47:26 UTC
pinskia@server:~/src/local$ ~/local-gcc/bin/x86_64-unknown-linux-gnu-gcc-4.7.0 -O3  t.c 
mbb.c: In function ‘Compute’:
mbb.c:33:6: internal compiler error: vector VEC(tree,base) index domain error, in vectorizable_store at tree-vect-stmts.c:3920
Please submit a full bug report,
with preprocessed source if appropriate.
See <http://gcc.gnu.org/bugs.html> for instructions.


But works on the trunk.
Comment 2 Mikael Pettersson 2013-03-03 19:43:14 UTC
This was fixed for 4.8 by Jan Hubicka's r193175, which rewrote finite_loop_p in tree-ssa-loop-niter.c.  That patch doesn't work as-is in 4.7.2 (it applies but uses other things which aren't in 4.7.2.)

The SEGV in 4.7.2 occurs in tree-vect-stmts.c:3938

3938              gcc_assert (useless_type_conversion_p (vectype,
3939                                                     TREE_TYPE (vec_oprnd)));

because vec_oprnd is NULL at that point.
Comment 3 Richard Biener 2013-03-04 10:56:51 UTC
Confirmed.  Probably a latent issue on trunk.  Mine.
Comment 4 Richard Biener 2013-03-04 13:05:19 UTC
Also ICEs on trunk for me with -O1 -ftree-vectorize.  Works with 4.3 at least.
Comment 5 Richard Biener 2013-03-04 13:13:58 UTC
Reduced testcase:

typedef struct {
    float l, h;
} tFPinterval;

tFPinterval X[1024];
tFPinterval Y[1024];
tFPinterval Z[1024];

void Compute(void)
{
  int d;
  for (d= 0; d < 1024; d++)
    {
      Y[d].l= X[d].l + X[d].h;
      Y[d].h= Y[d].l;
      Z[d].l= X[d].l;
      Z[d].h= X[d].h;
    }
}
Comment 6 Richard Biener 2013-03-04 14:19:37 UTC
We don't properly "vectorize" the 2nd reference to the load (this time
unpermuted).  When vectorizing the 2nd SLP instance with that reference
we encounter

      /* Check if the chain of loads is already vectorized.  */
      if (STMT_VINFO_VEC_STMT (vinfo_for_stmt (first_stmt)))
        {
          *vec_stmt = STMT_VINFO_VEC_STMT (stmt_info);
          return true;
        }

but that leaves SLP_TREE_VEC_STMTS unpopulated.  Shared nodes between SLP instances seem to be somewhat fragile ...

Especially in this case in which even wrong-code would occur as the
instances do not share the same permutation.

      if (slp
          && !SLP_INSTANCE_LOAD_PERMUTATION (slp_node_instance).exists ()
          && first_stmt != SLP_TREE_SCALAR_STMTS (slp_node)[0])
        first_stmt = SLP_TREE_SCALAR_STMTS (slp_node)[0];

also doesn't make much sense to me - instead it probably should be asserted:

      if (slp
          && first_stmt != SLP_TREE_SCALAR_STMTS (slp_node)[0])
        gcc_assert (SLP_INSTANCE_LOAD_PERMUTATION (slp_node_instance).exists ())

but bb-slp-29.c asserts here.

Easiest is for now to clear STMT_VINFO_VEC_STMT for all loads after
scheduling an SLP instance.
Comment 7 Richard Biener 2013-03-05 09:54:43 UTC
Author: rguenth
Date: Tue Mar  5 09:54:29 2013
New Revision: 196458

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=196458
Log:
2013-03-05  Richard Biener  <rguenther@suse.de>

	PR tree-optimization/56270
	* tree-vect-slp.c (vect_schedule_slp): Clear vectorized stmts
	of loads after scheduling an SLP instance.

	* gcc.dg/vect/slp-38.c: New testcase.

Added:
    trunk/gcc/testsuite/gcc.dg/vect/slp-38.c
Modified:
    trunk/gcc/ChangeLog
    trunk/gcc/testsuite/ChangeLog
    trunk/gcc/tree-vect-slp.c
Comment 8 Richard Biener 2013-03-05 09:55:18 UTC
Fixed on trunk sofar.
Comment 9 Richard Biener 2013-03-26 10:15:31 UTC
Author: rguenth
Date: Tue Mar 26 10:12:52 2013
New Revision: 197096

URL: http://gcc.gnu.org/viewcvs?rev=197096&root=gcc&view=rev
Log:
2013-03-26  Richard Biener  <rguenther@suse.de>

        Backport from mainline
        2013-03-13  Richard Biener  <rguenther@suse.de>

	PR tree-optimization/56608
	* tree-vect-slp.c (vect_schedule_slp): Do not remove scalar
	calls when vectorizing basic-blocks.

	* gcc.dg/vect/fast-math-bb-slp-call-3.c: New testcase.

        2013-03-05  Richard Biener  <rguenther@suse.de>

	PR tree-optimization/56270
	* tree-vect-slp.c (vect_schedule_slp): Clear vectorized stmts
	of loads after scheduling an SLP instance.

	* gcc.dg/vect/slp-38.c: New testcase.

Added:
    branches/gcc-4_7-branch/gcc/testsuite/gcc.dg/vect/fast-math-bb-slp-call-3.c
    branches/gcc-4_7-branch/gcc/testsuite/gcc.dg/vect/slp-38.c
Modified:
    branches/gcc-4_7-branch/gcc/ChangeLog
    branches/gcc-4_7-branch/gcc/testsuite/ChangeLog
    branches/gcc-4_7-branch/gcc/tree-vect-slp.c
Comment 10 Jakub Jelinek 2013-04-12 16:29:08 UTC
The 4.6 branch has been closed, fixed in GCC 4.7.3.