> > Patch is still OK, but ipa-ICF will only identify the functions if > > static chain is unused. Perhaps just picking the winning candidate to be > > version without static chain and making ipa-inline to not ICE when calls > > with static chain lands to function with no static chain would help us > > to optimize better. > > I see, thanks for the explanation. The attached patch appears to work. > > > PR ipa/113996 > * ipa-icf.h (sem_function): Add static_chain_p member. > * ipa-icf.cc (sem_function::init): Initialize it. > (sem_item_optimizer::merge_classes): If the class is made of > functions, pick one without static chain as the target. > > -- > Eric Botcazou
> @@ -3399,11 +3401,22 @@ sem_item_optimizer::merge_classes (unsigned int > prev_class_count, > > sem_item *source = c->members[0]; > > - if (DECL_NAME (source->decl) > - && MAIN_NAME_P (DECL_NAME (source->decl))) > - /* If merge via wrappers, picking main as the target can be > - problematic. */ > - source = c->members[1]; > + if (source->type == FUNC) > + { > + /* Pick a member without static chain, if any. */ > + for (unsigned int j = 0; j < c->members.length (); j++) > + if (!static_cast<sem_function *> (c->members[j])->static_chain_p) > + { > + source = c->members[j]; > + break; > + } > + > + /* If merge via wrappers, picking main as the target can be > + problematic. */ > + if (DECL_NAME (source->decl) > + && MAIN_NAME_P (DECL_NAME (source->decl))) > + source = c->members[source == c->members[0] ? 1 : 0]; Thanks for looking into this. I wonder if it can happen that we ICF merge function with static chain and main? We can fix this unlikely case by simply considering functions with static chain not equivalent to MAIN_NAME_P function. On x86_64 static chain goes to R10, but I wonder if we support targets where API of function taking static chain and not using it differs from API of function with no static chain? Honza