On Mon, Nov 20, 2023 at 3:34 PM Sebastian Huber
<[email protected]> wrote:
>
> 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:
OK.
> * tree-profile.cc (gen_counter_update): Use unshare_expr() for the
> counter expression in the second gimple_build_assign().
> ---
> 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)
> {
> --
> 2.35.3
>