From: Josef Melcr Date: Thu, 20 Nov 2025 22:46:38 +0000 (+0100) Subject: ipa: Rewrite callback_edge_useful_p heuristic. X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=0343c45a3387ac5e1e365c97e56ea8305ba67016;p=thirdparty%2Fgcc.git ipa: Rewrite callback_edge_useful_p heuristic. This function is used to determine whether a callback edge should be kept or not. It was supposed to capture the idea that a callback edge has been redirected at some point, however, it only considered redirecting to some clone. However, an edge may not always be redirected to a clone. For example, common function bodies produced by icf are not clones. This version of this function should cover all cases, at least for the time being. gcc/ChangeLog: PR ipa/122768 * attr-callback.cc (callback_edge_useful_p): Rewrite the heuristic, now consider clones as well as icf bodies. Signed-off-by: Josef Melcr --- diff --git a/gcc/attr-callback.cc b/gcc/attr-callback.cc index ee39ef61a20..04b5ad0ef11 100644 --- a/gcc/attr-callback.cc +++ b/gcc/attr-callback.cc @@ -344,11 +344,19 @@ 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; + + /* In case some future pass redirects edges, it should be added as a case + here. */ + + return false; } /* Returns the number of arguments the callback function described by ATTR