public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc r14-2922] More profile updating clenaups
@ 2023-08-02  7:44 Jan Hubicka
  0 siblings, 0 replies; only message in thread
From: Jan Hubicka @ 2023-08-02  7:44 UTC (permalink / raw)
  To: gcc-cvs

https://gcc.gnu.org/g:b278d3080ef23835438ec625b9841c6353c72e32

commit r14-2922-gb278d3080ef23835438ec625b9841c6353c72e32
Author: Jan Hubicka <jh@suse.cz>
Date:   Wed Aug 2 09:44:06 2023 +0200

    More profile updating clenaups
    
    This patch commonizes loop_count_in computatoin with
    expected_loop_iterations_by_profile (and moves it to cfgloopanal.cc rather than
    manip) and fixes roundoff error in scale_loop_profile.  I alos noticed that
    I managed to misapply the template change to gcc.dg/unroll-1.c.
    
    Bootstrapped/regtested x86_64-linux, comitted.
    
    gcc/ChangeLog:
    
            * cfgloop.h (loop_count_in): Declare.
            * cfgloopanal.cc (expected_loop_iterations_by_profile): Use count_in.
            (loop_count_in): Move here from ...
            * cfgloopmanip.cc (loop_count_in): ... here.
            (scale_loop_profile): Improve dumping; cast iteration bound to sreal.
    
    gcc/testsuite/ChangeLog:
    
            * gcc.dg/unroll-1.c: Fix template.

Diff:
---
 gcc/cfgloop.h                   |  1 +
 gcc/cfgloopanal.cc              | 48 ++++++++++++++++++++++++-----------------
 gcc/cfgloopmanip.cc             | 31 ++------------------------
 gcc/testsuite/gcc.dg/unroll-1.c |  3 +--
 4 files changed, 32 insertions(+), 51 deletions(-)

diff --git a/gcc/cfgloop.h b/gcc/cfgloop.h
index c4622d4b853..f28ec701764 100644
--- a/gcc/cfgloop.h
+++ b/gcc/cfgloop.h
@@ -922,6 +922,7 @@ extern bool get_max_loop_iterations (const class loop *loop, widest_int *nit);
 extern bool get_likely_max_loop_iterations (class loop *loop, widest_int *nit);
 extern int bb_loop_depth (const_basic_block);
 extern edge single_dom_exit (class loop *);
+extern profile_count loop_count_in (const class loop *loop);
 
 /* Converts VAL to widest_int.  */
 
diff --git a/gcc/cfgloopanal.cc b/gcc/cfgloopanal.cc
index d8923b27e5d..f4612d316d8 100644
--- a/gcc/cfgloopanal.cc
+++ b/gcc/cfgloopanal.cc
@@ -233,6 +233,33 @@ average_num_loop_insns (const class loop *loop)
   return ret;
 }
 
+/* Compute how many times loop is entered.  */
+
+profile_count
+loop_count_in (const class loop *loop)
+{
+  /* Compute number of invocations of the loop.  */
+  profile_count count_in = profile_count::zero ();
+  edge e;
+  edge_iterator ei;
+  bool found_latch = false;
+
+  if (loops_state_satisfies_p (LOOPS_MAY_HAVE_MULTIPLE_LATCHES))
+    FOR_EACH_EDGE (e, ei, loop->header->preds)
+      if (!flow_bb_inside_loop_p (loop, e->src))
+	count_in += e->count ();
+      else
+	found_latch = true;
+  else
+    FOR_EACH_EDGE (e, ei, loop->header->preds)
+      if (e->src != loop->latch)
+	count_in += e->count ();
+      else
+	found_latch = true;
+  gcc_checking_assert (found_latch);
+  return count_in;
+}
+
 /* Return true if BB profile can be used to determine the expected number of
    iterations (that is number of executions of latch edge(s) for each
    entry of the loop.  If this is the case initialize RET with the number
@@ -260,26 +287,7 @@ expected_loop_iterations_by_profile (const class loop *loop, sreal *ret,
       || !header_count.nonzero_p ())
     return false;
 
-  profile_count count_in = profile_count::zero ();
-  edge e;
-  edge_iterator ei;
-
-  /* For single-latch loops avoid querying dominators.  */
-  if (loop->latch)
-    {
-      bool found = false;
-      FOR_EACH_EDGE (e, ei, loop->header->preds)
-	if (e->src != loop->latch)
-	  count_in += e->count ();
-	else
-	  found = true;
-      /* If latch is not found, loop is inconsistent.  */
-      gcc_checking_assert (found);
-    }
-  else
-    FOR_EACH_EDGE (e, ei, loop->header->preds)
-      if (!dominated_by_p (CDI_DOMINATORS, e->src, loop->header))
-	count_in += e->count ();
+  profile_count count_in = loop_count_in (loop);
 
   bool known;
   /* Number of iterations is number of executions of latch edge.  */
diff --git a/gcc/cfgloopmanip.cc b/gcc/cfgloopmanip.cc
index fe452ecf60f..86360b5f380 100644
--- a/gcc/cfgloopmanip.cc
+++ b/gcc/cfgloopmanip.cc
@@ -525,33 +525,6 @@ scale_dominated_blocks_in_loop (class loop *loop, basic_block bb,
       }
 }
 
-/* Compute how many times loop is entered.  */
-
-profile_count
-loop_count_in (class loop *loop)
-{
-  /* Compute number of invocations of the loop.  */
-  profile_count count_in = profile_count::zero ();
-  edge e;
-  edge_iterator ei;
-  bool found_latch = false;
-
-  if (loops_state_satisfies_p (LOOPS_MAY_HAVE_MULTIPLE_LATCHES))
-    FOR_EACH_EDGE (e, ei, loop->header->preds)
-      if (!flow_bb_inside_loop_p (loop, e->src))
-	count_in += e->count ();
-      else
-	found_latch = true;
-  else
-    FOR_EACH_EDGE (e, ei, loop->header->preds)
-      if (e->src != loop->latch)
-	count_in += e->count ();
-      else
-	found_latch = true;
-  gcc_checking_assert (found_latch);
-  return count_in;
-}
-
 /* Return exit that suitable for update when loop iterations
    changed.  */
 
@@ -739,14 +712,14 @@ scale_loop_profile (class loop *loop, profile_probability p,
   if (dump_file && (dump_flags & TDF_DETAILS))
     {
       fprintf (dump_file,
-	       ";; guessed iterations of loop %i:%f new upper bound %i:\n",
+	       ";; Guessed iterations of loop %i is %f. New upper bound %i.\n",
 	       loop->num,
 	       iterations.to_double (),
 	       (int)iteration_bound);
     }
 
   /* See if loop is predicted to iterate too many times.  */
-  if (iterations <= iteration_bound)
+  if (iterations <= (sreal)iteration_bound)
     return;
 
   profile_count count_in = loop_count_in (loop);
diff --git a/gcc/testsuite/gcc.dg/unroll-1.c b/gcc/testsuite/gcc.dg/unroll-1.c
index ff2cbb07b22..fc6f39a9758 100644
--- a/gcc/testsuite/gcc.dg/unroll-1.c
+++ b/gcc/testsuite/gcc.dg/unroll-1.c
@@ -1,6 +1,6 @@
 /* PR optimization/8599 */
 /* { dg-do run } */
-/* { dg-options "-O2 -funroll-loops" } */
+/* { dg-options "-O2 -funroll-loops -fdump-rtl-loop2_unroll-details-blocks" } */
 /* { dg-options "-mtune=k6 -O2 -funroll-loops -fdump-rtl-loop2_unroll-details-blocks" { target { { i?86-*-* x86_64-*-* } && ia32 } } } */
 
 
@@ -26,4 +26,3 @@ int main()
   return 0;
 }
 /* { dg-final { scan-rtl-dump-not "Invalid sum" "loop2_unroll" } } */
-/* { dg-final { scan-rtl-dump-not "Invalid sum" "loop2_unroll" } } */

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

only message in thread, other threads:[~2023-08-02  7:44 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-08-02  7:44 [gcc r14-2922] More profile updating clenaups 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).