> > Hello,
> >
> > and ping please. This is now also a fix for PR 123619.
> >
>
> > > gcc/ChangeLog:
> > >
> > > 2025-12-05 Martin Jambor <[email protected]>
> > >
> > > * cgraph.h (ipa_polymorphic_call_context::equal_to): Add parametr
> > > strict_speculation.
> > > * ipa-polymorphic-call.cc (ipa_polymorphic_call_context::equal_to):
> > > Likewise.
> > > * ipa-cp.cc (values_equal_for_ipcp_p): Pass true to strict_speculation
> > > of ipa_polymorphic_call_context::equal_to.
>
> So the problem here is that iterative dataflow does not stop, since
> merging is not implemented monotonously.
>
> The problem seems to be that we keep track about consistency of the
> speculation and ignore it, if it makes no sense. However if we
> encounter possible dynamic type change we remove non-speculative info
> which magically makes speculation come back causing the
> non-monotonicity.
>
> Before type chane happens, we know that specualtion is already wrong, so
> we should drop it. I am testing the following
>
Hi,
I bootstrapped/regtested x86_64-linux and checked it fixes PR123619.
This is the variant I comited.
Honza
gcc/ChangeLog:
PR ipa/123619
* ipa-polymorphic-call.cc
(ipa_polymorphic_call_context::possible_dynamic_type_change): Remove
impossible
speuculation.
diff --git a/gcc/ipa-polymorphic-call.cc b/gcc/ipa-polymorphic-call.cc
index 243a2f13cdc..5e53c217e33 100644
--- a/gcc/ipa-polymorphic-call.cc
+++ b/gcc/ipa-polymorphic-call.cc
@@ -2363,7 +2363,18 @@
ipa_polymorphic_call_context::possible_dynamic_type_change (bool in_poly_cdtor,
tree otr_type)
{
if (dynamic)
- make_speculative (otr_type);
+ {
+ /* See if existing speculation was inconsistent before type change.
+ If so drop it first, so we do not lose track about it being
+ impossible. */
+ if (speculative_outer_type
+ && !speculation_consistent_p (speculative_outer_type,
+ speculative_offset,
+ speculative_maybe_derived_type,
+ otr_type))
+ clear_speculation ();
+ make_speculative (otr_type);
+ }
else if (in_poly_cdtor)
maybe_in_construction = true;
}