Index: tree-vectorizer.c =================================================================== *** tree-vectorizer.c (revision 122176) --- tree-vectorizer.c (working copy) *************** vect_is_simple_reduction (struct loop *l *** 1935,1948 **** int op_type; tree operation, op1, op2; tree type; if (TREE_CODE (loop_arg) != SSA_NAME) { if (vect_print_dump_info (REPORT_DETAILS)) ! { ! fprintf (vect_dump, "reduction: not ssa_name: "); ! print_generic_expr (vect_dump, loop_arg, TDF_SLIM); ! } return NULL_TREE; } --- 1935,1969 ---- int op_type; tree operation, op1, op2; tree type; + int nloop_uses; + tree name; + imm_use_iterator imm_iter; + use_operand_p use_p; + + name = PHI_RESULT (phi); + nloop_uses = 0; + FOR_EACH_IMM_USE_FAST (use_p, imm_iter, name) + { + tree use_stmt = USE_STMT (use_p); + if (flow_bb_inside_loop_p (loop, bb_for_stmt (use_stmt)) + && vinfo_for_stmt (use_stmt) + && !is_pattern_stmt_p (vinfo_for_stmt (use_stmt))) + nloop_uses++; + if (nloop_uses > 1) + { + if (vect_print_dump_info (REPORT_DETAILS)) + fprintf (vect_dump, "reduction used in loop."); + return NULL_TREE; + } + } if (TREE_CODE (loop_arg) != SSA_NAME) { if (vect_print_dump_info (REPORT_DETAILS)) ! { ! fprintf (vect_dump, "reduction: not ssa_name: "); ! print_generic_expr (vect_dump, loop_arg, TDF_SLIM); ! } return NULL_TREE; } *************** vect_is_simple_reduction (struct loop *l *** 1950,1968 **** if (!def_stmt) { if (vect_print_dump_info (REPORT_DETAILS)) ! fprintf (vect_dump, "reduction: no def_stmt."); return NULL_TREE; } if (TREE_CODE (def_stmt) != GIMPLE_MODIFY_STMT) { if (vect_print_dump_info (REPORT_DETAILS)) ! { ! print_generic_expr (vect_dump, def_stmt, TDF_SLIM); ! } return NULL_TREE; } operation = GIMPLE_STMT_OPERAND (def_stmt, 1); code = TREE_CODE (operation); if (!commutative_tree_code (code) || !associative_tree_code (code)) --- 1971,2004 ---- if (!def_stmt) { if (vect_print_dump_info (REPORT_DETAILS)) ! fprintf (vect_dump, "reduction: no def_stmt."); return NULL_TREE; } if (TREE_CODE (def_stmt) != GIMPLE_MODIFY_STMT) { if (vect_print_dump_info (REPORT_DETAILS)) ! print_generic_expr (vect_dump, def_stmt, TDF_SLIM); return NULL_TREE; } + name = GIMPLE_STMT_OPERAND (def_stmt, 0); + nloop_uses = 0; + FOR_EACH_IMM_USE_FAST (use_p, imm_iter, name) + { + tree use_stmt = USE_STMT (use_p); + if (flow_bb_inside_loop_p (loop, bb_for_stmt (use_stmt)) + && vinfo_for_stmt (use_stmt) + && !is_pattern_stmt_p (vinfo_for_stmt (use_stmt))) + nloop_uses++; + if (nloop_uses > 1) + { + if (vect_print_dump_info (REPORT_DETAILS)) + fprintf (vect_dump, "reduction used in loop."); + return NULL_TREE; + } + } + operation = GIMPLE_STMT_OPERAND (def_stmt, 1); code = TREE_CODE (operation); if (!commutative_tree_code (code) || !associative_tree_code (code))