value-prof.cc: Correct edge prob calculation.

Message ID 20230615095052.13119-1-filip.kastl@gmail.com
State New
Headers
Series value-prof.cc: Correct edge prob calculation. |

Checks

Context Check Description
linaro-tcwg-bot/tcwg_gcc_build--master-arm success Testing passed
linaro-tcwg-bot/tcwg_gcc_check--master-aarch64 success Testing passed
linaro-tcwg-bot/tcwg_gcc_build--master-aarch64 success Testing passed
linaro-tcwg-bot/tcwg_gcc_check--master-arm success Testing passed

Commit Message

Filip Kastl June 15, 2023, 9:50 a.m. UTC
  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(-)
  

Comments

Jan Hubicka July 4, 2023, 2:33 p.m. UTC | #1
> 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
  

Patch

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
     {