public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc r14-5629] gcov: Use unshare_expr() in gen_counter_update()
@ 2023-11-20 18:51 Sebastian Huber
  0 siblings, 0 replies; only message in thread
From: Sebastian Huber @ 2023-11-20 18:51 UTC (permalink / raw)
  To: gcc-cvs

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

commit r14-5629-ga034cca0a222598cb42302c059262b654685ff19
Author: Sebastian Huber <sebastian.huber@embedded-brains.de>
Date:   Mon Nov 20 14:48:03 2023 +0100

    gcov: Use unshare_expr() in gen_counter_update()
    
    This fixes issues like this:
    
      gcc/testsuite/gcc.dg/no_profile_instrument_function-attr-1.c: In function 'main':
      gcc/testsuite/gcc.dg/no_profile_instrument_function-attr-1.c:19:1: error: incorrect sharing of tree nodes
      __gcov0.main[0]
      # .MEM_12 = VDEF <.MEM_9>
      __gcov0.main[0] = PROF_edge_counter_4;
      during IPA pass: profile
      gcc/testsuite/gcc.dg/no_profile_instrument_function-attr-1.c:19:1: internal compiler error: verify_gimple failed
    
    Unshare the counter expression in the second gimple_build_assign() in
    gen_counter_update().  This is similar to the original
    gimple_gen_edge_profiler() for "ref":
    
    void
    gimple_gen_edge_profiler (int edgeno, edge e)
    {
      tree one;
    
      one = build_int_cst (gcov_type_node, 1);
    
      if (flag_profile_update == PROFILE_UPDATE_ATOMIC)
    [...]
      else
        {
          tree ref = tree_coverage_counter_ref (GCOV_COUNTER_ARCS, edgeno);
          tree gcov_type_tmp_var = make_temp_ssa_name (gcov_type_node,
                                                       NULL, "PROF_edge_counter");
          gassign *stmt1 = gimple_build_assign (gcov_type_tmp_var, ref);
          gcov_type_tmp_var = make_temp_ssa_name (gcov_type_node,
                                                  NULL, "PROF_edge_counter");
          gassign *stmt2 = gimple_build_assign (gcov_type_tmp_var, PLUS_EXPR,
                                                gimple_assign_lhs (stmt1), one);
          gassign *stmt3 = gimple_build_assign (unshare_expr (ref),
                                                gimple_assign_lhs (stmt2));
          gsi_insert_on_edge (e, stmt1);
          gsi_insert_on_edge (e, stmt2);
          gsi_insert_on_edge (e, stmt3);
        }
    }
    
    However, the orignal gimple_gen_time_profiler() did not use unshare_expr() for
    the counter expression (tree_time_profiler_counter):
    
    void
    gimple_gen_time_profiler (unsigned tag)
    {
    [...]
    
      /* Emit: counters[0] = ++__gcov_time_profiler_counter.  */
      if (flag_profile_update == PROFILE_UPDATE_ATOMIC)
    [...]
      else
        {
          tree tmp = make_temp_ssa_name (type, NULL, "PROF_time_profile");
          gassign *assign = gimple_build_assign (tmp, tree_time_profiler_counter);
          gsi_insert_before (&gsi, assign, GSI_NEW_STMT);
    
          tmp = make_temp_ssa_name (type, NULL, "PROF_time_profile");
          assign = gimple_build_assign (tmp, PLUS_EXPR, gimple_assign_lhs (assign),
                                        one);
          gsi_insert_after (&gsi, assign, GSI_NEW_STMT);
          assign = gimple_build_assign (original_ref, tmp);
          gsi_insert_after (&gsi, assign, GSI_NEW_STMT);
          assign = gimple_build_assign (tree_time_profiler_counter, tmp);
          gsi_insert_after (&gsi, assign, GSI_NEW_STMT);
        }
    }
    
    gcc/ChangeLog:
    
            * tree-profile.cc (gen_counter_update): Use unshare_expr() for the
            counter expression in the second gimple_build_assign().

Diff:
---
 gcc/tree-profile.cc | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/gcc/tree-profile.cc b/gcc/tree-profile.cc
index 7d3cb1ef089..68db09f6189 100644
--- a/gcc/tree-profile.cc
+++ b/gcc/tree-profile.cc
@@ -354,7 +354,7 @@ gen_counter_update (gimple_stmt_iterator *gsi, tree counter, tree result,
       tree tmp2 = make_temp_ssa_name (type, NULL, name);
       gassign *assign2 = gimple_build_assign (tmp2, PLUS_EXPR, tmp1, one);
       gsi_insert_after (gsi, assign2, GSI_NEW_STMT);
-      gassign *assign3 = gimple_build_assign (counter, tmp2);
+      gassign *assign3 = gimple_build_assign (unshare_expr (counter), tmp2);
       gsi_insert_after (gsi, assign3, GSI_NEW_STMT);
       if (result)
 	{

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

only message in thread, other threads:[~2023-11-20 18:51 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-11-20 18:51 [gcc r14-5629] gcov: Use unshare_expr() in gen_counter_update() Sebastian Huber

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).