From: "Martin Liška" <mliska@suse.cz>
To: Jan Hubicka <hubicka@kam.mff.cuni.cz>
Cc: gcc-patches@gcc.gnu.org
Subject: Re: [PATCH] Add operators / and * for profile_{count,probability}.
Date: Tue, 24 May 2022 13:35:35 +0200 [thread overview]
Message-ID: <e5e4cbfb-9935-fc36-82f4-61a57811dd56@suse.cz> (raw)
In-Reply-To: <6bb9ea88-d14a-a22e-ca6b-1609ba5b8b76@suse.cz>
PING^1
On 5/5/22 20:15, Martin Liška wrote:
> On 5/5/22 15:49, Jan Hubicka wrote:
>> Hi,
>>> The patch simplifies usage of the profile_{count,probability} types.
>>>
>>> Patch can bootstrap on x86_64-linux-gnu and survives regression tests.
>>>
>>> Ready to be installed?
>>
>> The reason I intentionally did not add * and / to the original API was
>> to detect situations where values that should be
>> profile_count/profile_probability are stored into integers, since
>> previous code used integers for everything.
>>
>> Having one to add apply_scale made him/her (mostly me :) to think if the
>> value is really just a fixed scale or it it should be better converted
>> to proper data type (count or probability).
>>
>> I guess now we completed the conversion so risk of this creeping in is
>> relatively low and the code indeed looks better.
>
> Yes, that's my impression as well that the profiling code is quite settled down.
>
>> It will make it bit
>> harder for me to backport jump threading profile updating fixes I plan
>> for 12.2 but it should not be hard.
>
> You'll manage ;)
>
>>> diff --git a/gcc/cfgloopmanip.cc b/gcc/cfgloopmanip.cc
>>> index b4357c03e86..a1ac1146445 100644
>>> --- a/gcc/cfgloopmanip.cc
>>> +++ b/gcc/cfgloopmanip.cc
>>> @@ -563,8 +563,7 @@ scale_loop_profile (class loop *loop, profile_probability p,
>>>
>>> /* Probability of exit must be 1/iterations. */
>>> count_delta = e->count ();
>>> - e->probability = profile_probability::always ()
>>> - .apply_scale (1, iteration_bound);
>>> + e->probability = profile_probability::always () / iteration_bound;
>> However this is kind of example of the problem.
>> iteration_bound is gcov_type so we can get overflow here.
>
> typedef int64_t gcov_type;
>
> and apply_scale takes int64_t types as arguments. Similarly the newly added operators,
> so how can that change anything?
>
>> I guess we want to downgrade iteration_bound since it is always either 0
>> or int.
>>> diff --git a/gcc/tree-switch-conversion.cc b/gcc/tree-switch-conversion.cc
>>> index e14b4e6c94a..cef26a9878e 100644
>>> --- a/gcc/tree-switch-conversion.cc
>>> +++ b/gcc/tree-switch-conversion.cc
>>> @@ -1782,7 +1782,7 @@ switch_decision_tree::analyze_switch_statement ()
>>> tree high = CASE_HIGH (elt);
>>>
>>> profile_probability p
>>> - = case_edge->probability.apply_scale (1, (intptr_t) (case_edge->aux));
>>> + = case_edge->probability / ((intptr_t) (case_edge->aux));
>>
>> I think the switch ranges may be also in risk of overflow?
>>
>> We could make operators to accept gcov_type or int64_t.
>
> As explained, they do.
>
> Cheers,
> Martin
>
>>
>> Thanks,
>> Honza
>
next prev parent reply other threads:[~2022-05-24 11:35 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-05-05 12:17 Martin Liška
2022-05-05 13:49 ` Jan Hubicka
2022-05-05 18:15 ` Martin Liška
2022-05-24 11:35 ` Martin Liška [this message]
2022-06-16 6:21 ` Martin Liška
2022-06-17 14:19 ` Jan Hubicka
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=e5e4cbfb-9935-fc36-82f4-61a57811dd56@suse.cz \
--to=mliska@suse.cz \
--cc=gcc-patches@gcc.gnu.org \
--cc=hubicka@kam.mff.cuni.cz \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).