diff options
-rw-r--r-- | gcc/cfgloopmanip.cc | 15 | ||||
-rw-r--r-- | gcc/testsuite/gcc.dg/tree-ssa/vect-profile-upate.c | 9 | ||||
-rw-r--r-- | gcc/tree-vect-loop-manip.cc | 2 |
3 files changed, 21 insertions, 5 deletions
diff --git a/gcc/cfgloopmanip.cc b/gcc/cfgloopmanip.cc index 524b979..f56a9b8 100644 --- a/gcc/cfgloopmanip.cc +++ b/gcc/cfgloopmanip.cc @@ -548,18 +548,23 @@ scale_loop_profile (class loop *loop, profile_probability p, profile_count count_in = profile_count::zero (); edge e; edge_iterator ei; + bool found_latch = false; FOR_EACH_EDGE (e, ei, loop->header->preds) - count_in += e->count (); + if (e->src != loop->latch) + count_in += e->count (); + else + found_latch = true; + gcc_checking_assert (found_latch); /* Now scale the loop body so header count is count_in * (iteration_bound + 1) */ profile_probability scale_prob - = (count_in *= iteration_bound).probability_in (loop->header->count); + = (count_in * (iteration_bound + 1)).probability_in (loop->header->count); if (dump_file && (dump_flags & TDF_DETAILS)) { fprintf (dump_file, ";; Scaling loop %i with scale ", loop->num); - p.dump (dump_file); + scale_prob.dump (dump_file); fprintf (dump_file, " to reach upper bound %i\n", (int)iteration_bound); } @@ -593,7 +598,6 @@ scale_loop_profile (class loop *loop, profile_probability p, bool found = false; FOR_EACH_EDGE (e, ei, exit_edge->src->succs) if (!(e->flags & EDGE_FAKE) - && !(e->probability == profile_probability::never ()) && !loop_exit_edge_p (loop, e)) { if (found) @@ -617,7 +621,8 @@ scale_loop_profile (class loop *loop, profile_probability p, for (unsigned int i = 0; i < loop->num_nodes; i++) if (body[i] != exit_edge->src && dominated_by_p (CDI_DOMINATORS, body[i], exit_edge->src)) - body[i]->count.apply_scale (new_count, old_count); + body[i]->count = body[i]->count.apply_scale (new_count, + old_count); free (body); } diff --git a/gcc/testsuite/gcc.dg/tree-ssa/vect-profile-upate.c b/gcc/testsuite/gcc.dg/tree-ssa/vect-profile-upate.c new file mode 100644 index 0000000..72cc428 --- /dev/null +++ b/gcc/testsuite/gcc.dg/tree-ssa/vect-profile-upate.c @@ -0,0 +1,9 @@ +/* { dg-do compile } */ +/* { dg-options "-O2 -fdump-tree-optimized-details-blocks" } */ +int a[99]; +void test() +{ + for (int i = 0; i < 99; i++) + a[i]++; +} +/* { dg-final { scan-tree-dump-not "Invalid sum" "optimized"} } */ diff --git a/gcc/tree-vect-loop-manip.cc b/gcc/tree-vect-loop-manip.cc index 2361cb3..30baac6 100644 --- a/gcc/tree-vect-loop-manip.cc +++ b/gcc/tree-vect-loop-manip.cc @@ -3389,6 +3389,8 @@ vect_do_peeling (loop_vec_info loop_vinfo, tree niters, tree nitersm1, gcc_assert (bound != 0); /* -1 to convert loop iterations to latch iterations. */ record_niter_bound (epilog, bound - 1, false, true); + scale_loop_profile (epilog, profile_probability::always (), + bound - 1); } delete_update_ssa (); |