This PR shows that we weren't filtering out irrelevant stmts in vect_get_peeling_costs_all_drs (unlike related loops in which we iterate over all datarefs).
Tested on aarch64-linux-gnu, x86_64-linux-gnu and powerpc64le-linux-gnu. Installed as obvious. Richard 2017-09-22 Richard Sandiford <richard.sandif...@linaro.org> gcc/ PR tree-optimization/82289 * tree-vect-data-refs.c (vect_get_peeling_costs_all_drs): Check STMT_VINFO_RELEVANT_P. gcc/testsuite/ PR tree-optimization/82289 * gcc.dg/vect/pr82289.c: New test. Index: gcc/tree-vect-data-refs.c =================================================================== --- gcc/tree-vect-data-refs.c 2017-09-22 17:44:23.043135080 +0100 +++ gcc/tree-vect-data-refs.c 2017-09-22 17:50:04.801574308 +0100 @@ -1326,6 +1326,9 @@ vect_get_peeling_costs_all_drs (vec<data { gimple *stmt = DR_STMT (dr); stmt_vec_info stmt_info = vinfo_for_stmt (stmt); + if (!STMT_VINFO_RELEVANT_P (stmt_info)) + continue; + /* For interleaving, only the alignment of the first access matters. */ if (STMT_VINFO_GROUPED_ACCESS (stmt_info) Index: gcc/testsuite/gcc.dg/vect/pr82289.c =================================================================== --- /dev/null 2017-09-22 10:29:41.244937880 +0100 +++ gcc/testsuite/gcc.dg/vect/pr82289.c 2017-09-22 17:50:04.800626671 +0100 @@ -0,0 +1,28 @@ +/* { dg-do compile } */ + +int a, b, c, *d, *f[1]; + +void fn1 (int *j) +{ + int e, g, h = 1; + for (; e; e++) + { + if (g > 0) + { + d = j; + return; + } + if (!h) + while (g) + ; + while (h < 1) + if (a) + { + fn1 (&h); + h = 0; + } + f[e] = &c; + } + while (1) + ; +}