We need to restrict what we handle as last operation in a nested cycle because vectorizable_reduction performs the code-generation in the end.
Boostrap and regtest in progress on x86_64-unknown-linux-gnu. Richard. 2018-11-13 Richard Biener <rguent...@suse.de> PR tree-optimization/87931 * tree-vect-loop.c (vect_is_simple_reduction): Restrict nested cycles we support to latch computations vectorizable_reduction handles. * gcc.dg/graphite/pr87931.c: New testcase. Index: gcc/tree-vect-loop.c =================================================================== --- gcc/tree-vect-loop.c (revision 266061) +++ gcc/tree-vect-loop.c (working copy) @@ -2983,6 +2976,22 @@ vect_is_simple_reduction (loop_vec_info if (nested_in_vect_loop && !check_reduction) { + /* FIXME: Even for non-reductions code generation is funneled + through vectorizable_reduction for the stmt defining the + PHI latch value. So we have to artificially restrict ourselves + for the supported operations. */ + switch (get_gimple_rhs_class (code)) + { + case GIMPLE_BINARY_RHS: + case GIMPLE_TERNARY_RHS: + break; + default: + /* Not supported by vectorizable_reduction. */ + if (dump_enabled_p ()) + report_vect_op (MSG_MISSED_OPTIMIZATION, def_stmt, + "nested cycle: not handled operation: "); + return NULL; + } if (dump_enabled_p ()) report_vect_op (MSG_NOTE, def_stmt, "detected nested cycle: "); return def_stmt_info; Index: gcc/testsuite/gcc.dg/graphite/pr87931.c =================================================================== --- gcc/testsuite/gcc.dg/graphite/pr87931.c (nonexistent) +++ gcc/testsuite/gcc.dg/graphite/pr87931.c (working copy) @@ -0,0 +1,22 @@ +/* { dg-do compile } */ +/* { dg-options "-O3 -fno-tree-copy-prop -fgraphite-identity" } */ + +#define N 40 +#define M 128 +float in[N+M]; +float coeff[M]; +float fir_out[N]; + +void fir () +{ + int i,j,k; + float diff; + + for (i = 0; i < N; i++) { + diff = 0; + for (j = 0; j < M; j++) { + diff += in[j+i]*coeff[j]; + } + fir_out[i] = diff; + } +}