This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Merging identical functions in GCC


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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]