https://gcc.gnu.org/bugzilla/show_bug.cgi?id=107661

--- Comment #7 from Sergei Trofimovich <slyfox at gcc dot gnu.org> ---
Looking -fdump-ipa-cp-all I see the following clone

```
IPA decision stage:


Evaluating opportunities for static void function_ref::callback_fn(void*) [with
Callable = seemingly_unused_foo(int)::L]/30.

Evaluating opportunities for static void function_ref::callback_fn(void*) [with
Callable = void()]/29.

Evaluating opportunities for void getWaitStatesSince3(int, function_ref)/18.
 - considering value callback_fn for param #1 Expired, offset: 0 (caller_count:
1)
     good_cloning_opportunity_p (time: 33, size: 37, freq_sum: 1) ->
evaluation: 891.89, threshold: 500
  Creating a specialized node of void getWaitStatesSince3(int,
function_ref)/18.
                Accounting size:5.00, time:14.00 on predicate exec:(true)
     the new node is void getWaitStatesSince3.constprop(int, function_ref)/33.
     Aggregate replacements: 1[0]=callback_fn
     overall size reached 88

Evaluating opportunities for void getWaitStatesSince6(int, int, int,
function_ref)/17.
 - considering value 0 for param #0 MBB (caller_count: 2)
     good_cloning_opportunity_p (time: 1, size: 21, freq_sum: 2, self_scc,
single_call) -> evaluation: 80.95, threshold: 500
     good_cloning_opportunity_p (time: 1, size: 21, freq_sum: 2, self_scc,
single_call) -> evaluation: 80.95, threshold: 500
 - considering value 42 for param #2 WaitStates (caller_count: 2)
     good_cloning_opportunity_p (time: 1.5, size: 20, freq_sum: 2, self_scc,
single_call) -> evaluation: 127.50, threshold: 500
     good_cloning_opportunity_p (time: 1.5, size: 20, freq_sum: 2, self_scc,
single_call) -> evaluation: 127.50, threshold: 500
 - considering value callback_fn for param #3 Expired, offset: 0 (caller_count:
2)
     good_cloning_opportunity_p (time: 33, size: 29, freq_sum: 1.4888,
self_scc, single_call) -> evaluation: 1440.03, threshold: 500
  Creating a specialized node of void getWaitStatesSince6(int, int, int,
function_ref)/17.
                Accounting size:2.00, time:11.00 on predicate exec:(true)
                Accounting size:3.00, time:12.00 on predicate exec:(true)
                Accounting size:3.00, time:12.00 on predicate exec:(true)
                Accounting size:5.00, time:6.84 on predicate exec:(true)
     the new node is void getWaitStatesSince6.constprop(int, int, int,
function_ref)/34.
     Aggregate replacements: 3[0]=callback_fn
     overall size reached 109

Evaluating opportunities for void getWaitStatesSince6(int, int, int,
function_ref)/17.
 - considering value 0 for param #0 MBB (caller_count: 1)
     good_cloning_opportunity_p (time: 1, size: 21, freq_sum: 1, self_scc,
single_call) -> evaluation: 40.48, threshold: 500
     good_cloning_opportunity_p (time: 1, size: 21, freq_sum: 1, self_scc,
single_call) -> evaluation: 40.48, threshold: 500
 - considering value 42 for param #2 WaitStates (caller_count: 1)
     good_cloning_opportunity_p (time: 1.5, size: 20, freq_sum: 1, self_scc,
single_call) -> evaluation: 63.75, threshold: 500
     good_cloning_opportunity_p (time: 1.5, size: 20, freq_sum: 1, self_scc,
single_call) -> evaluation: 63.75, threshold: 500
 - adding an extra caller void getWaitStatesSince6(int, int, int,
function_ref)/17 of void getWaitStatesSince6.constprop(int, int, int,
function_ref)/34

Evaluating opportunities for void Exec(function_ref)/13.
 - considering value callback_fn for param #0 fr, offset: 0 (caller_count: 1)
     good_cloning_opportunity_p (time: 33, size: 8, freq_sum: 1) -> evaluation:
4125.00, threshold: 500
  Creating a specialized node of void Exec(function_ref)/13.
                Accounting size:4.00, time:16.00 on predicate exec:(true)
     the new node is void Exec.constprop(function_ref)/35.
     Aggregate replacements: 0[0]=callback_fn
ipa-prop: Discovered an indirect call to a known target (void
Exec.constprop(function_ref)/35 -> static void function_ref::callback_fn(void*)
[with Callable = seemingly_unused_foo(int)::L]/30), for stmt _1 (_2);
../a.cc:37:14: optimized: converting indirect call in void
Exec.constprop(function_ref)/35 to direct call to static void
function_ref::callback_fn(void*) [with Callable =
seemingly_unused_foo(int)::L]/30
                Accounting size:2.00, time:11.00 on predicate exec:(true)
     overall size reached 117

Evaluating opportunities for void Exec(function_ref)/13.
Not considering void Exec.constprop(function_ref)/35 for ipa bitwise
propagation ; -fipa-bit-cp: disabled.
...

IPA constant propagation end
```

When debug reports unqualified `Aggregate replacements: 1[0]=callback_fn` does
it mean ipa-cp does not distinguish between:
  * static void function_ref::callback_fn(void*) [with Callable =
seemingly_unused_foo(int)::L]/30.
  * static void function_ref::callback_fn(void*) [with Callable = void()]/29.
?

I suspect it does not and that results in a wrong callback_fn inline.

Reply via email to