]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
Do not instrument loops with known number of iterations and with no instrumentable...
authorHonza <jh@ryzen3.suse.cz>
Mon, 1 May 2023 21:50:31 +0000 (23:50 +0200)
committerHonza <jh@ryzen3.suse.cz>
Mon, 1 May 2023 21:50:31 +0000 (23:50 +0200)
gcc/profile.cc
gcc/value-prof.cc

index d2b8dfcadc1de05177c5a6da17a415affaf5a3b6..4e3f74dfe1da0e23864c3d8c6561919694c0a8d0 100644 (file)
@@ -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))
     {
index 5e029c811e2e38f26d798eb0da1f66cf578dcdea..f85e83388b7ea0df956e0c2ceada7ce7ba0faaa0 100644 (file)
@@ -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),