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

https://gcc.gnu.org/g:692d26f8cc1844f74b62ef9d7c786be653b8e66c

commit 692d26f8cc1844f74b62ef9d7c786be653b8e66c
Author: kubaneko <kubanek0ondrej@gmail.com>
Date:   Thu Apr 13 15:31:32 2023 +0000

    fixed some bugs

Diff:
---
 gcc/cfgloop.cc               |  4 ++--
 gcc/cfgloopmanip.cc          |  6 ++++++
 gcc/tree-ssa-loop-ch.cc      | 36 +++++++++++++++++++++++++-----------
 gcc/tree-ssa-loop-ivcanon.cc |  1 +
 4 files changed, 34 insertions(+), 13 deletions(-)

diff --git a/gcc/cfgloop.cc b/gcc/cfgloop.cc
index 695941020e8..a0d25056992 100644
--- a/gcc/cfgloop.cc
+++ b/gcc/cfgloop.cc
@@ -2288,10 +2288,10 @@ void adjust_loop_estimates_minus ( class loop* loop, unsigned HOST_WIDE_INT npee
 {
   if (loop->any_estimate)
     {
-      if (wi::ltu_p (npeel, loop->nb_iterations_estimate))
+      if (wi::leu_p (npeel, loop->nb_iterations_estimate))
         loop->nb_iterations_estimate -= npeel;
       else
-	loop->nb_iterations_estimate = 0;
+        loop->any_estimate = false;
     }
   if (loop->any_upper_bound && precise)
     {
diff --git a/gcc/cfgloopmanip.cc b/gcc/cfgloopmanip.cc
index 6f5bc91d82b..f05d68515bc 100644
--- a/gcc/cfgloopmanip.cc
+++ b/gcc/cfgloopmanip.cc
@@ -959,6 +959,12 @@ copy_loop_info (class loop *loop, class loop *target)
   target->finite_p = loop->finite_p;
   target->unroll = loop->unroll;
   target->owned_clique = loop->owned_clique;
+  if (loop->counters){
+    target->counters = ggc_alloc<histogram_counters>();
+    target->counters->sum=loop->counters->sum;
+    target->counters->adjusted=loop->counters->adjusted;
+    target->counters->hist=vec_safe_copy(loop->counters->hist);
+  }
 }
 
 /* Copies copy of LOOP as subloop of TARGET loop, placing newly
diff --git a/gcc/tree-ssa-loop-ch.cc b/gcc/tree-ssa-loop-ch.cc
index 604cdae8f27..57eb366cfda 100644
--- a/gcc/tree-ssa-loop-ch.cc
+++ b/gcc/tree-ssa-loop-ch.cc
@@ -381,7 +381,7 @@ unsigned int
 ch_base::copy_headers (function *fun)
 {
   basic_block header;
-  edge exit, entry;
+  edge exit, nonexit, entry;
   basic_block *bbs, *copied_bbs;
   unsigned n_bbs;
   unsigned bbs_size;
@@ -453,8 +453,15 @@ ch_base::copy_headers (function *fun)
 	 the header to have just a single successor and copying up to
 	 postdominator.  */
 
-      exit = NULL;
+      nonexit = NULL;
       n_bbs = 0;
+      int nexits = 0;
+      profile_count exit_count = profile_count::zero ();
+      profile_count entry_count = profile_count::zero ();
+      edge e;
+      edge_iterator ei;
+      FOR_EACH_EDGE (e, ei, loop->header->preds)
+        entry_count += e->count ();
       auto prob_enters_loop=profile_probability::guessed_always();
       while (should_duplicate_loop_header_p (header, loop, &remaining_limit))
 	{
@@ -464,18 +471,23 @@ ch_base::copy_headers (function *fun)
 	  /* Find a successor of header that is inside a loop; i.e. the new
 	     header after the condition is copied.  */
 	  if (flow_bb_inside_loop_p (loop, EDGE_SUCC (header, 0)->dest))
-	    exit = EDGE_SUCC (header, 0);
-	  else
-	    exit = EDGE_SUCC (header, 1);
-      if (exit){
-            prob_enters_loop*=exit->probability;
+      {
+        nonexit = EDGE_SUCC (header, 0);
+        exit = EDGE_SUCC (header, 1);
+      }
+      else
+      {
+        nonexit = EDGE_SUCC (header, 1);
+        exit = EDGE_SUCC (header, 0);
       }
+      exit_count += exit->count ();
+      nexits++;
 	  bbs[n_bbs++] = header;
 	  gcc_assert (bbs_size > n_bbs);
-      header = exit->dest;
+      header = nonexit->dest;
 	}
 
-      if (!exit)
+      if (!nonexit)
 	continue;
 
       if (dump_file && (dump_flags & TDF_DETAILS))
@@ -561,9 +573,11 @@ ch_base::copy_headers (function *fun)
 	}
       // if it is unlikely that after header copy the iterations enter the loop it
       // behaves like peeling 1 time
-      if (prob_enters_loop<profile_probability::very_unlikely() || remaining_limit>=0){
+      auto_vec<edge> exits = get_loop_exit_edges (loop);
+      if (nexits == (int)exits.length ())
+           adjust_loop_estimates_minus(loop, 1, true);
+      else if (exit_count >= entry_count.apply_scale (9, 10))
           adjust_loop_estimates_minus(loop, 1, false);
-      }
 
       changed = true;
     }
diff --git a/gcc/tree-ssa-loop-ivcanon.cc b/gcc/tree-ssa-loop-ivcanon.cc
index be4dd448889..043dd18b033 100644
--- a/gcc/tree-ssa-loop-ivcanon.cc
+++ b/gcc/tree-ssa-loop-ivcanon.cc
@@ -1066,6 +1066,7 @@ try_peel_loop (class loop *loop,
       }
       if (!good_peels.is_empty()){
           npeel=good_peels.pop();
+          // we do not pop() prcnt because we want it to be last for current iteration
       }
   }

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

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

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-04-13 15:31 [gcc(refs/users/kubaneko/heads/histogram)] fixed some bugs 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).