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;
+
+ /* 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;
+ }
+
+ return false;
}
/* Returns the number of arguments the callback function described by ATTR
--
2.51.0