public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc(refs/users/kubaneko/heads/histogram)] Do not instrument loops with known number of iterations and with no instrumentable exits.
@ 2023-05-01 21:51 Jan Hubicka
  0 siblings, 0 replies; only message in thread
From: Jan Hubicka @ 2023-05-01 21:51 UTC (permalink / raw)
  To: gcc-cvs

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

commit b37d3aa26581cc6145ee8be6c82ad81f203f313a
Author: Honza <jh@ryzen3.suse.cz>
Date:   Mon May 1 23:50:31 2023 +0200

    Do not instrument loops with known number of iterations and with no instrumentable exits.

Diff:
---
 gcc/profile.cc    |  5 ++++-
 gcc/value-prof.cc | 34 ++++++++++++++++++++++++++++++++++
 2 files changed, 38 insertions(+), 1 deletion(-)

diff --git a/gcc/profile.cc b/gcc/profile.cc
index d2b8dfcadc1..4e3f74dfe1d 100644
--- a/gcc/profile.cc
+++ b/gcc/profile.cc
@@ -66,6 +66,7 @@ along with GCC; see the file COPYING3.  If not see
 #include "cfgloop.h"
 #include "sreal.h"
 #include "file-prefix-map.h"
+#include "tree-scalar-evolution.h"
 
 #include "profile.h"
 
@@ -1227,7 +1228,8 @@ branch_prob (bool thunk)
   total_num_times_called++;
 
   calculate_dominance_info (CDI_DOMINATORS);
-  loop_optimizer_init (LOOPS_HAVE_SIMPLE_LATCHES);
+  loop_optimizer_init (LOOPS_NORMAL);
+  scev_initialize ();
 
   flow_call_edges_add (NULL);
   add_noreturn_fake_exit_edges ();
@@ -1590,6 +1592,7 @@ branch_prob (bool thunk)
   values.release ();
   free_edge_list (el);
   coverage_end_function (lineno_checksum, cfg_checksum);
+  scev_finalize ();
   if (flag_branch_probabilities
       && (profile_status_for_fn (cfun) == PROFILE_READ))
     {
diff --git a/gcc/value-prof.cc b/gcc/value-prof.cc
index 5e029c811e2..f85e83388b7 100644
--- a/gcc/value-prof.cc
+++ b/gcc/value-prof.cc
@@ -44,6 +44,8 @@ along with GCC; see the file COPYING3.  If not see
 #include "builtins.h"
 #include "cfgloop.h"
 #include "tree-ssa-loop-manip.h"
+#include "tree-ssa-loop.h"
+#include "tree-ssa-loop-niter.h"
 
 /* In this file value profile based optimizations are placed.  Currently the
    following optimizations are implemented (for more detailed descriptions
@@ -1952,6 +1954,38 @@ gimple_histogram_values_to_profile (function *fun, histogram_values *values)
     {
       tree var;
       gimple_stmt_iterator gsi;
+      edge exit_edge = NULL;
+      auto_vec<edge> exits = get_loop_exit_edges (loop);
+      bool complex_exit = false;
+      bool exit_found = false;
+
+      /* If loop has only exits that can not be instrumented,
+	 we can not profile histograms.  */
+      for (auto exit : exits)
+	if (exit->flags & EDGE_FAKE)
+	  ;
+	else if (exit->flags & EDGE_COMPLEX)
+	  complex_exit = true;
+	else
+	  {
+	    if (!exit_found)
+	      exit_edge = exit;
+	    else
+	      exit_edge = NULL;
+	    exit_found = true;
+	    break;
+	  }
+      if (!exit_found)
+	continue;
+
+      /* If there is only one non-fake exit edge, see if we know number of
+	 iterations.  */
+      tree niter;
+      edge ex;
+      if (!complex_exit && exit_edge
+	  && (niter = find_loop_niter (loop, &ex))
+	  && TREE_CODE (niter) == INTEGER_CST)
+	continue;
 
       gsi = gsi_start_bb (loop->latch);
       create_iv (build_int_cst_type (get_gcov_type (), 0),

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

only message in thread, other threads:[~2023-05-01 21:51 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-05-01 21:51 [gcc(refs/users/kubaneko/heads/histogram)] Do not instrument loops with known number of iterations and with no instrumentable exits 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).