> gcc.dg/20031102-1.c now causes some 'surprising' optimization > behaviour. It is essentially > > int FooBar(void) > { > ... stuff > return 0; > } > > int main(void) > { > return FooBar(); > } > > > What happens is that FooBar gets inlined into main, and then > ipa-icf notices FooBar and main have identical bodies. It chooses > to have FooBar tail call main, which results in a surprising call > of 'main'. On PTX this is particularly unfortunate because we have > to emit a single prototype for main with the regular argc and argv > arguments (the backend gets around 'int main (void)' by faking the > additional 2 args). But that fails here because the tail call > doesn't match the prototype. > > Anyway, picking 'main' as the source function struck me as a poor > choice, hence the attached patch. It picks the second function of a > congruent set, if the first is 'main'. Note that even on, say > x86-linux, we emit a tail call rather than an alias for the included > testcase. > > I removed the gcc_assert, as the vector indexing operator already > checks the subscript is within range. > > Alternatively I could probably just fixup the testcase to make > FooBar uninlinable, as I suspect that might have been the original > intent. > > tested on x86_64-linux and ptx-none. > > nathan
> 2015-12-17 Nathan Sidwell <nat...@acm.org> > > gcc/ > * ipa-icf.c (sem_item_optimizer::merge): Don't pick 'main' as the > source function. > > gcc/testsuite/ > * gcc.dg/ipa/ipa-icf-merge-1.c: New. OK, thanks. Indeed we should not introduce new calls to main :) It contains some magic stuff on x86 targets, too. Honza