Merging identical functions in GCC
Roman Kononov
kononov195-far@yahoo.com
Mon Sep 18 15:25:00 GMT 2006
On 09/15/2006 04:32 PM, Ross Ridge wrote:
> Also, I don't think it's safe if you merge only functions in COMDAT
> sections.
>
> Consider:
>
> #include <assert.h>
>
> template <class T> T foo(T a) { return a; }
> template <class T> T bar(T a) { return a; }
>
> int
> main() {
> assert((int (*)(int)) foo<int> != (int (*)(int)) bar<int>);
> }
>
> Both foo<int> and bar<int> get put in their own COMDAT section and their
> RTL and assembly are the same, but it's not safe to merge them.
Merge can be safely done like this:
If both functions A and B are not inlined functions, and they have single
entry points, and memcmp of their asm code is zero, and the code is large
enough, then the asm code of the functions B is replaced by "jmp A" instruction.
Regards,
Roman
More information about the Gcc
mailing list