On 2021-06-15 12:57, guojiufu via Gcc-patches wrote:
On 2021-06-14 17:16, Jan Hubicka wrote:


On 5/6/2021 8:36 PM, guojiufu via Gcc-patches wrote:
> Gentle ping.
>
> Original message:
> https://gcc.gnu.org/pipermail/gcc-patches/2020-October/555871.html
I think you need a more aggressive ping  :-)

OK for the trunk.  Sorry for the long delay.  I kept hoping someone else
would step in and look at it.
Sorry, the patch was on my todo list to think through for a while :(
It seems to me that both old and new code needs bit more work.  First
the exit loop frequency is set to

prob = profile_probability::always ().apply_scale (1, new_est_niter + 1);

which is only correct if the estimated number of iterations is accurate. If we do not have profile feedback and trip count is not known precisely
in most cases it won't be.  We estimate loops to iterate about 3 times
and then niter_for_unrolled_loop will apply the capping to 5 iterations
that is completely arbitrary.

Forcing exit probability to precise may then disable futher loop
optimizations since after the change we will think we know the loop
iterates 5 times and thus it is not worthy for loop opt (which is quite oposite with the fact that we are just unrolling it thinking it is hot).

Thanks, understand your concern, both new and old code are assuming the
the number of iterations is accurate.
Maybe we could add code to reset exit probability for the case
where "!count_in.reliable_p ()".


Old code does
 1) scale body down so only one iteration is done
 2) set exit edge probability to be 1/(new_est_iter+1)
    precisely
 3) scale up accoring to the 1/new_nonexit_prob
    which would be correct if the nonexit probability was updated to
    1-exit_probability but that does not seem to happen.

New code does
Yes, this is intended: we know that the enter-count should be
equal to the exit-count of one loop, and then the
"loop-body-count * exit-probability = exit-count".
Also, the entry count of the loop would not be changed before and after
one optimization (or slightly change,e.g. peeling count).

Based on this, we could adjust the loop body count according to
exit-count (or say enter-count) and exit-probability, when the
exit-probability is easy to estimate.

 1) give up when there are multiple exits.
    I wonder how common this is - we do outer loop vectorizaiton

The computation in the new code is based on a single exit. This is
also a requirement of old code, and it would be true when run to here.

To support multiple exits, I'm thinking about the way to calculate the
count/probability for each basic_block and each exit edge. While it seems the count/prob may not scale up on the same ratio. This is another reason
I give up these cases with multi-exits.

Any suggestions about supporting these cases?


BR,
Jiufu Guo


 2) adjust loop body count according to the exit
 3) updat profile of BB after the exit edge.



Why do you need:
+  if (current_ir_type () != IR_GIMPLE)
+    update_br_prob_note (exit->src);

It is tree_transform_and_unroll_loop, so I think we should always have
IR_GIMPLE?

These two lines are added to "recompute_loop_frequencies" which can be used
in rtl, like the second patch of this:
https://gcc.gnu.org/pipermail/gcc-patches/2020-October/555872.html
Oh, maybe these two lines code would be put to tree_transform_and_unroll_loop
instead of common code recompute_loop_frequencies.

Thanks a lot for the review in your busy time!

BR.
Jiufu Guo

Honza

jeff

Reply via email to