@@ -9750,8 +9750,15 @@ vect_schedule_slp_node (vec_info *vinfo,
{
gimple_stmt_iterator si2
= gsi_after_labels (LOOP_VINFO_LOOP (loop_vinfo)->header);
- if (last_stmt != *si2
- && vect_stmt_dominates_stmt_p (last_stmt, *si2))
+ if ((gsi_end_p (si2)
+ && (LOOP_VINFO_LOOP (loop_vinfo)->header
+ != gimple_bb (last_stmt))
+ && dominated_by_p (CDI_DOMINATORS,
+ LOOP_VINFO_LOOP (loop_vinfo)->header,
+ gimple_bb (last_stmt)))
+ || (!gsi_end_p (si2)
+ && last_stmt != *si2
+ && vect_stmt_dominates_stmt_p (last_stmt, *si2)))
si = si2;
}
}