On Tue, Feb 21, 2017 at 3:49 PM, Jan Hubicka wrote: >> 2017-02-21 Bin Cheng >> >> PR tree-optimization/77536 >> * tree-ssa-loop-manip.c (niter_for_unrolled_loop): New function. >> (tree_transform_and_unroll_loop): Use above function to compute the >> estimated niter of unrolled loop and use it when scaling profile. >> * tree-ssa-loop-manip.h niter_for_unrolled_loop(): New declaration. >> * tree-vect-loop.c (scale_profile_for_vect_loop): New function. >> (vect_transform_loop): Call above function. >> >> gcc/testsuite/ChangeLog >> 2017-02-21 Bin Cheng >> >> PR tree-optimization/77536 >> * gcc.dg/vect/pr79347.c: Revise testing string. >> @@ -1329,7 +1339,12 @@ tree_transform_and_unroll_loop (struct loop *loop, unsigned factor, >> freq_h = loop->header->frequency; >> freq_e = EDGE_FREQUENCY (loop_preheader_edge (loop)); >> if (freq_h != 0) >> - scale_loop_frequencies (loop, freq_e * (new_est_niter + 1), freq_h); >> + { >> + gcov_type scale; >> + /* This should not overflow. */ >> + scale = GCOV_COMPUTE_SCALE (freq_e * (new_est_niter + 1), freq_h); >> + scale_loop_frequencies (loop, scale, REG_BR_PROB_BASE); > > You need to use counts counts when new_est_niter is derrived from profile feedback. > This is because frequencies are capped to 10000, so if loop iterates very many times, > new_est_niter will be large, freq_h will be 10000 and freq_e will be 0. > > Also watch the case when freq_e==loop_preheader_edge (loop)->count==0 and freq_h > is non-zero. Just do MAX (freq_e, 1). This will not drop the loop body profile to 0. > >> +/* Scale profiling counters by estimation for LOOP which is vectorized >> + by factor VF. */ >> + >> +static void >> +scale_profile_for_vect_loop (struct loop *loop, unsigned vf) >> +{ >> + edge preheader = loop_preheader_edge (loop); >> + unsigned freq_h = loop->header->frequency; >> + unsigned freq_e = EDGE_FREQUENCY (preheader); >> + /* Reduce loop iterations by the vectorization factor. */ >> + gcov_type new_est_niter = niter_for_unrolled_loop (loop, vf); >> + >> + /* Use profiling count information if frequencies are zero. */ >> + if (freq_h == 0 || freq_e == 0) >> + { >> + freq_e = preheader->count; >> + freq_h = loop->header->count; >> + } >> + >> + if (freq_h != 0) >> + { >> + gcov_type scale; >> + /* This should not overflow. */ >> + scale = GCOV_COMPUTE_SCALE (freq_e * (new_est_niter + 1), freq_h); >> + scale_loop_frequencies (loop, scale, REG_BR_PROB_BASE); >> + } > > Similarly here. Use counts when they are non-zero and use MAX (freq_e, 1). > freq_e/freq_h needs to be gcov_type in that case. > > Patch is OK with these changes. Thanks a lot! Hi Honza, There is the 3rd version patch fixing mentioned issues. Is it OK? Thanks, bin