stop IPA wrapping 'main'
Nathan Sidwell
nathan@acm.org
Thu Dec 17 18:39:00 GMT 2015
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
-------------- next part --------------
A non-text attachment was scrubbed...
Name: trunk-ipa.patch
Type: text/x-patch
Size: 1857 bytes
Desc: not available
URL: <http://gcc.gnu.org/pipermail/gcc-patches/attachments/20151217/ebee7cc4/attachment.bin>
More information about the Gcc-patches
mailing list