]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
ipa: Rewrite callback_edge_useful_p heuristic.
authorJosef Melcr <josef.melcr@suse.com>
Thu, 20 Nov 2025 22:46:38 +0000 (23:46 +0100)
committerJosef Melcr <josef.melcr@suse.com>
Fri, 21 Nov 2025 08:17:20 +0000 (09:17 +0100)
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 <josef.melcr@suse.com>
gcc/attr-callback.cc

index ee39ef61a20da6a496e661ce46c4425a73db773c..04b5ad0ef119abf7485ea9b44620ba4d29e604d8 100644 (file)
@@ -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