From: Jan Hubicka <hubicka@ucw.cz>
To: gcc-patches@gcc.gnu.org
Subject: Fix profile update in duplicat_loop_body_to_header_edge for loops with 0 count_in
Date: Thu, 10 Aug 2023 19:03:44 +0200 [thread overview]
Message-ID: <ZNUYcP4Lm1v7fps9@kam.mff.cuni.cz> (raw)
Hi,
this patch makes duplicate_loop_body_to_header_edge to not drop profile counts to
uninitialized when count_in is 0. This happens because profile_probability in 0 count
is undefined.
Bootstrapped/regtested x86_64-linux, committed.
gcc/ChangeLog:
* cfgloopmanip.cc (duplicate_loop_body_to_header_edge): Special case loops with
0 iteration count.
diff --git a/gcc/cfgloopmanip.cc b/gcc/cfgloopmanip.cc
index b237ad4e8ac..a2ed54a23bb 100644
--- a/gcc/cfgloopmanip.cc
+++ b/gcc/cfgloopmanip.cc
@@ -1296,6 +1296,16 @@ duplicate_loop_body_to_header_edge (class loop *loop, edge e,
}
profile_probability prob_pass_wont_exit =
new_count_le.probability_in (count_in);
+ /* If profile count is 0, the probability will be uninitialized.
+ We can set probability to any initialized value to avoid
+ precision loss. If profile is sane, all counts will be 0 anyway. */
+ if (!count_in.nonzero_p ())
+ {
+ prob_pass_thru
+ = profile_probability::always ().apply_scale (1, 2);
+ prob_pass_wont_exit
+ = profile_probability::always ().apply_scale (1, 2);
+ }
scale_step = XNEWVEC (profile_probability, ndupl);
@@ -1306,7 +1316,9 @@ duplicate_loop_body_to_header_edge (class loop *loop, edge e,
/* Complete peeling is special as the probability of exit in last
copy becomes 1. */
- if (flags & DLTHE_FLAG_COMPLETTE_PEEL)
+ if (!count_in.nonzero_p ())
+ ;
+ else if (flags & DLTHE_FLAG_COMPLETTE_PEEL)
{
profile_count wanted_count = e->count ();
reply other threads:[~2023-08-10 17:03 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
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=ZNUYcP4Lm1v7fps9@kam.mff.cuni.cz \
--to=hubicka@ucw.cz \
--cc=gcc-patches@gcc.gnu.org \
/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).