public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH] value-prof.cc: Correct edge prob calculation.
@ 2023-06-15  9:50 Filip Kastl
  2023-07-04 14:33 ` Jan Hubicka
  0 siblings, 1 reply; 2+ messages in thread
From: Filip Kastl @ 2023-06-15  9:50 UTC (permalink / raw)
  To: gcc-patches; +Cc: Filip Kastl

The mod-subtract optimization with ncounts==1 produced incorrect edge
probabilities due to incorrect conditional probability calculation. This
patch fixes the calculation.

gcc/ChangeLog:

	* value-prof.cc (gimple_mod_subtract_transform): Correct edge
	  prob calculation.

Signed-off-by: Filip Kastl <filip.kastl@gmail.com>
---
 gcc/value-prof.cc | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/gcc/value-prof.cc b/gcc/value-prof.cc
index f40e58ac4f2..580d6dd648d 100644
--- a/gcc/value-prof.cc
+++ b/gcc/value-prof.cc
@@ -1186,7 +1186,11 @@ gimple_mod_subtract_transform (gimple_stmt_iterator *si)
   if (all > 0)
     {
       prob1 = profile_probability::probability_in_gcov_type (count1, all);
-      prob2 = profile_probability::probability_in_gcov_type (count2, all);
+      if (all == count1)
+	prob2 = profile_probability::even ();
+      else
+	prob2 = profile_probability::probability_in_gcov_type (count2, all -
+							       count1);
     }
   else
     {
-- 
2.40.1


^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH] value-prof.cc: Correct edge prob calculation.
  2023-06-15  9:50 [PATCH] value-prof.cc: Correct edge prob calculation Filip Kastl
@ 2023-07-04 14:33 ` Jan Hubicka
  0 siblings, 0 replies; 2+ messages in thread
From: Jan Hubicka @ 2023-07-04 14:33 UTC (permalink / raw)
  To: Filip Kastl; +Cc: gcc-patches

> The mod-subtract optimization with ncounts==1 produced incorrect edge
> probabilities due to incorrect conditional probability calculation. This
> patch fixes the calculation.
> 
> gcc/ChangeLog:
> 
> 	* value-prof.cc (gimple_mod_subtract_transform): Correct edge
> 	  prob calculation.

OK,
thanks!
Honza

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2023-07-04 14:33 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-06-15  9:50 [PATCH] value-prof.cc: Correct edge prob calculation Filip Kastl
2023-07-04 14:33 ` Jan Hubicka

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).