if (final_iv)
{
- gassign *assign = gimple_build_assign (final_iv, MINUS_EXPR,
- indx_after_incr, init);
- gsi_insert_on_edge_immediate (single_exit (loop), assign);
+ gassign *assign;
+ edge exit = single_exit (loop);
+ gcc_assert (single_pred_p (exit->dest));
+ tree phi_dest
+ = integer_zerop (init) ? final_iv : copy_ssa_name (indx_after_incr);
+ /* Make sure to maintain LC SSA form here and elide the subtraction
+ if the value is zero. */
+ gphi *phi = create_phi_node (phi_dest, exit->dest);
+ add_phi_arg (phi, indx_after_incr, exit, UNKNOWN_LOCATION);
+ if (!integer_zerop (init))
+ {
+ assign = gimple_build_assign (final_iv, MINUS_EXPR,
+ phi_dest, init);
+ gimple_stmt_iterator gsi = gsi_after_labels (exit->dest);
+ gsi_insert_before (&gsi, assign, GSI_SAME_STMT);
+ }
}
return cond_stmt;