Here is a patch that should fix this bug. Can somebody test that it fixes it?
Thanks, Sebastian
Index: tree-loop-linear.c =================================================================== --- tree-loop-linear.c (revision 140668) +++ tree-loop-linear.c (working copy) @@ -333,11 +333,16 @@ linear_transform_loops (void) lambda_loopnest before, after; lambda_trans_matrix trans; struct obstack lambda_obstack; + struct loop *loop; + VEC(loop_p,heap) *nest = VEC_alloc (loop_p, heap, 3); depth = perfect_loop_nest_depth (loop_nest); if (depth == 0) continue; + for (loop = loop_nest; loop; loop = loop->inner) + VEC_safe_push (loop_p, heap, nest, loop); + gcc_obstack_init (&lambda_obstack); VEC_truncate (tree, oldivs, 0); VEC_truncate (tree, invariants, 0); @@ -350,8 +355,7 @@ linear_transform_loops (void) goto free_and_continue; lambda_collect_parameters (datarefs, &lambda_parameters); - if (!lambda_compute_access_matrices (datarefs, lambda_parameters, - loop_nest->num)) + if (!lambda_compute_access_matrices (datarefs, lambda_parameters, nest)) goto free_and_continue; if (dump_file && (dump_flags & TDF_DETAILS)) @@ -410,6 +414,7 @@ linear_transform_loops (void) obstack_free (&lambda_obstack, NULL); free_dependence_relations (dependence_relations); free_data_refs (datarefs); + VEC_free (loop_p, heap, nest); } for (i = 0; VEC_iterate (gimple, remove_ivs, i, oldiv_stmt); i++) Index: tree-data-ref.h =================================================================== --- tree-data-ref.h (revision 140668) +++ tree-data-ref.h (working copy) @@ -128,13 +128,13 @@ typedef struct scop *scop_p; */ struct access_matrix { - int loop_nest_num; + VEC (loop_p, heap) *loop_nest; int nb_induction_vars; VEC (tree, heap) *parameters; VEC (lambda_vector, heap) *matrix; }; -#define AM_LOOP_NEST_NUM(M) (M)->loop_nest_num +#define AM_LOOP_NEST(M) (M)->loop_nest #define AM_NB_INDUCTION_VARS(M) (M)->nb_induction_vars #define AM_PARAMETERS(M) (M)->parameters #define AM_MATRIX(M) (M)->matrix @@ -149,8 +149,14 @@ struct access_matrix static inline int am_vector_index_for_loop (struct access_matrix *access_matrix, int loop_num) { - gcc_assert (loop_num >= AM_LOOP_NEST_NUM (access_matrix)); - return loop_num - AM_LOOP_NEST_NUM (access_matrix); + int i; + loop_p l; + + for (i = 0; VEC_iterate (loop_p, AM_LOOP_NEST (access_matrix), i, l); i++) + if (l->num == loop_num) + return i; + + gcc_unreachable(); } int access_matrix_get_index_for_parameter (tree, struct access_matrix *); @@ -581,7 +587,7 @@ bool lambda_transform_legal_p (lambda_tr void lambda_collect_parameters (VEC (data_reference_p, heap) *, VEC (tree, heap) **); bool lambda_compute_access_matrices (VEC (data_reference_p, heap) *, - VEC (tree, heap) *, int); + VEC (tree, heap) *, VEC (loop_p, heap) *); /* In tree-data-ref.c */ void split_constant_offset (tree , tree *, tree *); Index: lambda-code.c =================================================================== --- lambda-code.c (revision 140668) +++ lambda-code.c (working copy) @@ -2786,17 +2786,15 @@ av_for_af (tree access_fun, lambda_vecto static bool build_access_matrix (data_reference_p data_reference, - VEC (tree, heap) *parameters, int loop_nest_num) + VEC (tree, heap) *parameters, VEC (loop_p, heap) *nest) { struct access_matrix *am = GGC_NEW (struct access_matrix); unsigned i, ndim = DR_NUM_DIMENSIONS (data_reference); - struct loop *loop = gimple_bb (DR_STMT (data_reference))->loop_father; - struct loop *loop_nest = get_loop (loop_nest_num); - unsigned nivs = loop_depth (loop) - loop_depth (loop_nest) + 1; + unsigned nivs = VEC_length (loop_p, nest); unsigned lambda_nb_columns; lambda_vector_vec_p matrix; - AM_LOOP_NEST_NUM (am) = loop_nest_num; + AM_LOOP_NEST (am) = nest; AM_NB_INDUCTION_VARS (am) = nivs; AM_PARAMETERS (am) = parameters; @@ -2824,13 +2822,13 @@ build_access_matrix (data_reference_p da bool lambda_compute_access_matrices (VEC (data_reference_p, heap) *datarefs, VEC (tree, heap) *parameters, - int loop_nest_num) + VEC (loop_p, heap) *nest) { data_reference_p dataref; unsigned ix; for (ix = 0; VEC_iterate (data_reference_p, datarefs, ix, dataref); ix++) - if (!build_access_matrix (dataref, parameters, loop_nest_num)) + if (!build_access_matrix (dataref, parameters, nest)) return false; return true;