Hello,
On Sun, Oct 19 2025, Josef Melcr wrote:
> Hi,
>
> On 10/19/25 00:51, Josef Melcr wrote:
>> Following Andrew's replies, I did some digging and found out that
>> comparing decl pointers is rather unreliable. In the committed
>> version, I'd swap it for DECL_UID comparisons, unless someone suggests
>> something even better. I didn't know about DECL_UID when I was
>> working on this patch, sorry about that.
>
> The rewritten patch can be found below. I bootstrapped and regtested it
> with the rest of the series with no problems, so I'd like to check it in
> instead of the original version.
>
>
> Best regards,
>
> Josef
>
> =====
>
> gcc/ChangeLog:
>
> * attr-callback.cc (callback_edge_useful_p): Rewrite the
> heuristic, now consider icf bodies and not yet redirected
> edges.
>
> Signed-off-by: Josef Melcr <[email protected]>
> ---
> gcc/attr-callback.cc | 25 ++++++++++++++++++++-----
> 1 file changed, 20 insertions(+), 5 deletions(-)
>
> diff --git a/gcc/attr-callback.cc b/gcc/attr-callback.cc
> index 83d27544150..49be5d61f22 100644
> --- a/gcc/attr-callback.cc
> +++ b/gcc/attr-callback.cc
> @@ -344,11 +344,26 @@ bool
> callback_edge_useful_p (cgraph_edge *e)
> {
> gcc_checking_assert (e->callback);
> - /* If the edge is not pointing towards a clone, it is no longer
> useful as its
> - entire purpose is to produce clones of callbacks. */
> - if (!e->callee->clone_of)
> - return false;
> - return true;
> + /* If the edge is pointing towards a clone, it is useful. */
> + if (e->callee->clone_of)
> + return true;
> +
> + /* If the callee has been produced by icf, the edge is useful, as it
> will be
> + used to for the redirection. */
> + if (e->callee->icf_merged)
> + return true;
I understand this part.
> +
> + /* If the decl in the call stmt doesn't match, the edge has been
> redirected
> + and thus is useful. */
> + if (e->call_stmt)
> + {
> + tree call_stmt_decl
> + = TREE_OPERAND (gimple_call_arg (e->call_stmt, e->callback_id), 0);
> + if (DECL_UID (call_stmt_decl) != DECL_UID (e->callee->decl))
> + return true;
> + }
But I don't understand this one. First, with LTO the check for
e->call_stmt non-NULL-ness will always fail as the function is only
called from IPA-CP WPA phase and so statements will not be in memory.
So we need a better check, whatever this tries to check for. But I
don't see what non-cloning and non-ICF case you are after here. What is
the testcase where this triggers?
Sorry for the delay in replying. I tried to figure out what I'm missing
here but have not managed.
Thanks,
Martin