This fixes PR60836 by emitting a non-proper PHI argument to the incoming edge.
Bootstrapped and tested on x86_64-unknown-linux-gnu, applied to trunk. Richard. 2014-04-16 Richard Biener <rguent...@suse.de> PR tree-optimization/60836 * tree-vect-loop.c (vect_create_epilog_for_reduction): Force initial PHI args to be gimple values. * g++.dg/vect/pr60836.cc: New testcase. Index: gcc/tree-vect-loop.c =================================================================== *** gcc/tree-vect-loop.c (revision 209423) --- gcc/tree-vect-loop.c (working copy) *************** vect_create_epilog_for_reduction (vec<tr *** 3951,3958 **** /* Set phi nodes arguments. */ FOR_EACH_VEC_ELT (reduction_phis, i, phi) { ! tree vec_init_def = vec_initial_defs[i]; ! tree def = vect_defs[i]; for (j = 0; j < ncopies; j++) { /* Set the loop-entry arg of the reduction-phi. */ --- 3952,3963 ---- /* Set phi nodes arguments. */ FOR_EACH_VEC_ELT (reduction_phis, i, phi) { ! tree vec_init_def, def; ! gimple_seq stmts; ! vec_init_def = force_gimple_operand (vec_initial_defs[i], &stmts, ! true, NULL_TREE); ! gsi_insert_seq_on_edge_immediate (loop_preheader_edge (loop), stmts); ! def = vect_defs[i]; for (j = 0; j < ncopies; j++) { /* Set the loop-entry arg of the reduction-phi. */ Index: gcc/testsuite/g++.dg/vect/pr60836.cc =================================================================== *** gcc/testsuite/g++.dg/vect/pr60836.cc (revision 0) --- gcc/testsuite/g++.dg/vect/pr60836.cc (working copy) *************** *** 0 **** --- 1,39 ---- + // { dg-do compile } + + int a, b; + typedef double (*NormFunc) (const int &); + int & + max (int &p1, int &p2) + { + if (p1 < p2) + return p2; + return p1; + } + + struct A + { + int operator () (int p1, int p2) + { + return max (p1, p2); + } + }; + template < class, class > double + norm_ (const int &) + { + char c, d; + A e; + for (; a; a++) + { + b = e (b, d); + b = e (b, c); + } + } + + void + norm () + { + static NormFunc f = norm_ < int, A >; + f = 0; + } + + // { dg-final { cleanup-tree-dump "vect" } }