Hi,
while thinking of the details on how to handle comdat locals through 
ipa-cp/inliner/folding
I wonder, if we won't end up with better code going the oposite way.
We can declare those functions static first and then have post-inliner IPA pass 
that will
travel the callgraph and mark all static functions/variables that are accessed 
only from
one comdat to be comdat local. We already have issues here - for example when 
ipa-split
decides to split a comdat function, its part will end up output comdat block.
Similarly when we decide to produce a clone only to optimize comdat function, 
the clone
may easily become dead.  I also think with the C++ include jungle, people will 
end up
having static things referenced only from comdats, but I may be wrong.

This approach would have issues by itself tough
 1) we will need to do it at -O0 too and in this case we may want to have flag
    for those decloned functions since we need to do it only for those
 2) since I dropped the ball on merging function labels patch, we may end up
    privatizing function with a label that has address taken from static 
variable
    that is not privatized.  We may just disable localization for such 
functions I suppose.
 3) we may surprise users who forget to annotate with used attribute.
 4) inliner does not handle static and comdats the same way, since it assumes 
comdat
    will be optimized out with some probability.  This won't match on statics 
that will
    later become part of comdat group.   Not big deal probably.

On the other hand my feeling is that this has a potential of code size savings 
and
may end up more robust/easier to maintain than support this somewhat 
counter-intuitive
context thorough the whole IPA optimization queue.

What do you think?

Honza

Reply via email to