This is the mail archive of the mailing list for the GCC project.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [PATCH 3/9] operand_equal_p: add support for OBJ_TYPE_REF.

> On Fri, Aug 16, 2019 at 2:07 PM Jan Hubicka <> wrote:
> >
> > >
> > > When we compare OBJ_TYPE_REF_TOKEN and OBJ_TYPE_REF_OBJECT
> > > and they are equal, are there cases where types_same_for_odr returns false?
> >
> > OBJ_TYPE_REF_OBJECT is pointer to the instance, OBJ_TYPE_REF_TOKEN is
> > index in the vtable or the type given by obj_ref_type_class.  I guess
> > one can do something like
> >
> >  void *ptr;
> >  ...
> >  if (cond)
> >    ((class_a *)ptr)->firstvirtualmethod_of_class_a ();
> >  else
> >    ((class_b *)ptr)->firstvirtualmethod_of_class_b ();
> >
> > Here OBJECT will be always *ptr, TOKEN will be 0, but the actual virtual
> > method is different. So merging this may lead to invalid
> > devirtualization at least when the classes are anonymous namespace and
> > we work out late in compilation that they are not derived.
> But we also compare OBJ_TYPE_REF_EXPR and later we expand to a call
> with exactly that address...

I think this is same as with memory references.  Just because the
addresses compare equal and read same type we still can not merge w/o
verifying that the alias oracle will not give different answers 
(so we need to compare cliques and access paths). operand_equal_p does
checking in this case though it is bit random on way it understands
access paths.

To get more agressive unification we can drop the optional metadata
(i.e. remove OBJ_TYPE_REF or drop to alias set zero) while merging but I
think this will need more care and decisions what to do for -Os only and
what to do for -O2/fast.  For this reason I would first handle this
conservatively (i.e. require match of metadata as well) and then improve
from that.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]