From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 1075) id 246FE3858D1E; Mon, 1 May 2023 21:51:00 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 246FE3858D1E DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1682977860; bh=QG1QLQhhD9TpnOfh2L2I4p0ga0Fqf0/RER1MBuNxCIo=; h=From:To:Subject:Date:From; b=l7sEYBDLohuyr+TD2LH/OW6EcbK7sZc5dPYsc7blt8SrEvSUNNupAa23FzQfZacs0 ILiSpbnJgozbFK80QQxpD9xjgmmnh6UaIHRJ5GxoUap9yZwLdeycfkqvVjMjCnvAnb WGL1LeIiXEb7TSDY5NmgdJabyjV5N0zWwwxhAaBM= Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: Jan Hubicka To: gcc-cvs@gcc.gnu.org Subject: [gcc(refs/users/kubaneko/heads/histogram)] Do not instrument loops with known number of iterations and with no instrumentable exits. X-Act-Checkin: gcc X-Git-Author: Honza X-Git-Refname: refs/users/kubaneko/heads/histogram X-Git-Oldrev: 349581e9d5319442b0ccfa913717b934dd61f8c2 X-Git-Newrev: b37d3aa26581cc6145ee8be6c82ad81f203f313a Message-Id: <20230501215100.246FE3858D1E@sourceware.org> Date: Mon, 1 May 2023 21:51:00 +0000 (GMT) List-Id: https://gcc.gnu.org/g:b37d3aa26581cc6145ee8be6c82ad81f203f313a commit b37d3aa26581cc6145ee8be6c82ad81f203f313a Author: Honza 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 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),