public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc(refs/users/kubaneko/heads/histogram)] change of peeled probabilities
@ 2023-04-03 13:42 Ondrej Kubanek
  0 siblings, 0 replies; only message in thread
From: Ondrej Kubanek @ 2023-04-03 13:42 UTC (permalink / raw)
  To: gcc-cvs

https://gcc.gnu.org/g:6e7dfd5a75e8abbac97ca36dfa1c373cc9bf0a61

commit 6e7dfd5a75e8abbac97ca36dfa1c373cc9bf0a61
Author: kubaneko <kubanek0ondrej@gmail.com>
Date:   Sun Apr 2 15:03:07 2023 +0000

    change of peeled probabilities

Diff:
---
 gcc/cfgloopmanip.cc          | 20 +++++++++++++++++++-
 gcc/tree-ssa-loop-ivcanon.cc |  3 ++-
 2 files changed, 21 insertions(+), 2 deletions(-)

diff --git a/gcc/cfgloopmanip.cc b/gcc/cfgloopmanip.cc
index 0e3ad8ed742..47ab699664e 100644
--- a/gcc/cfgloopmanip.cc
+++ b/gcc/cfgloopmanip.cc
@@ -1148,11 +1148,29 @@ duplicate_loop_body_to_header_edge (class loop *loop, edge e,
 	}
 
       scale_step = XNEWVEC (profile_probability, ndupl);
-
+    // If we have histogram then we know precise probabilities for peeling
+    // is_latch means unrolling
+    if (!loop->counters || is_latch) {
       for (i = 1; i <= ndupl; i++)
 	scale_step[i - 1] = bitmap_bit_p (wont_exit, i)
 				? prob_pass_wont_exit
 				: prob_pass_thru;
+    } else {
+        gcov_type psum=0;
+        for (i = 0; i < ndupl && i<(unsigned int)param_profile_histogram_size_lin; i++){
+            psum+=(*loop->counters->hist)[i];
+            scale_step[i] = profile_probability::always() - 
+            (psum ? profile_probability::always()/loop->counters->sum/psum 
+                : profile_probability::never());
+        }
+        ++i;
+        for (; i <= ndupl; i++)
+        scale_step[i - 1] = bitmap_bit_p (wont_exit, i)
+                  ? prob_pass_wont_exit
+                  : prob_pass_thru;
+        // should rescale
+          
+    }
 
       /* Complete peeling is special as the probability of exit in last
 	 copy becomes 1.  */
diff --git a/gcc/tree-ssa-loop-ivcanon.cc b/gcc/tree-ssa-loop-ivcanon.cc
index 347e143a4c7..e72875cb777 100644
--- a/gcc/tree-ssa-loop-ivcanon.cc
+++ b/gcc/tree-ssa-loop-ivcanon.cc
@@ -1044,7 +1044,8 @@ try_peel_loop (class loop *loop,
       for (int i=0;i<param_profile_histogram_size_lin; i++){
           psum+=(*(loop->counters->hist))[i];
           // iteration has enough cumulated in partial sum and itself has at least 1 percent
-          if ((100*psum)/sum>=good_percentage)
+          // or we have complete peeling
+          if ((100*psum)/sum>=good_percentage || psum==sum)
           {
             good_peels.safe_push(i);
             if ((maxiter >= 0 && maxiter <= good_peels.last()) ||

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2023-04-03 13:42 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-04-03 13:42 [gcc(refs/users/kubaneko/heads/histogram)] change of peeled probabilities Ondrej Kubanek

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