I noticed this while working on a rs6000 back-end patch and was questioning how I could have caused this failure and then I noticed it was a GC issue and could be reproduced without my patch. Anyways here is the testcase reduced from vect-outer-4m.c: unsigned short in[40 +128]; int main (void) { int i = 0, j = 0; unsigned int diff; unsigned int s=0,sum=0; for (i = 0; i < 40;i++) { diff = 0; for (j = 0; j < 128;j+=8) diff += in[j+i]; s += ((unsigned short)diff>>3); } if (s != sum) abort (); } --- CUT --- Compile with -O2 -ftree-vectorize --param ggc-min-expand=0 --param ggc-min-heapsize=0 -maltivec to reproduce the bug.
The problem is const_vector_from_tree called on: <vector_cst 0x7ffff3375e10 type <vector_type 0x7ffff33ed540 __vector signed int type <integer_type 0x7ffff332d540 int sizes-gimplified public SI size <integer_cst 0x7ffff3319930 constant 32> unit size <integer_cst 0x7ffff33195a0 constant 4> align 32 symtab 0 alias set -1 canonical type 0x7ffff332d540 precision 32 min <integer_cst 0x7ffff33198a0 -2147483648> max <integer_cst 0x7ffff33198d0 2147483647> pointer_to_this <pointer_type 0x7ffff333c9c0>> V4SI size <integer_cst 0x7ffff3319c90 constant 128> unit size <integer_cst 0x7ffff3319cc0 constant 16> align 128 symtab 0 alias set -1 canonical type 0x7ffff33ed540 nunits 4> constant elt0: <integer_cst 0x7ffff3352570 type <integer_type 0x7ffff332d540 int> constant 3> elt1: <integer_cst 0x7ffff3352570 3> elt2: <integer_cst 0x7ffff3352570 3> elt3: <integer_cst 0x7ffff3352570 3> elt4: <integer_cst 0x7ffff3352570 3> elt5: <integer_cst 0x7ffff3352570 3> elt6: <integer_cst 0x7ffff3352570 3> elt7: <integer_cst 0x7ffff3352570 3>> Note V4SImode, yet 8 elements. This allocates a vector with rtvec_alloc (4), yet fills in 8 elements. Looking what creates it.
vect_get_vec_def_for_operand has: tree vectype = STMT_VINFO_VECTYPE (stmt_vinfo); int nunits = TYPE_VECTOR_SUBPARTS (vectype); ... /* Case 1: operand is a constant. */ case vect_constant_def: ... for (i = nunits - 1; i >= 0; --i) { t = tree_cons (NULL_TREE, op, t); } vector_type = get_vectype_for_scalar_type (TREE_TYPE (op)); gcc_assert (vector_type); vec_cst = build_vector (vector_type, t); and similarly in a few other cases. vectype in this case is V8HI, but op is SImode, so nunits is 8, yet vector_type has just 4 units.
happens during outer-loop vectorization. I'm looking into it.
Subject: Bug 37574 Author: dorit Date: Fri Sep 26 06:28:01 2008 New Revision: 140685 URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=140685 Log: PR tree-optimization/37574 * tree-vectorizer.c (vect_is_simple_use): Fix indentation. * tree-vect-transform.c (vect_get_constant_vectors): Use vectype instead of vector_type for constants. Take computation out of loop. (vect_get_vec_def_for_operand): Use only vectype for constant case, and use only vector_type for invariant case. (get_initial_def_for_reduction): Use vectype instead of vector_type. Added: trunk/gcc/testsuite/gcc.dg/vect/ggc-pr37574.c Modified: trunk/gcc/ChangeLog trunk/gcc/testsuite/ChangeLog trunk/gcc/testsuite/gcc.dg/vect/vect.exp trunk/gcc/tree-vect-transform.c trunk/gcc/tree-vectorizer.c
Fixed.